Anda di halaman 1dari 2

#include "Graph.

h"
#include "GUI.h"
/* This program displays the Texas flag.
*/
using namespace Graph_lib;
Point tl(01,01);
//Window Origin
//-----------------------------------------------------------------//
//Window struct that contains all the objects.
struct Canvas : Graph_lib::Window
{
Canvas(Point xy, int w, int h, const string& title);
private:
Rectangle flag;
Rectangle flagb;
Rectangle flagr;
Rectangle flagpole;
Closed_polyline star;
//Button declarations
Button quit_button;
//Button callback functions
static void cb_quit(Address, Address);
void quit();
void draw_lines();
};
//-----------------------------------------------------------------//
/* Constructor for the Window that includes the specifics for each
object declared earlier.
*/
Canvas::Canvas(Point xy, int w, int h, const string& title)
:Window(xy,w,h,title),
// Flag Background:
flag(Point(75,75),600,400),
flagb(Point(75,75),200,400),
flagr(Point(275,275),400,200),
flagpole(Point(70,75),6,700),
quit_button(Point(x_max()-70,0),70, 20, "Quit", cb_quit)
{
flag.set_fill_color(Color::white);
flagb.set_fill_color(Color::blue);
flagr.set_fill_color(Color::red);
flagpole.set_fill_color(Color::black);
flagpole.set_color(Color::invisible);
//Closed_polyline that contains 10 points and sets the color to white.
star.add(Point(175,200));
star.add(Point(192,252));
star.add(Point(247,252));
star.add(Point(202,282));
star.add(Point(219,336));
star.add(Point(175,298));
star.add(Point(131,336));

star.add(Point(148,284));
star.add(Point(103,252));
star.add(Point(158,252));
star.set_fill_color(Color::white);
// Object attachments
attach(flag);
attach(flagb);
attach(flagr);
attach(flagpole);
attach(star);
attach(quit_button);
}
//-------------------------------------------------------------//
// Button that exits the image.
void Canvas::cb_quit(Address, Address pw)
{
reference_to<Canvas>(pw).quit();
}
void Canvas::quit()
{
hide();
}
int main()
{
try
{
Canvas win(tl, 800, 600,"Homework 6, Problem 3");
return gui_main();
}
catch(exception& e)
{
cerr << "Error: " << e.what() << endl;
return 1;
}
catch(...)
{
cerr << "Unknown Error." << endl;
return 2;
}
}

Anda mungkin juga menyukai