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 11 #include "TeapotWindow.h" 12 13 TeapotWindow::TeapotWindow(BRect rect, char* name, window_type wt, ulong something) 14 : BDirectWindow(rect,name,wt,something) 15 { 16 GLenum type = BGL_RGB | BGL_DEPTH | BGL_DOUBLE; 17 18 BRect r = rect; 19 r.OffsetTo(BPoint(100,100)); 20 21 Lock(); 22 r = Bounds(); 23 r.bottom = r.top + 14; 24 BMenuBar* mb = new BMenuBar(r,"main menu"); 25 26 BMenu* m; 27 BMessage msg (bmsgAddModel); 28 29 mb->AddItem(m = new BMenu("File")); 30 AddChild(mb); 31 32 mb->ResizeToPreferred(); 33 34 r = Bounds(); 35 r.top = mb->Bounds().bottom+1; 36 BView *sv = new BView(r,"subview",B_FOLLOW_ALL,0); 37 AddChild(sv); 38 39 r = sv->Bounds(); 40 fObjectView = new ObjectView(r,"objectView", B_FOLLOW_ALL_SIDES,type); 41 sv->AddChild(fObjectView); 42 fObjectView = fObjectView; 43 44 BMenuItem* item; 45 msg.AddInt32("num",256); 46 m->AddItem(item = new BMenuItem("Add a teapot",new BMessage(msg), 'N')); 47 item->SetTarget(fObjectView); 48 m->AddSeparatorItem(); 49 m->AddItem(item = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q')); 50 item->SetTarget(be_app); 51 msg.RemoveName("num"); 52 mb->AddItem(m = new BMenu("Options")); 53 m->AddItem(item = new BMenuItem("Perspective",new BMessage(bmsgPerspective))); 54 item->SetTarget(fObjectView); 55 item->SetMarked(false); 56 m->AddItem(item = new BMenuItem("FPS Display",new BMessage(bmsgFPS))); 57 item->SetTarget(fObjectView); 58 item->SetMarked(true); 59 m->AddItem(item = new BMenuItem("Filled polygons",new BMessage(bmsgFilled))); 60 item->SetTarget(fObjectView); 61 item->SetMarked(true); 62 m->AddItem(item = new BMenuItem("Lighting",new BMessage(bmsgLighting))); 63 item->SetTarget(fObjectView); 64 item->SetMarked(true); 65 m->AddItem(item = new BMenuItem("Backface culling",new BMessage(bmsgCulling))); 66 item->SetTarget(fObjectView); 67 item->SetMarked(true); 68 m->AddItem(item = new BMenuItem("Z-buffered",new BMessage(bmsgZBuffer))); 69 item->SetTarget(fObjectView); 70 item->SetMarked(true); 71 m->AddItem(item = new BMenuItem("Gouraud shading",new BMessage(bmsgGouraud))); 72 item->SetTarget(fObjectView); 73 item->SetMarked(true); 74 // m->AddItem(item = new BMenuItem("Texture mapped",new BMessage(bmsgTextured))); 75 // item->SetTarget(fObjectView); 76 m->AddItem(item = new BMenuItem("Fog",new BMessage(bmsgFog))); 77 item->SetTarget(fObjectView); 78 79 BMenu *sm; 80 mb->AddItem(m = new BMenu("Lights")); 81 msg.what = bmsgLights; 82 83 msg.AddInt32("num",1); 84 m->AddItem(item = new BMenuItem(sm = new BMenu("Upper center"),NULL)); 85 item->SetTarget(fObjectView); 86 msg.AddInt32("color",lightNone); 87 sm->AddItem(item = new BMenuItem("Off",new BMessage(msg))); 88 item->SetTarget(fObjectView); 89 sm->AddSeparatorItem(); 90 msg.ReplaceInt32("color",lightWhite); 91 sm->AddItem(item = new BMenuItem("White",new BMessage(msg))); 92 item->SetTarget(fObjectView); 93 item->SetMarked(true); 94 msg.ReplaceInt32("color",lightYellow); 95 sm->AddItem(item = new BMenuItem("Yellow",new BMessage(msg))); 96 item->SetTarget(fObjectView); 97 msg.ReplaceInt32("color",lightBlue); 98 sm->AddItem(item = new BMenuItem("Blue",new BMessage(msg))); 99 item->SetTarget(fObjectView); 100 msg.ReplaceInt32("color",lightRed); 101 sm->AddItem(item = new BMenuItem("Red",new BMessage(msg))); 102 item->SetTarget(fObjectView); 103 msg.ReplaceInt32("color",lightGreen); 104 sm->AddItem(item = new BMenuItem("Green",new BMessage(msg))); 105 item->SetTarget(fObjectView); 106 107 msg.RemoveName("color"); 108 109 msg.ReplaceInt32("num",2); 110 m->AddItem(item = new BMenuItem(sm = new BMenu("Lower left"),NULL)); 111 item->SetTarget(fObjectView); 112 msg.AddInt32("color",lightNone); 113 sm->AddItem(item = new BMenuItem("Off",new BMessage(msg))); 114 item->SetTarget(fObjectView); 115 sm->AddSeparatorItem(); 116 msg.ReplaceInt32("color",lightWhite); 117 sm->AddItem(item = new BMenuItem("White",new BMessage(msg))); 118 item->SetTarget(fObjectView); 119 msg.ReplaceInt32("color",lightYellow); 120 sm->AddItem(item = new BMenuItem("Yellow",new BMessage(msg))); 121 item->SetTarget(fObjectView); 122 msg.ReplaceInt32("color",lightBlue); 123 sm->AddItem(item = new BMenuItem("Blue",new BMessage(msg))); 124 item->SetTarget(fObjectView); 125 item->SetMarked(true); 126 msg.ReplaceInt32("color",lightRed); 127 sm->AddItem(item = new BMenuItem("Red",new BMessage(msg))); 128 item->SetTarget(fObjectView); 129 msg.ReplaceInt32("color",lightGreen); 130 sm->AddItem(item = new BMenuItem("Green",new BMessage(msg))); 131 item->SetTarget(fObjectView); 132 133 msg.RemoveName("color"); 134 135 msg.ReplaceInt32("num",3); 136 m->AddItem(item = new BMenuItem(sm = new BMenu("Right"),NULL)); 137 item->SetTarget(fObjectView); 138 msg.AddInt32("color",lightNone); 139 sm->AddItem(item = new BMenuItem("Off",new BMessage(msg))); 140 item->SetTarget(fObjectView); 141 item->SetMarked(true); 142 sm->AddSeparatorItem(); 143 msg.ReplaceInt32("color",lightWhite); 144 sm->AddItem(item = new BMenuItem("White",new BMessage(msg))); 145 item->SetTarget(fObjectView); 146 msg.ReplaceInt32("color",lightYellow); 147 sm->AddItem(item = new BMenuItem("Yellow",new BMessage(msg))); 148 item->SetTarget(fObjectView); 149 msg.ReplaceInt32("color",lightBlue); 150 sm->AddItem(item = new BMenuItem("Blue",new BMessage(msg))); 151 item->SetTarget(fObjectView); 152 msg.ReplaceInt32("color",lightRed); 153 sm->AddItem(item = new BMenuItem("Red",new BMessage(msg))); 154 item->SetTarget(fObjectView); 155 msg.ReplaceInt32("color",lightGreen); 156 sm->AddItem(item = new BMenuItem("Green",new BMessage(msg))); 157 item->SetTarget(fObjectView); 158 159 float f = mb->Bounds().IntegerHeight()+1; 160 SetSizeLimits(32,1024,32+f,1024+f); 161 162 Unlock(); 163 } 164 165 166 bool 167 TeapotWindow::QuitRequested() 168 { 169 // printf("closing \n"); 170 fObjectView->EnableDirectMode( false ); 171 be_app->PostMessage(B_QUIT_REQUESTED); 172 return true; 173 } 174 175 176 void 177 TeapotWindow::DirectConnected(direct_buffer_info* info) 178 { 179 if (fObjectView) 180 fObjectView->DirectConnected( info ); 181 fObjectView->EnableDirectMode( true ); 182 } 183 184 185 void 186 TeapotWindow::MessageReceived(BMessage* msg) 187 { 188 // msg->PrintToStream(); 189 switch (msg->what) { 190 default: 191 BDirectWindow::MessageReceived(msg); 192 } 193 } 194