Ticket #7921: ButtonLook.cpp

File ButtonLook.cpp, 1.8 KB (added by Pete, 13 years ago)

Short source demo that shows Control Look problem

Line 
1// Test of Redirecting Standard Output
2
3#include <stdio.h>
4#include <unistd.h>
5#include <Application.h>
6#include <View.h>
7#include <Window.h>
8#include <Button.h>
9#include <ControlLook.h>
10
11
12class TestWindow : public BWindow {
13public:
14 TestWindow(BRect frame);
15 virtual bool QuitRequested() {
16 be_app->PostMessage(B_QUIT_REQUESTED);
17 return true;
18 }
19 BButton *btn, *vbtn;
20 BView *view;
21};
22
23TestWindow::TestWindow(BRect frame)
24 : BWindow(frame, "Button Look Test", B_TITLED_WINDOW, 0)
25{
26// be_control_look = NULL; // uncomment to see expected buttons
27 btn = new BButton(BRect(10, 10, 40, 40), "button", "X", NULL);
28 AddChild(btn);
29 rgb_color clr = btn->ViewColor();
30 printf("Button in window:\n");
31 printf("ViewColor %d %d %d (%d)\n", clr.red, clr.green, clr.blue, clr.alpha);
32 clr = btn->LowColor();
33 printf("LowColor %d %d %d (%d)\n", clr.red, clr.green, clr.blue, clr.alpha);
34 clr = btn->HighColor();
35 printf("HighColor %d %d %d (%d)\n", clr.red, clr.green, clr.blue, clr.alpha);
36
37 view = new BView(BRect(100, 0, 300, 300), "view",
38 B_FOLLOW_ALL_SIDES, B_WILL_DRAW);
39 AddChild(view);
40 vbtn = new BButton(BRect(10, 10, 40, 40), "button", "Y", NULL);
41 view->AddChild(vbtn);
42 clr = vbtn->ViewColor();
43 printf("Button in view:\n");
44 printf("ViewColor %d %d %d (%d)\n", clr.red, clr.green, clr.blue, clr.alpha);
45 clr = vbtn->LowColor();
46 printf("LowColor %d %d %d (%d)\n", clr.red, clr.green, clr.blue, clr.alpha);
47 clr = vbtn->HighColor();
48 printf("HighColor %d %d %d (%d)\n", clr.red, clr.green, clr.blue, clr.alpha);
49}
50
51
52class TestApplication : public BApplication
53{
54public:
55 TestApplication() : BApplication("application/x-Test-TextView") {
56 (new TestWindow(BRect(50, 50, 350, 350)))->Show();
57 }
58};
59
60
61
62int main(void)
63{
64 TestApplication myApplication;
65 myApplication.Run();
66 return(0);
67}
68