#include #include #include "CMUgraphics.h" const double pi = 3.1415926; class myWindow : public Window { private: int i, x, y; Font foobar, barfoo; public: myWindow(int width, int height) : Window(width, height, "FOO"), foobar(Font("arial.ttf", 22)), barfoo(Font("cour.ttf", 12)) { i = 0; x = y = 150; disableAutoPageFlip(); } ~myWindow() { } void handleKeyboardEvent(const KeyboardEvent& event) { if(KeyboardEvent(NamedKey::ESCAPE) == event) { CMUgraphics::exitHandler(); } } void handleMouseEvent(const MouseEvent& event) { if((event.getX() != -1) && (event.getY() != -1)) { x = event.getX(); y = event.getY(); } } void handleTimerEvent(const TimerEvent& event) { } void handleIdleEvent() { drawRectangleFilled(Style::BLACK, 0, 0, 300, 400); Style THICK_GREEN = Style(Color::GREEN, 3); Style THICK_BLACK = Style(Color::BLACK, 3); Style TRANS_RED = Style(Color(255, 0, 0, 128)); Image testimage("scslogo.png", Image::PNG); THICK_GREEN.flipPatternBit(0); THICK_GREEN.flipPatternBit(1); THICK_GREEN.flipPatternBit(2); THICK_GREEN.flipPatternBit(3); THICK_GREEN.flipPatternBit(4); vector xcoord(5); vector ycoord(5); xcoord[0] = 0; ycoord[0] = 0; xcoord[1] = 150; ycoord[1] = 300; xcoord[2] = 150; ycoord[2] = 0; xcoord[3] = 300; ycoord[3] = 300; xcoord[4] = 300; ycoord[4] = 150; drawLine(THICK_GREEN, 150 + 100*cos((double)i/(8 * pi)), 150 + 100*sin((double)i/(8 * pi)), 150 + 100*cos(pi + (double)i/(8 * pi)), 150 + 100*sin(pi + (double)i/(8 * pi)) ); i++; drawTriangleFilled(TRANS_RED, x, y, 250, 250, 50, 250); drawEllipseOutline(Style::WHITE, 50, 50, 150, 250); drawText(Style::BLUE, foobar, 100, 100, "Testing"); drawText(Style::GREEN, barfoo, 200, 200, "More"); drawPixel(Style::WHITE, 1, 1); drawPixel(Style::WHITE, 10, 10); drawPolyLine(Style::RED, xcoord, ycoord); drawBezierCurve(Style::BLUE, xcoord, ycoord); drawImage(testimage, 200, 100); Image anotherimage(createImage(50, 50, 75, 75)); drawImage(anotherimage, 190, 10); anotherimage.save("testing.jpg", Image::JPEG); anotherimage.save("testing.png", Image::PNG); flipPage(); } }; int main() { myWindow test3(400, 300); CMUgraphics::handleEvents(); return 0; }