2 Copyright 1999, Be Incorporated. All Rights Reserved.
3 This file may be used under the terms of the Be Sample Code License.
10 #include <InterfaceKit.h>
14 #include "TeapotWindow.h"
16 #undef B_TRANSLATION_CONTEXT
17 #define B_TRANSLATION_CONTEXT "TeapotWindow"
19 TeapotWindow::TeapotWindow(BRect rect
, const char* name
, window_type wt
,
22 BDirectWindow(rect
, name
, wt
, something
)
24 GLenum type
= BGL_RGB
| BGL_DEPTH
| BGL_DOUBLE
;
27 BRect bounds
= Bounds();
28 bounds
.bottom
= bounds
.top
+ 14;
29 BMenuBar
* menuBar
= new BMenuBar(bounds
, "main menu");
32 BMessage
msg(kMsgAddModel
);
34 menuBar
->AddItem(menu
= new BMenu(B_TRANSLATE("File")));
37 menuBar
->ResizeToPreferred();
40 bounds
.top
= menuBar
->Bounds().bottom
+ 1;
41 BView
*subView
= new BView(bounds
, "subview", B_FOLLOW_ALL
, 0);
44 bounds
= subView
->Bounds();
45 fObjectView
= new(std::nothrow
) ObjectView(bounds
, "objectView",
46 B_FOLLOW_ALL_SIDES
, type
);
47 subView
->AddChild(fObjectView
);
50 msg
.AddInt32("num", 256);
51 menu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Add a teapot"),
52 new BMessage(msg
), 'N'));
53 item
->SetTarget(fObjectView
);
54 menu
->AddSeparatorItem();
55 menu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Quit"),
56 new BMessage(B_QUIT_REQUESTED
), 'Q'));
57 item
->SetTarget(be_app
);
58 msg
.RemoveName("num");
59 menuBar
->AddItem(menu
= new BMenu(B_TRANSLATE("Settings")));
60 menu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Perspective"),
61 new BMessage(kMsgPerspective
)));
62 item
->SetTarget(fObjectView
);
63 item
->SetMarked(false);
64 menu
->AddItem(item
= new BMenuItem(B_TRANSLATE("FPS display"),
65 new BMessage(kMsgFPS
)));
66 item
->SetTarget(fObjectView
);
67 item
->SetMarked(true);
68 menu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Filled polygons"),
69 new BMessage(kMsgFilled
)));
70 item
->SetTarget(fObjectView
);
71 item
->SetMarked(true);
72 menu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Lighting"),
73 new BMessage(kMsgLighting
)));
74 item
->SetTarget(fObjectView
);
75 item
->SetMarked(true);
76 menu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Backface culling"),
77 new BMessage(kMsgCulling
)));
78 item
->SetTarget(fObjectView
);
79 item
->SetMarked(true);
80 menu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Z-buffered"),
81 new BMessage(kMsgZBuffer
)));
82 item
->SetTarget(fObjectView
);
83 item
->SetMarked(true);
84 menu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Gouraud shading"),
85 new BMessage(kMsgGouraud
)));
86 item
->SetTarget(fObjectView
);
87 item
->SetMarked(true);
88 // menu->AddItem(item = new BMenuItem("Texture mapped", new BMessage(kMsgTextured)));
89 // item->SetTarget(fObjectView);
90 menu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Fog"),
91 new BMessage(kMsgFog
)));
92 item
->SetTarget(fObjectView
);
95 menuBar
->AddItem(menu
= new BMenu(B_TRANSLATE("Lights")));
96 msg
.what
= kMsgLights
;
98 msg
.AddInt32("num", 1);
99 menu
->AddItem(item
= new BMenuItem(subMenu
=
100 new BMenu(B_TRANSLATE("Upper center")), NULL
));
101 item
->SetTarget(fObjectView
);
102 msg
.AddInt32("color", lightNone
);
103 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Off"),
105 item
->SetTarget(fObjectView
);
106 subMenu
->AddSeparatorItem();
107 msg
.ReplaceInt32("color", lightWhite
);
108 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("White"),
110 item
->SetTarget(fObjectView
);
111 item
->SetMarked(true);
112 msg
.ReplaceInt32("color", lightYellow
);
113 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Yellow"),
115 item
->SetTarget(fObjectView
);
116 msg
.ReplaceInt32("color", lightBlue
);
117 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Blue"),
119 item
->SetTarget(fObjectView
);
120 msg
.ReplaceInt32("color", lightRed
);
121 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Red"),
123 item
->SetTarget(fObjectView
);
124 msg
.ReplaceInt32("color", lightGreen
);
125 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Green"),
127 item
->SetTarget(fObjectView
);
129 msg
.RemoveName("color");
131 msg
.ReplaceInt32("num", 2);
132 menu
->AddItem(item
= new BMenuItem(subMenu
=
133 new BMenu(B_TRANSLATE("Lower left")), NULL
));
134 item
->SetTarget(fObjectView
);
135 msg
.AddInt32("color", lightNone
);
136 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Off"),
138 item
->SetTarget(fObjectView
);
139 subMenu
->AddSeparatorItem();
140 msg
.ReplaceInt32("color", lightWhite
);
141 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("White"),
143 item
->SetTarget(fObjectView
);
144 msg
.ReplaceInt32("color", lightYellow
);
145 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Yellow"),
147 item
->SetTarget(fObjectView
);
148 msg
.ReplaceInt32("color", lightBlue
);
149 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Blue"),
151 item
->SetTarget(fObjectView
);
152 item
->SetMarked(true);
153 msg
.ReplaceInt32("color", lightRed
);
154 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Red"),
156 item
->SetTarget(fObjectView
);
157 msg
.ReplaceInt32("color", lightGreen
);
158 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Green"),
160 item
->SetTarget(fObjectView
);
162 msg
.RemoveName("color");
164 msg
.ReplaceInt32("num", 3);
165 menu
->AddItem(item
= new BMenuItem(subMenu
=
166 new BMenu(B_TRANSLATE("Right")), NULL
));
167 item
->SetTarget(fObjectView
);
168 msg
.AddInt32("color", lightNone
);
169 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Off"),
171 item
->SetTarget(fObjectView
);
172 item
->SetMarked(true);
173 subMenu
->AddSeparatorItem();
174 msg
.ReplaceInt32("color", lightWhite
);
175 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("White"),
177 item
->SetTarget(fObjectView
);
178 msg
.ReplaceInt32("color", lightYellow
);
179 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Yellow"),
181 item
->SetTarget(fObjectView
);
182 msg
.ReplaceInt32("color", lightBlue
);
183 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Blue"),
185 item
->SetTarget(fObjectView
);
186 msg
.ReplaceInt32("color", lightRed
);
187 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Red"),
189 item
->SetTarget(fObjectView
);
190 msg
.ReplaceInt32("color", lightGreen
);
191 subMenu
->AddItem(item
= new BMenuItem(B_TRANSLATE("Green"),
193 item
->SetTarget(fObjectView
);
195 float f
= menuBar
->Bounds().IntegerHeight() + 1;
196 SetSizeLimits(32, 1024, 32 + f
, 1024 + f
);
197 //TODO: verify, adding an height to x seems strange
203 TeapotWindow::QuitRequested()
205 if (fObjectView
!= NULL
)
206 fObjectView
->EnableDirectMode(false);
208 be_app
->PostMessage(B_QUIT_REQUESTED
);
214 TeapotWindow::DirectConnected(direct_buffer_info
* info
)
216 // TODO: Direct rendering causes the mouse to flicker due
217 // to the lack of a Hardware Cursor, however without
218 // it the teapot freezes on mouse move. (bug?)
220 if (fObjectView
!= NULL
) {
221 fObjectView
->DirectConnected(info
);
222 fObjectView
->EnableDirectMode(true);
229 TeapotWindow::MessageReceived(BMessage
* msg
)
231 // msg->PrintToStream();
234 BDirectWindow::MessageReceived(msg
);