1 /*
2 * Copyright 2017, Adrien Destugues, pulkomandy@pulkomandy.tk
3 * Distributed under terms of the MIT license.
4 */
5
6
7 #include <Application.h>
8 #include <ControlLook.h>
9 #include <View.h>
10 #include <Window.h>
11
12
13 class View : public BView {
14 public:
15 View(BRect r);
16 void Draw(BRect update);
17 void DrawButtonFrames(BRect r, BRect update);
18
19 };
20
21
View(BRect r)22 View::View(BRect r)
23 : BView(r, "test", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE)
24 {
25 SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
26 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
27 }
28
29
30 void
Draw(BRect update)31 View::Draw(BRect update)
32 {
33 // - DrawButtonFrame (rounded + square)
34 // - DrawMenuFieldFrame + Background
35 // - DrawActiveTab
36 // - DrawSliderBar
37
38 MovePenTo(20, 20);
39 DrawString("TEST");
40
41 // Reference line
42 BRect r(20, 30, 80, 60);
43 DrawButtonFrames(r, update);
44
45 PushState();
46
47 // Positive translation
48 TranslateBy(0, 35);
49 DrawButtonFrames(r, update);
50
51 // Null, then negative translations
52 for (int i = 0; i < 10; i++) {
53 r.OffsetBy(0, 70);
54 TranslateBy(0, -35);
55 DrawButtonFrames(r, update);
56 }
57
58 PopState();
59 r = BRect(20, 30, 80, 60);
60
61 // Scale
62 PushState();
63 ScaleBy(2, 2);
64 TranslateBy(350 / 2, 0);
65 DrawButtonFrames(r, update);
66
67 PopState();
68
69 // Rotation
70 TranslateBy(420, 110);
71 RotateBy(M_PI / 4);
72 DrawButtonFrames(r, update);
73 }
74
75
76 void
DrawButtonFrames(BRect r,BRect update)77 View::DrawButtonFrames(BRect r, BRect update)
78 {
79 BRect r1 = r;
80 be_control_look->DrawButtonFrame(this, r1, update,
81 ui_color(B_PANEL_BACKGROUND_COLOR),
82 ui_color(B_PANEL_BACKGROUND_COLOR));
83 be_control_look->DrawButtonBackground(this, r1, update,
84 ui_color(B_PANEL_BACKGROUND_COLOR));
85
86 MovePenTo(r1.left + 5, r1.top + 15);
87 DrawString("BUTTON");
88
89 r.OffsetBy(70, 0);
90 r1 = r;
91 be_control_look->DrawButtonFrame(this, r1, update,
92 ui_color(B_PANEL_BACKGROUND_COLOR),
93 ui_color(B_PANEL_BACKGROUND_COLOR), BControlLook::B_DISABLED);
94 be_control_look->DrawButtonBackground(this, r1, update,
95 ui_color(B_PANEL_BACKGROUND_COLOR), BControlLook::B_DISABLED);
96
97 MovePenTo(r1.left + 5, r1.top + 15);
98 DrawString("Disabled");
99
100 r.OffsetBy(70, 0);
101 r1 = r;
102 be_control_look->DrawButtonFrame(this, r1, update,
103 ui_color(B_PANEL_BACKGROUND_COLOR),
104 ui_color(B_PANEL_BACKGROUND_COLOR), BControlLook::B_ACTIVATED);
105 be_control_look->DrawButtonBackground(this, r1, update,
106 ui_color(B_PANEL_BACKGROUND_COLOR), BControlLook::B_ACTIVATED);
107
108 MovePenTo(r1.left + 5, r1.top + 15);
109 DrawString("Active");
110
111 r.OffsetBy(70, 0);
112 r1 = r;
113 be_control_look->DrawButtonFrame(this, r1, update,
114 ui_color(B_PANEL_BACKGROUND_COLOR),
115 ui_color(B_PANEL_BACKGROUND_COLOR),
116 BControlLook::B_DISABLED | BControlLook:: B_ACTIVATED);
117 be_control_look->DrawButtonBackground(this, r1, update,
118 ui_color(B_PANEL_BACKGROUND_COLOR),
119 BControlLook::B_DISABLED | BControlLook::B_ACTIVATED);
120
121 MovePenTo(r1.left + 5, r1.top + 15);
122 DrawString("Act+Disa");
123
124 r.OffsetBy(70, 0);
125 r1 = r;
126 be_control_look->DrawButtonFrame(this, r1, update, 8,
127 ui_color(B_PANEL_BACKGROUND_COLOR),
128 ui_color(B_PANEL_BACKGROUND_COLOR), 0);
129 be_control_look->DrawButtonBackground(this, r1, update, 8,
130 ui_color(B_PANEL_BACKGROUND_COLOR), 0);
131
132 MovePenTo(r1.left + 5, r1.top + 15);
133 DrawString("Rounded");
134
135 /* TODO test various border sets
136 * TODO test with multiple radius on each corner (including 0 on some)
137 */
138 }
139
140
141 class Window : public BWindow {
142 public:
143 Window();
144
145 virtual bool QuitRequested();
146 };
147
148
Window()149 Window::Window()
150 : BWindow(BRect(50, 100, 1150, 500), "ControlLook-Test",
151 B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
152 {
153 AddChild(new View(Bounds()));
154
155 // TODO Add transformed variations:
156 // - Normal
157 // - Translated
158 // - Scaled
159 // - Rotated
160 }
161
162
163 bool
QuitRequested()164 Window::QuitRequested()
165 {
166 be_app->PostMessage(B_QUIT_REQUESTED);
167 return true;
168 }
169
170
171 // #pragma mark -
172
173
174 class Application : public BApplication {
175 public:
176 Application();
177
178 virtual void ReadyToRun(void);
179 };
180
181
Application()182 Application::Application()
183 : BApplication("application/x-vnd.haiku-test-controllook")
184 {
185 }
186
187
188 void
ReadyToRun(void)189 Application::ReadyToRun(void)
190 {
191 BWindow *window = new Window();
192 window->Show();
193 }
194
195
196 // #pragma mark -
197
198
199 int
main(int argc,char ** argv)200 main(int argc, char **argv)
201 {
202 Application app;
203
204 app.Run();
205 return 0;
206 }
207
208