1 /* 2 Copyright 1999, Be Incorporated. All Rights Reserved. 3 This file may be used under the terms of the Be Sample Code License. 4 */ 5 6 #include <stdio.h> 7 #include <InterfaceKit.h> 8 #include <Rect.h> 9 #include <Point.h> 10 #include <new> 11 12 #include "TeapotWindow.h" 13 14 TeapotWindow::TeapotWindow(BRect rect, char* name, window_type wt, ulong something) 15 : BDirectWindow(rect, name, wt, something) 16 { 17 GLenum type = BGL_RGB | BGL_DEPTH | BGL_DOUBLE; 18 19 Lock(); 20 BRect bounds = Bounds(); 21 bounds.bottom = bounds.top + 14; 22 BMenuBar* menuBar = new BMenuBar(bounds, "main menu"); 23 24 BMenu* menu; 25 BMessage msg(kMsgAddModel); 26 27 menuBar->AddItem(menu = new BMenu("File")); 28 AddChild(menuBar); 29 30 menuBar->ResizeToPreferred(); 31 32 bounds = Bounds(); 33 bounds.top = menuBar->Bounds().bottom + 1; 34 BView *subView = new BView(bounds, "subview", B_FOLLOW_ALL, 0); 35 AddChild(subView); 36 37 bounds = subView->Bounds(); 38 fObjectView = new(std::nothrow) ObjectView(bounds, "objectView", B_FOLLOW_ALL_SIDES, type); 39 subView->AddChild(fObjectView); 40 41 BMenuItem* item; 42 msg.AddInt32("num", 256); 43 menu->AddItem(item = new BMenuItem("Add a teapot", new BMessage(msg), 'N')); 44 item->SetTarget(fObjectView); 45 menu->AddSeparatorItem(); 46 menu->AddItem(item = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q')); 47 item->SetTarget(be_app); 48 msg.RemoveName("num"); 49 menuBar->AddItem(menu = new BMenu("Options")); 50 menu->AddItem(item = new BMenuItem("Perspective", new BMessage(kMsgPerspective))); 51 item->SetTarget(fObjectView); 52 item->SetMarked(false); 53 menu->AddItem(item = new BMenuItem("FPS display", new BMessage(kMsgFPS))); 54 item->SetTarget(fObjectView); 55 item->SetMarked(true); 56 menu->AddItem(item = new BMenuItem("Filled polygons", new BMessage(kMsgFilled))); 57 item->SetTarget(fObjectView); 58 item->SetMarked(true); 59 menu->AddItem(item = new BMenuItem("Lighting", new BMessage(kMsgLighting))); 60 item->SetTarget(fObjectView); 61 item->SetMarked(true); 62 menu->AddItem(item = new BMenuItem("Backface culling", new BMessage(kMsgCulling))); 63 item->SetTarget(fObjectView); 64 item->SetMarked(true); 65 menu->AddItem(item = new BMenuItem("Z-buffered", new BMessage(kMsgZBuffer))); 66 item->SetTarget(fObjectView); 67 item->SetMarked(true); 68 menu->AddItem(item = new BMenuItem("Gouraud shading", new BMessage(kMsgGouraud))); 69 item->SetTarget(fObjectView); 70 item->SetMarked(true); 71 // menu->AddItem(item = new BMenuItem("Texture mapped", new BMessage(kMsgTextured))); 72 // item->SetTarget(fObjectView); 73 menu->AddItem(item = new BMenuItem("Fog", new BMessage(kMsgFog))); 74 item->SetTarget(fObjectView); 75 76 BMenu *subMenu; 77 menuBar->AddItem(menu = new BMenu("Lights")); 78 msg.what = kMsgLights; 79 80 msg.AddInt32("num", 1); 81 menu->AddItem(item = new BMenuItem(subMenu = new BMenu("Upper center"), NULL)); 82 item->SetTarget(fObjectView); 83 msg.AddInt32("color", lightNone); 84 subMenu->AddItem(item = new BMenuItem("Off", new BMessage(msg))); 85 item->SetTarget(fObjectView); 86 subMenu->AddSeparatorItem(); 87 msg.ReplaceInt32("color", lightWhite); 88 subMenu->AddItem(item = new BMenuItem("White", new BMessage(msg))); 89 item->SetTarget(fObjectView); 90 item->SetMarked(true); 91 msg.ReplaceInt32("color", lightYellow); 92 subMenu->AddItem(item = new BMenuItem("Yellow", new BMessage(msg))); 93 item->SetTarget(fObjectView); 94 msg.ReplaceInt32("color", lightBlue); 95 subMenu->AddItem(item = new BMenuItem("Blue", new BMessage(msg))); 96 item->SetTarget(fObjectView); 97 msg.ReplaceInt32("color", lightRed); 98 subMenu->AddItem(item = new BMenuItem("Red", new BMessage(msg))); 99 item->SetTarget(fObjectView); 100 msg.ReplaceInt32("color", lightGreen); 101 subMenu->AddItem(item = new BMenuItem("Green", new BMessage(msg))); 102 item->SetTarget(fObjectView); 103 104 msg.RemoveName("color"); 105 106 msg.ReplaceInt32("num", 2); 107 menu->AddItem(item = new BMenuItem(subMenu = new BMenu("Lower left"), NULL)); 108 item->SetTarget(fObjectView); 109 msg.AddInt32("color", lightNone); 110 subMenu->AddItem(item = new BMenuItem("Off", new BMessage(msg))); 111 item->SetTarget(fObjectView); 112 subMenu->AddSeparatorItem(); 113 msg.ReplaceInt32("color", lightWhite); 114 subMenu->AddItem(item = new BMenuItem("White", new BMessage(msg))); 115 item->SetTarget(fObjectView); 116 msg.ReplaceInt32("color", lightYellow); 117 subMenu->AddItem(item = new BMenuItem("Yellow", new BMessage(msg))); 118 item->SetTarget(fObjectView); 119 msg.ReplaceInt32("color", lightBlue); 120 subMenu->AddItem(item = new BMenuItem("Blue", new BMessage(msg))); 121 item->SetTarget(fObjectView); 122 item->SetMarked(true); 123 msg.ReplaceInt32("color", lightRed); 124 subMenu->AddItem(item = new BMenuItem("Red", new BMessage(msg))); 125 item->SetTarget(fObjectView); 126 msg.ReplaceInt32("color", lightGreen); 127 subMenu->AddItem(item = new BMenuItem("Green", new BMessage(msg))); 128 item->SetTarget(fObjectView); 129 130 msg.RemoveName("color"); 131 132 msg.ReplaceInt32("num", 3); 133 menu->AddItem(item = new BMenuItem(subMenu = new BMenu("Right"), NULL)); 134 item->SetTarget(fObjectView); 135 msg.AddInt32("color", lightNone); 136 subMenu->AddItem(item = new BMenuItem("Off", new BMessage(msg))); 137 item->SetTarget(fObjectView); 138 item->SetMarked(true); 139 subMenu->AddSeparatorItem(); 140 msg.ReplaceInt32("color", lightWhite); 141 subMenu->AddItem(item = new BMenuItem("White", new BMessage(msg))); 142 item->SetTarget(fObjectView); 143 msg.ReplaceInt32("color", lightYellow); 144 subMenu->AddItem(item = new BMenuItem("Yellow", new BMessage(msg))); 145 item->SetTarget(fObjectView); 146 msg.ReplaceInt32("color", lightBlue); 147 subMenu->AddItem(item = new BMenuItem("Blue", new BMessage(msg))); 148 item->SetTarget(fObjectView); 149 msg.ReplaceInt32("color", lightRed); 150 subMenu->AddItem(item = new BMenuItem("Red", new BMessage(msg))); 151 item->SetTarget(fObjectView); 152 msg.ReplaceInt32("color", lightGreen); 153 subMenu->AddItem(item = new BMenuItem("Green", new BMessage(msg))); 154 item->SetTarget(fObjectView); 155 156 float f = menuBar->Bounds().IntegerHeight() + 1; 157 SetSizeLimits(32, 1024, 32 + f, 1024 + f); 158 //TODO: verify, adding an height to x seems strange 159 Unlock(); 160 } 161 162 163 bool 164 TeapotWindow::QuitRequested() 165 { 166 if (fObjectView != NULL) 167 fObjectView->EnableDirectMode(false); 168 169 be_app->PostMessage(B_QUIT_REQUESTED); 170 return true; 171 } 172 173 174 void 175 TeapotWindow::DirectConnected(direct_buffer_info* info) 176 { 177 if (fObjectView != NULL) { 178 fObjectView->DirectConnected(info); 179 fObjectView->EnableDirectMode(true); 180 } 181 } 182 183 184 void 185 TeapotWindow::MessageReceived(BMessage* msg) 186 { 187 // msg->PrintToStream(); 188 switch (msg->what) { 189 default: 190 BDirectWindow::MessageReceived(msg); 191 } 192 } 193