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 namespace Graph_lib { void Shape::draw_lines() const { if (color().visibility() && 1 line_intersect(Point p1, Point p2, Point p3, Point p4, bool& parallel) { double x1 = p1.x; double x2 = p2.x; double x3 = p3.x; double x4 = p4.x; double y1 = p1.y; double y2 = p2.y; double y3 = p3.y; double y4 = p4.y; double denom = ((y4 - y3)*(x2-x1) - (x4-x3)*(y2-y1)); if (denom == 0){ parallel= true; return pair(0,0); } parallel = false; return pair( ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3))/denom, ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3))/denom); } //intersection between two line segments //Returns true if the two segments intersect, //in which case intersection is set to the point of intersection bool line_segment_intersect(Point p1, Point p2, Point p3, Point p4, Point& intersection){ bool parallel; pair u = line_intersect(p1,p2,p3,p4,parallel); if (parallel || u.first < 0 || u.first > 1 || u.second < 0 || u.second > 1) return false; intersection.x = p1.x + u.first*(p2.x - p1.x); intersection.y = p1.y + u.first*(p2.y - p1.y); return true; } void Polygon::add(Point p) { int np = number_of_points(); if (1 suffix_map; int init_suffix_map() { suffix_map["jpg"] = Suffix::jpg; suffix_map["JPG"] = Suffix::jpg; suffix_map["jpeg"] = Suffix::jpg; suffix_map["JPEG"] = Suffix::jpg; suffix_map["gif"] = Suffix::gif; suffix_map["GIF"] = Suffix::gif; suffix_map["bmp"] = Suffix::bmp; suffix_map["BMP"] = Suffix::bmp; return 0; } /* Suffix::Encoding get_encoding(const string& s) // try to deduce type from file name using a lookup table { static int x = init_suffix_map(); string::const_iterator p = find(s.begin(),s.end(),'.'); if (p==s.end()) return Suffix::none; // no suffix string suf(p+1,s.end()); return suffix_map[suf]; } */ // ik-1/30/2015 changed implementation so that it can work with relative paths // try to deduce type from file name using a lookup table Suffix::Encoding get_encoding(const string& s) { static int x = init_suffix_map(); size_t p = s.rfind( '.' ); if ( p == string::npos ) return Suffix::none; // no suffix string suf( s.substr( p + 1 ) ); return suffix_map[suf]; } bool can_open(const string& s) // check if a file named s exists and can be opened for reading { ifstream ff(s.c_str()); return ff.is_open(); } // somewhat overelaborate constructor // because errors related to image files can be such a pain to debug Image::Image(Point xy, string s, Suffix::Encoding e) :w(0), h(0), fn(xy,"") { add(xy); if (!can_open(s)) { fn.set_label("cannot open \""+s+'\"'); p = new Bad_image(30,20); // the "error image" return; } if (e == Suffix::none) e = get_encoding(s); switch(e) { case Suffix::jpg: p = new Fl_JPEG_Image(s.c_str()); break; case Suffix::gif: p = new Fl_GIF_Image(s.c_str()); break; // case Suffix::bmp: // p = new Fl_BMP_Image(s.c_str()); // break; default: // Unsupported image encoding fn.set_label("unsupported file type \""+s+'\"'); p = new Bad_image(30,20); // the "error image" } } void Image::draw_lines() const { if (fn.label()!="") fn.draw_lines(); if (w&&h) p->draw(point(0).x,point(0).y,w,h,cx,cy); else p->draw(point(0).x,point(0).y); } } // Graph

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!