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 107 Window::~Window() 108 { 109 } 110 111 112 bool 113 Window::QuitRequested() 114 { 115 be_app->PostMessage(B_QUIT_REQUESTED); 116 return true; 117 } 118 119 120 // #pragma mark - 121 122 123 Application::Application() 124 : 125 BApplication("application/x-vnd.haiku-view_state") 126 { 127 } 128 129 130 void 131 Application::ReadyToRun() 132 { 133 Window* window = new Window(); 134 window->Show(); 135 } 136 137 138 // #pragma mark - 139 140 141 int 142 main(int argc, char** argv) 143 { 144 Application app; 145 app.Run(); 146 147 return 0; 148 } 149