Question: In c++ the program needs to create one TextRectangle for every word in the sentence and calculates the TextRectangle width according to the number of
In c++ the program needs to create one TextRectangle for every word in the sentence and calculates the TextRectangle width according to the number of characters
main_gui.cpp
// main.cpp #include "book/Simple_window.h" // get access to our window library #include "TextRectangle.h" int main() try { using namespace Graph_lib; // our graphics facilities are in Graph_lib Simple_window win(Point(100, 100), 220, 410, "CIS-155 Final Project"); string word = "Hello"; TextRectangle trect(Point(50, 60), word.length() * 10, 20, word); trect.set_fill_color(Color::white); trect.text_hide(); // make text invisible win.attach(trect); win.wait_for_button(); // Display hidden text trect.set_fill_color(Color::green); trect.text_show(Color::black); // make text visible using black color win.wait_for_button(); // Display clear text } catch (exception& ex) { // some error reporting cerr << ex.what() << endl; return 1; } catch (...) { // some more error reporting cerr << "epic fail" << endl; return 2; }
Graph.cpp
#include "Graph.h" #include
GUI.cpp
#include "GUI.h" #include "std_lib_facilities.h" #include using namespace Graph_lib; void Button::attach(Graph_lib::Window& win) { pw = new Fl_Button(loc.x, loc.y, width, height, label.c_str()); pw->callback(reinterpret_cast(do_it), &win); // pass the window own = &win; } int In_box::get_int() { Fl_Input& pi = reference_to(pw); // return atoi(pi.value()); const char* p = pi.value(); if (!isdigit(p[0])) return -999999; return atoi(p); } string In_box::get_string() { Fl_Input& pi = reference_to(pw); return string(pi.value()); } void In_box::attach(Graph_lib::Window& win) { pw = new Fl_Input(loc.x, loc.y, width, height, label.c_str()); own = &win; } void Out_box::put(int i) { Fl_Output& po = reference_to(pw); std::stringstream ss; ss << i; po.value(ss.str().c_str()); } void Out_box::put(const string& s) { reference_to(pw).value(s.c_str()); } void Out_box::attach(Graph_lib::Window& win) { pw = new Fl_Output(loc.x, loc.y, width, height, label.c_str()); own = &win; } /* Menu::Menu(Point xy, int w, int h, Kind kk, const string& s) :Widget(xy,w,h,s,0), k(kk), offset(0) { } */ int Menu::attach(Button& b) { b.width = width; b.height = height; switch(k) { case horizontal: b.loc = Point(loc.x+offset,loc.y); offset+=b.width; break; case vertical: b.loc = Point(loc.x,loc.y+offset); offset+=b.height; break; } selection.push_back(&b); return int(selection.size()-1); } int Menu::attach(Button* p) { // owned.push_back(p); return attach(*p); }
Window.cpp
#include "Window.h" #include "Graph.h" #include "GUI.h" namespace Graph_lib { Window::Window(int ww, int hh, const string& title) :Fl_Window(ww,hh,title.c_str()),w(ww),h(hh) { init(); } Window::Window(Point xy, int ww, int hh, const string& title) :Fl_Window(xy.x,xy.y,ww,hh,title.c_str()),w(ww),h(hh) { init(); } void Window::init() { resizable(this); show(); } //---------------------------------------------------- void Window::draw() { Fl_Window::draw(); for (unsigned int i=0; idraw(); } void Window::attach(Widget& w) { begin(); // FTLK: begin attaching new Fl_Wigets to this window w.attach(*this); // let the Widget create its Fl_Wigits end(); // FTLK: stop attaching new Fl_Wigets to this window } void Window::detach(Widget& b) { b.hide(); } void Window::attach(Shape& s) { shapes.push_back(&s); // s.attached = this; } void Window::detach(Shape& s) { for (unsigned int i = shapes.size(); 0