Ticket #946: movingWindows.cpp

File movingWindows.cpp, 1.7 KB (added by kaoutsis, 16 years ago)

Style changes

Line 
1#include <Window.h>
2#include <Application.h>
3#include <stdlib.h>
4
5
6class SimpleWindow : public BWindow {
7public:
8 SimpleWindow(BRect frame);
9 virtual bool QuitRequested();
10};
11
12
13SimpleWindow::SimpleWindow(BRect frame)
14 : BWindow(frame, "A Simple Window", B_TITLED_WINDOW, B_NOT_RESIZABLE)
15{
16}
17
18
19bool
20SimpleWindow::QuitRequested()
21{
22 be_app->PostMessage(B_QUIT_REQUESTED);
23 return true;
24}
25
26
27class SimpleApplication : public BApplication {
28public:
29 SimpleApplication();
30};
31
32
33SimpleApplication::SimpleApplication()
34 : BApplication("application/x-vnd.dps-simpleapp")
35{
36 SimpleWindow *aWindow;
37 SimpleWindow *aWindow2;
38 BRect aRect;
39 BRect aRect2;
40 float x = 320;
41 float y = 220;
42
43 aRect.Set(x, y, x + 180, y + 30); //left, top, right, bottom
44 aRect2.Set(y, x, y + 180, x + 30);
45
46 aWindow = new SimpleWindow(aRect);
47 aWindow2 = new SimpleWindow(aRect2);
48
49 aWindow->Show();
50 aWindow2->Show();
51 system("sleep 1");
52
53 aWindow->SetTitle("and now it will move...");
54 aWindow2->SetTitle("and now it will move...");
55 system("sleep 1");
56
57 aWindow->SetTitle("my moving window1");
58 aWindow2->SetTitle("my moving window2");
59
60 for (; x > 0; x--, y -= ((float)220 / (float)320)) {
61 aWindow->MoveTo(x, y);
62 aWindow2->MoveTo(y, x);
63 }
64 //x=0; y=0;
65 for (; (x <= 320); x++, y += ((float)220 / (float)320)) {
66 aWindow->MoveTo(x, y);
67 aWindow2->MoveTo(y, x);
68 }
69 system("sleep 1");
70 for (; y <= 800; y *= 1.009) {
71 aWindow->MoveTo(x, y);
72 aWindow2->MoveTo(y, x);
73 }
74
75 be_app->PostMessage(B_QUIT_REQUESTED);
76}
77
78
79int main()
80{
81
82 SimpleApplication myApplication;
83 myApplication.Run();
84
85 return 0;
86}
87
88