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