1 /* 2 * Copyright 2005-2009, Haiku Inc. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include <Application.h> 11 #include <Window.h> 12 #include <View.h> 13 14 #include <stdio.h> 15 16 17 class View : public BView { 18 public: 19 View(BRect rect); 20 virtual ~View(); 21 22 virtual void Draw(BRect updateRect); 23 }; 24 25 26 class Window : public BWindow { 27 public: 28 Window(); 29 virtual ~Window(); 30 31 virtual bool QuitRequested(); 32 }; 33 34 35 class Application : public BApplication { 36 public: 37 Application(); 38 39 virtual void ReadyToRun(); 40 }; 41 42 43 View::View(BRect rect) 44 : 45 BView(rect, "view state", B_FOLLOW_ALL, B_WILL_DRAW) 46 { 47 } 48 49 50 View::~View() 51 { 52 } 53 54 55 void 56 View::Draw(BRect updateRect) 57 { 58 SetHighColor(100, 100, 100); 59 StrokeRect(Bounds()); 60 61 // TODO: for now, we only test scaling functionality 62 63 SetHighColor(42, 42, 242); 64 StrokeRect(BRect(5, 5, 10, 10)); 65 #ifdef __HAIKU__ 66 printf("scale 1: %g\n", Scale()); 67 #endif 68 69 SetScale(2.0); 70 StrokeRect(BRect(5, 5, 10, 10)); 71 #ifdef __HAIKU__ 72 printf("scale 2: %g\n", Scale()); 73 #endif 74 75 SetHighColor(42, 242, 42); 76 PushState(); 77 StrokeRect(BRect(6, 6, 11, 11)); 78 #ifdef __HAIKU__ 79 printf("scale 3: %g\n", Scale()); 80 #endif 81 82 SetHighColor(242, 42, 42); 83 SetScale(2.0); 84 StrokeRect(BRect(5, 5, 10, 10)); 85 #ifdef __HAIKU__ 86 printf("scale 4: %g\n", Scale()); 87 #endif 88 89 PopState(); 90 SetScale(1.0); 91 } 92 93 94 // #pragma mark - 95 96 97 Window::Window() 98 : 99 BWindow(BRect(100, 100, 400, 400), "ViewState-Test", B_TITLED_WINDOW, 100 B_ASYNCHRONOUS_CONTROLS) 101 { 102 BView* view = new View(BRect(10, 10, 290, 290)); 103 AddChild(view); 104 } 105 106 Window::~Window() 107 { 108 } 109 110 111 bool 112 Window::QuitRequested() 113 { 114 be_app->PostMessage(B_QUIT_REQUESTED); 115 return true; 116 } 117 118 119 // #pragma mark - 120 121 122 Application::Application() 123 : 124 BApplication("application/x-vnd.haiku-view_state") 125 { 126 } 127 128 129 void 130 Application::ReadyToRun() 131 { 132 Window* window = new Window(); 133 window->Show(); 134 } 135 136 137 // #pragma mark - 138 139 140 int 141 main(int argc, char** argv) 142 { 143 Application app; 144 app.Run(); 145 146 return 0; 147 } 148