178c1c29bSStephan Aßmus // main.cpp 278c1c29bSStephan Aßmus 378c1c29bSStephan Aßmus #include <stdio.h> 478c1c29bSStephan Aßmus #include <stdlib.h> 578c1c29bSStephan Aßmus 678c1c29bSStephan Aßmus #include <Application.h> 74dfc2afbSAxel Dörfler #include <Alert.h> 8040ce757SStephan Aßmus #include <Bitmap.h> 978c1c29bSStephan Aßmus #include <Box.h> 1078c1c29bSStephan Aßmus #include <Button.h> 1178c1c29bSStephan Aßmus #include <CheckBox.h> 12040ce757SStephan Aßmus #include <ListItem.h> 13040ce757SStephan Aßmus #include <ListView.h> 1478c1c29bSStephan Aßmus #include <Menu.h> 1578c1c29bSStephan Aßmus #include <MenuBar.h> 1681cc749fSStephan Aßmus #include <MenuField.h> 1778c1c29bSStephan Aßmus #include <MenuItem.h> 1881cc749fSStephan Aßmus #include <PopUpMenu.h> 198e05e376SStephan Aßmus #include <ScrollBar.h> 208e05e376SStephan Aßmus #include <ScrollView.h> 21b7f478e2SStephan Aßmus #include <Slider.h> 2278c1c29bSStephan Aßmus #include <String.h> 2378c1c29bSStephan Aßmus #include <RadioButton.h> 24*5a2b3bacSStephan Aßmus #include <Region.h> 25040ce757SStephan Aßmus #include <TabView.h> 2678c1c29bSStephan Aßmus #include <TextControl.h> 2778c1c29bSStephan Aßmus #include <TextView.h> 2878c1c29bSStephan Aßmus 2978c1c29bSStephan Aßmus #include "ObjectView.h" 3078c1c29bSStephan Aßmus #include "States.h" 3178c1c29bSStephan Aßmus 3278c1c29bSStephan Aßmus #include "ObjectWindow.h" 3378c1c29bSStephan Aßmus 3478c1c29bSStephan Aßmus enum { 3578c1c29bSStephan Aßmus MSG_SET_OBJECT_TYPE = 'stot', 3678c1c29bSStephan Aßmus MSG_SET_FILL_OR_STROKE = 'stfs', 3778c1c29bSStephan Aßmus MSG_SET_COLOR = 'stcl', 3878c1c29bSStephan Aßmus MSG_SET_PEN_SIZE = 'stps', 3981cc749fSStephan Aßmus MSG_SET_DRAWING_MODE = 'stdm', 4078c1c29bSStephan Aßmus 4178c1c29bSStephan Aßmus MSG_NEW_OBJECT = 'nobj', 4278c1c29bSStephan Aßmus 4378c1c29bSStephan Aßmus MSG_UNDO = 'undo', 4478c1c29bSStephan Aßmus MSG_REDO = 'redo', 4578c1c29bSStephan Aßmus 4678c1c29bSStephan Aßmus MSG_CLEAR = 'clir', 4775bf993eSStephan Aßmus 4875bf993eSStephan Aßmus MSG_OBJECT_SELECTED = 'obsl', 49269293b0SStephan Aßmus MSG_REMOVE_OBJECT = 'rmob', 5078c1c29bSStephan Aßmus }; 5178c1c29bSStephan Aßmus 5275bf993eSStephan Aßmus // ObjectItem 5375bf993eSStephan Aßmus class ObjectItem : public BStringItem { 5475bf993eSStephan Aßmus public: 5575bf993eSStephan Aßmus ObjectItem(const char* name, State* object) 5675bf993eSStephan Aßmus : BStringItem(name), 5775bf993eSStephan Aßmus fObject(object) 5875bf993eSStephan Aßmus { 5975bf993eSStephan Aßmus } 6075bf993eSStephan Aßmus 6175bf993eSStephan Aßmus State* Object() const 6275bf993eSStephan Aßmus { return fObject; } 6375bf993eSStephan Aßmus 6475bf993eSStephan Aßmus private: 6575bf993eSStephan Aßmus State* fObject; 6675bf993eSStephan Aßmus }; 6775bf993eSStephan Aßmus 68269293b0SStephan Aßmus // ObjectListView 69269293b0SStephan Aßmus class ObjectListView : public BListView { 70269293b0SStephan Aßmus public: 71269293b0SStephan Aßmus ObjectListView(BRect frame, const char* name, list_view_type listType) 72269293b0SStephan Aßmus : BListView(frame, name, listType) 73269293b0SStephan Aßmus { 74269293b0SStephan Aßmus } 75269293b0SStephan Aßmus 76269293b0SStephan Aßmus virtual void KeyDown(const char* bytes, int32 numBytes) 77269293b0SStephan Aßmus { 78269293b0SStephan Aßmus switch (*bytes) { 79269293b0SStephan Aßmus case B_DELETE: 80269293b0SStephan Aßmus Window()->PostMessage(MSG_REMOVE_OBJECT); 81269293b0SStephan Aßmus break; 82269293b0SStephan Aßmus default: 83269293b0SStephan Aßmus BListView::KeyDown(bytes, numBytes); 84269293b0SStephan Aßmus } 85269293b0SStephan Aßmus } 86269293b0SStephan Aßmus }; 87269293b0SStephan Aßmus 8875bf993eSStephan Aßmus // #pragma mark - 8975bf993eSStephan Aßmus 9078c1c29bSStephan Aßmus // constructor 9178c1c29bSStephan Aßmus ObjectWindow::ObjectWindow(BRect frame, const char* name) 9275bf993eSStephan Aßmus // : BWindow(frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 93040ce757SStephan Aßmus // B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) 9475bf993eSStephan Aßmus : BWindow(frame, name, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 9575bf993eSStephan Aßmus B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) 96040ce757SStephan Aßmus // : BWindow(frame, name, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 97b7f478e2SStephan Aßmus // B_ASYNCHRONOUS_CONTROLS) 98b7f478e2SStephan Aßmus // : BWindow(frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 99b7f478e2SStephan Aßmus // B_ASYNCHRONOUS_CONTROLS) 100b7f478e2SStephan Aßmus // : BWindow(frame, name, B_BORDERED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 101b7f478e2SStephan Aßmus // B_ASYNCHRONOUS_CONTROLS) 102b7f478e2SStephan Aßmus // : BWindow(frame, name, B_NO_BORDER_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 103b7f478e2SStephan Aßmus // B_ASYNCHRONOUS_CONTROLS) 10478c1c29bSStephan Aßmus { 10578c1c29bSStephan Aßmus BRect b(Bounds()); 10678c1c29bSStephan Aßmus 10778c1c29bSStephan Aßmus b.bottom = b.top + 8; 10878c1c29bSStephan Aßmus BMenuBar* menuBar = new BMenuBar(b, "menu bar"); 10978c1c29bSStephan Aßmus AddChild(menuBar); 11078c1c29bSStephan Aßmus 111d5233162SStephan Aßmus BMenu* menu = new BMenu("File"); 11278c1c29bSStephan Aßmus menuBar->AddItem(menu); 11378c1c29bSStephan Aßmus 114590fdd3fSStephan Aßmus BMenuItem* menuItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 115d5233162SStephan Aßmus 'Q'); 11678c1c29bSStephan Aßmus menu->AddItem(menuItem); 11778c1c29bSStephan Aßmus 11878c1c29bSStephan Aßmus b = Bounds(); 11978c1c29bSStephan Aßmus b.top = menuBar->Bounds().bottom + 1; 120040ce757SStephan Aßmus b.right = ceilf((b.left + b.right) / 2.0); 1218e05e376SStephan Aßmus BBox* bg = new BBox(b, "bg box", B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW, B_PLAIN_BORDER); 12278c1c29bSStephan Aßmus 12378c1c29bSStephan Aßmus AddChild(bg); 12478c1c29bSStephan Aßmus bg->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 12578c1c29bSStephan Aßmus 1268e05e376SStephan Aßmus // object view occupies the right side of the window 1278e05e376SStephan Aßmus b.left = b.right + 1.0; 1288e05e376SStephan Aßmus b.right = Bounds().right - B_V_SCROLL_BAR_WIDTH; 1298e05e376SStephan Aßmus b.bottom -= B_H_SCROLL_BAR_HEIGHT; 13078c1c29bSStephan Aßmus fObjectView = new ObjectView(b, "object view", B_FOLLOW_ALL, 13178c1c29bSStephan Aßmus B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE); 1328e05e376SStephan Aßmus // wrap a scroll view around the object view 1338e05e376SStephan Aßmus BScrollView* scrollView = new BScrollView("object scroller", fObjectView, 1348e05e376SStephan Aßmus B_FOLLOW_ALL, 0, true, true, 1358e05e376SStephan Aßmus B_NO_BORDER); 13678c1c29bSStephan Aßmus 1378e05e376SStephan Aßmus if (BScrollBar* scrollBar = fObjectView->ScrollBar(B_VERTICAL)) { 1388e05e376SStephan Aßmus scrollBar->SetRange(0.0, fObjectView->Bounds().Height()); 1398e05e376SStephan Aßmus scrollBar->SetProportion(0.5); 140040ce757SStephan Aßmus // scrollBar->SetRange(0.0, 0.0); 1418e05e376SStephan Aßmus } 1428e05e376SStephan Aßmus if (BScrollBar* scrollBar = fObjectView->ScrollBar(B_HORIZONTAL)) { 1438e05e376SStephan Aßmus scrollBar->SetRange(0.0, fObjectView->Bounds().Width()); 1448e05e376SStephan Aßmus scrollBar->SetProportion(0.5); 145040ce757SStephan Aßmus // scrollBar->SetRange(0.0, 0.0); 1468e05e376SStephan Aßmus } 1478e05e376SStephan Aßmus AddChild(scrollView); 14878c1c29bSStephan Aßmus 14978c1c29bSStephan Aßmus b = bg->Bounds(); 15078c1c29bSStephan Aßmus // controls occupy the left side of the window 1518e05e376SStephan Aßmus b.InsetBy(5.0, 5.0); 15278c1c29bSStephan Aßmus BBox* controlGroup = new BBox(b, "controls box", B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, 15378c1c29bSStephan Aßmus B_WILL_DRAW, B_FANCY_BORDER); 15478c1c29bSStephan Aßmus 15578c1c29bSStephan Aßmus controlGroup->SetLabel("Controls"); 15678c1c29bSStephan Aßmus bg->AddChild(controlGroup); 15778c1c29bSStephan Aßmus 15878c1c29bSStephan Aßmus b = controlGroup->Bounds(); 15978c1c29bSStephan Aßmus b.top += 10.0; 16078c1c29bSStephan Aßmus b.bottom = b.top + 25.0; 16178c1c29bSStephan Aßmus b.InsetBy(5.0, 5.0); 162040ce757SStephan Aßmus b.right = b.left + b.Width() / 2.0 - 3.0; 16378c1c29bSStephan Aßmus 16478c1c29bSStephan Aßmus // new button 16578c1c29bSStephan Aßmus fNewB = new BButton(b, "new button", "New Object", new BMessage(MSG_NEW_OBJECT)); 16678c1c29bSStephan Aßmus controlGroup->AddChild(fNewB); 167040ce757SStephan Aßmus SetDefaultButton(fNewB); 16878c1c29bSStephan Aßmus 16978c1c29bSStephan Aßmus // clear button 17078c1c29bSStephan Aßmus b.OffsetBy(0, fNewB->Bounds().Height() + 5.0); 17178c1c29bSStephan Aßmus fClearB = new BButton(b, "clear button", "Clear", new BMessage(MSG_CLEAR)); 17278c1c29bSStephan Aßmus controlGroup->AddChild(fClearB); 17378c1c29bSStephan Aßmus 17478c1c29bSStephan Aßmus // object type radio buttons 17578c1c29bSStephan Aßmus BMessage* message; 17678c1c29bSStephan Aßmus BRadioButton* radioButton; 17778c1c29bSStephan Aßmus 17878c1c29bSStephan Aßmus b.OffsetBy(0, fClearB->Bounds().Height() + 5.0); 17978c1c29bSStephan Aßmus message = new BMessage(MSG_SET_OBJECT_TYPE); 18078c1c29bSStephan Aßmus message->AddInt32("type", OBJECT_LINE); 18178c1c29bSStephan Aßmus radioButton = new BRadioButton(b, "radio 1", "Line", message); 18278c1c29bSStephan Aßmus controlGroup->AddChild(radioButton); 18378c1c29bSStephan Aßmus 18478c1c29bSStephan Aßmus radioButton->SetValue(B_CONTROL_ON); 18578c1c29bSStephan Aßmus 18678c1c29bSStephan Aßmus b.OffsetBy(0, radioButton->Bounds().Height() + 5.0); 18778c1c29bSStephan Aßmus message = new BMessage(MSG_SET_OBJECT_TYPE); 18878c1c29bSStephan Aßmus message->AddInt32("type", OBJECT_RECT); 18978c1c29bSStephan Aßmus radioButton = new BRadioButton(b, "radio 2", "Rect", message); 19078c1c29bSStephan Aßmus controlGroup->AddChild(radioButton); 19178c1c29bSStephan Aßmus 19278c1c29bSStephan Aßmus b.OffsetBy(0, radioButton->Bounds().Height() + 5.0); 19378c1c29bSStephan Aßmus message = new BMessage(MSG_SET_OBJECT_TYPE); 19478c1c29bSStephan Aßmus message->AddInt32("type", OBJECT_ROUND_RECT); 19578c1c29bSStephan Aßmus radioButton = new BRadioButton(b, "radio 3", "Round Rect", message); 19678c1c29bSStephan Aßmus controlGroup->AddChild(radioButton); 19778c1c29bSStephan Aßmus 19878c1c29bSStephan Aßmus b.OffsetBy(0, radioButton->Bounds().Height() + 5.0); 19978c1c29bSStephan Aßmus message = new BMessage(MSG_SET_OBJECT_TYPE); 20078c1c29bSStephan Aßmus message->AddInt32("type", OBJECT_ELLIPSE); 20178c1c29bSStephan Aßmus radioButton = new BRadioButton(b, "radio 4", "Ellipse", message); 20278c1c29bSStephan Aßmus controlGroup->AddChild(radioButton); 20378c1c29bSStephan Aßmus 20481cc749fSStephan Aßmus // drawing mode 205579be6b8SStephan Aßmus BPopUpMenu* popupMenu = new BPopUpMenu("<pick>"); 20681cc749fSStephan Aßmus 20781cc749fSStephan Aßmus message = new BMessage(MSG_SET_DRAWING_MODE); 20881cc749fSStephan Aßmus message->AddInt32("mode", B_OP_COPY); 209579be6b8SStephan Aßmus popupMenu->AddItem(new BMenuItem("Copy", message)); 21081cc749fSStephan Aßmus 21181cc749fSStephan Aßmus message = new BMessage(MSG_SET_DRAWING_MODE); 21281cc749fSStephan Aßmus message->AddInt32("mode", B_OP_OVER); 213579be6b8SStephan Aßmus popupMenu->AddItem(new BMenuItem("Over", message)); 214579be6b8SStephan Aßmus 215579be6b8SStephan Aßmus message = new BMessage(MSG_SET_DRAWING_MODE); 216579be6b8SStephan Aßmus message->AddInt32("mode", B_OP_INVERT); 217579be6b8SStephan Aßmus popupMenu->AddItem(new BMenuItem("Invert", message)); 218579be6b8SStephan Aßmus 219579be6b8SStephan Aßmus message = new BMessage(MSG_SET_DRAWING_MODE); 220579be6b8SStephan Aßmus message->AddInt32("mode", B_OP_BLEND); 221579be6b8SStephan Aßmus popupMenu->AddItem(new BMenuItem("Blend", message)); 222579be6b8SStephan Aßmus 223579be6b8SStephan Aßmus message = new BMessage(MSG_SET_DRAWING_MODE); 224579be6b8SStephan Aßmus message->AddInt32("mode", B_OP_SELECT); 225579be6b8SStephan Aßmus popupMenu->AddItem(new BMenuItem("Select", message)); 226579be6b8SStephan Aßmus 227579be6b8SStephan Aßmus message = new BMessage(MSG_SET_DRAWING_MODE); 228579be6b8SStephan Aßmus message->AddInt32("mode", B_OP_ERASE); 229579be6b8SStephan Aßmus popupMenu->AddItem(new BMenuItem("Erase", message)); 230579be6b8SStephan Aßmus 231579be6b8SStephan Aßmus message = new BMessage(MSG_SET_DRAWING_MODE); 232579be6b8SStephan Aßmus message->AddInt32("mode", B_OP_ADD); 233579be6b8SStephan Aßmus popupMenu->AddItem(new BMenuItem("Add", message)); 234579be6b8SStephan Aßmus 235579be6b8SStephan Aßmus message = new BMessage(MSG_SET_DRAWING_MODE); 236579be6b8SStephan Aßmus message->AddInt32("mode", B_OP_SUBTRACT); 237579be6b8SStephan Aßmus popupMenu->AddItem(new BMenuItem("Subtract", message)); 238579be6b8SStephan Aßmus 239579be6b8SStephan Aßmus message = new BMessage(MSG_SET_DRAWING_MODE); 240579be6b8SStephan Aßmus message->AddInt32("mode", B_OP_MIN); 241579be6b8SStephan Aßmus popupMenu->AddItem(new BMenuItem("Min", message)); 242579be6b8SStephan Aßmus 243579be6b8SStephan Aßmus message = new BMessage(MSG_SET_DRAWING_MODE); 244579be6b8SStephan Aßmus message->AddInt32("mode", B_OP_MAX); 245579be6b8SStephan Aßmus popupMenu->AddItem(new BMenuItem("Max", message)); 246579be6b8SStephan Aßmus 247579be6b8SStephan Aßmus message = new BMessage(MSG_SET_DRAWING_MODE); 248579be6b8SStephan Aßmus message->AddInt32("mode", B_OP_ALPHA); 249040ce757SStephan Aßmus BMenuItem* item = new BMenuItem("Alpha", message); 250040ce757SStephan Aßmus item->SetMarked(true); 251040ce757SStephan Aßmus popupMenu->AddItem(item); 25281cc749fSStephan Aßmus 25381cc749fSStephan Aßmus b.OffsetBy(0, radioButton->Bounds().Height() + 5.0); 25481cc749fSStephan Aßmus fDrawingModeMF = new BMenuField(b, "drawing mode field", "Mode", 25581cc749fSStephan Aßmus popupMenu); 25681cc749fSStephan Aßmus 25781cc749fSStephan Aßmus controlGroup->AddChild(fDrawingModeMF); 25881cc749fSStephan Aßmus 25981cc749fSStephan Aßmus fDrawingModeMF->SetDivider(fDrawingModeMF->StringWidth(fDrawingModeMF->Label()) + 10.0); 260579be6b8SStephan Aßmus 26178c1c29bSStephan Aßmus // red text control 262579be6b8SStephan Aßmus b.OffsetBy(0, fDrawingModeMF->Bounds().Height() + 5.0); 26378c1c29bSStephan Aßmus fRedTC = new BTextControl(b, "red text control", "Red", "", 26478c1c29bSStephan Aßmus new BMessage(MSG_SET_COLOR)); 26578c1c29bSStephan Aßmus controlGroup->AddChild(fRedTC); 26678c1c29bSStephan Aßmus 26778c1c29bSStephan Aßmus // green text control 26878c1c29bSStephan Aßmus b.OffsetBy(0, fRedTC->Bounds().Height() + 5.0); 26978c1c29bSStephan Aßmus fGreenTC = new BTextControl(b, "green text control", "Green", "", 27078c1c29bSStephan Aßmus new BMessage(MSG_SET_COLOR)); 27178c1c29bSStephan Aßmus controlGroup->AddChild(fGreenTC); 27278c1c29bSStephan Aßmus 27378c1c29bSStephan Aßmus // blue text control 27478c1c29bSStephan Aßmus b.OffsetBy(0, fGreenTC->Bounds().Height() + 5.0); 27578c1c29bSStephan Aßmus fBlueTC = new BTextControl(b, "blue text control", "Blue", "", 27678c1c29bSStephan Aßmus new BMessage(MSG_SET_COLOR)); 27778c1c29bSStephan Aßmus controlGroup->AddChild(fBlueTC); 27878c1c29bSStephan Aßmus 27978c1c29bSStephan Aßmus // alpha text control 28078c1c29bSStephan Aßmus b.OffsetBy(0, fBlueTC->Bounds().Height() + 5.0); 28178c1c29bSStephan Aßmus fAlphaTC = new BTextControl(b, "alpha text control", "Alpha", "", 28278c1c29bSStephan Aßmus new BMessage(MSG_SET_COLOR)); 28378c1c29bSStephan Aßmus controlGroup->AddChild(fAlphaTC); 2848e05e376SStephan Aßmus 28578c1c29bSStephan Aßmus // divide text controls the same 2868e05e376SStephan Aßmus float mWidth = fDrawingModeMF->StringWidth(fDrawingModeMF->Label()); 28778c1c29bSStephan Aßmus float rWidth = fRedTC->StringWidth(fRedTC->Label()); 28878c1c29bSStephan Aßmus float gWidth = fGreenTC->StringWidth(fGreenTC->Label()); 28978c1c29bSStephan Aßmus float bWidth = fBlueTC->StringWidth(fBlueTC->Label()); 29078c1c29bSStephan Aßmus float aWidth = fAlphaTC->StringWidth(fAlphaTC->Label()); 29178c1c29bSStephan Aßmus 2928e05e376SStephan Aßmus float width = max_c(mWidth, max_c(rWidth, max_c(gWidth, max_c(bWidth, aWidth)))) + 10.0; 2938e05e376SStephan Aßmus fDrawingModeMF->SetDivider(width); 29478c1c29bSStephan Aßmus fRedTC->SetDivider(width); 29578c1c29bSStephan Aßmus fGreenTC->SetDivider(width); 29678c1c29bSStephan Aßmus fBlueTC->SetDivider(width); 2978e05e376SStephan Aßmus fAlphaTC->SetDivider(width); 29878c1c29bSStephan Aßmus 29978c1c29bSStephan Aßmus // fill check box 30078c1c29bSStephan Aßmus b.OffsetBy(0, fAlphaTC->Bounds().Height() + 5.0); 30178c1c29bSStephan Aßmus fFillCB = new BCheckBox(b, "fill check box", "Fill", 30278c1c29bSStephan Aßmus new BMessage(MSG_SET_FILL_OR_STROKE)); 30378c1c29bSStephan Aßmus controlGroup->AddChild(fFillCB); 30478c1c29bSStephan Aßmus 30578c1c29bSStephan Aßmus // pen size text control 30678c1c29bSStephan Aßmus b.OffsetBy(0, radioButton->Bounds().Height() + 5.0); 307b7f478e2SStephan Aßmus b.bottom = b.top + 10.0;//35; 308b7f478e2SStephan Aßmus fPenSizeS = new BSlider(b, "width slider", "Width", 309b7f478e2SStephan Aßmus NULL, 1, 100, B_TRIANGLE_THUMB); 310b7f478e2SStephan Aßmus fPenSizeS->SetLimitLabels("1", "100"); 311b7f478e2SStephan Aßmus fPenSizeS->SetModificationMessage(new BMessage(MSG_SET_PEN_SIZE)); 312b7f478e2SStephan Aßmus fPenSizeS->SetHashMarks(B_HASH_MARKS_BOTTOM); 313b7f478e2SStephan Aßmus fPenSizeS->SetHashMarkCount(10); 314b7f478e2SStephan Aßmus 315b7f478e2SStephan Aßmus controlGroup->AddChild(fPenSizeS); 316b7f478e2SStephan Aßmus 317040ce757SStephan Aßmus // list view with objects 318040ce757SStephan Aßmus b = controlGroup->Bounds(); 319040ce757SStephan Aßmus b.top += 10.0; 320040ce757SStephan Aßmus b.InsetBy(9.0, 7.0); 321040ce757SStephan Aßmus b.left = b.left + b.Width() / 2.0 + 6.0; 322269293b0SStephan Aßmus b.right -= B_V_SCROLL_BAR_WIDTH; 323040ce757SStephan Aßmus b.bottom = fDrawingModeMF->Frame().top - 5.0; 324040ce757SStephan Aßmus 325269293b0SStephan Aßmus fObjectLV = new ObjectListView(b, "object list", B_MULTIPLE_SELECTION_LIST); 32675bf993eSStephan Aßmus fObjectLV->SetSelectionMessage(new BMessage(MSG_OBJECT_SELECTED)); 327040ce757SStephan Aßmus 328040ce757SStephan Aßmus // wrap a scroll view around the list view 329040ce757SStephan Aßmus scrollView = new BScrollView("list scroller", fObjectLV, 330040ce757SStephan Aßmus B_FOLLOW_NONE, 0, false, true, 331040ce757SStephan Aßmus B_FANCY_BORDER); 332040ce757SStephan Aßmus controlGroup->AddChild(scrollView); 333040ce757SStephan Aßmus 334269293b0SStephan Aßmus // add a dummy tab view 335269293b0SStephan Aßmus b.top = b.bottom + 10.0; 336269293b0SStephan Aßmus b.right += B_V_SCROLL_BAR_WIDTH; 337269293b0SStephan Aßmus b.bottom = controlGroup->Bounds().bottom - 7.0; 338269293b0SStephan Aßmus BTabView* tabView = new BTabView(b, "tab view", B_WIDTH_FROM_WIDEST, 339269293b0SStephan Aßmus B_FOLLOW_ALL, B_FULL_UPDATE_ON_RESIZE | 340269293b0SStephan Aßmus B_WILL_DRAW | B_NAVIGABLE_JUMP | 341269293b0SStephan Aßmus B_FRAME_EVENTS | B_NAVIGABLE); 342269293b0SStephan Aßmus 343269293b0SStephan Aßmus tabView->AddTab(new BView(BRect(0, 0, 40, 40), "T", B_FOLLOW_ALL, 0)); 344269293b0SStephan Aßmus tabView->AddTab(new BView(BRect(0, 0, 40, 40), "T", B_FOLLOW_ALL, 0)); 345269293b0SStephan Aßmus tabView->AddTab(new BView(BRect(0, 0, 40, 40), "T", B_FOLLOW_ALL, 0)); 346269293b0SStephan Aßmus controlGroup->AddChild(tabView); 347269293b0SStephan Aßmus 348b7f478e2SStephan Aßmus // enforce some size limits 349b7f478e2SStephan Aßmus float minWidth = controlGroup->Frame().Width() + 30.0; 350b7f478e2SStephan Aßmus float minHeight = fPenSizeS->Frame().bottom + 351b7f478e2SStephan Aßmus menuBar->Bounds().Height() + 15.0; 352b7f478e2SStephan Aßmus float maxWidth = minWidth * 4.0; 353040ce757SStephan Aßmus float maxHeight = minHeight + 100; 354b7f478e2SStephan Aßmus SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight); 35578c1c29bSStephan Aßmus 356e4bcf6e0SStephan Aßmus ResizeTo(max_c(frame.Width(), minWidth), max_c(frame.Height(), minHeight)); 357e4bcf6e0SStephan Aßmus 35878c1c29bSStephan Aßmus _UpdateControls(); 35978c1c29bSStephan Aßmus } 36078c1c29bSStephan Aßmus 36178c1c29bSStephan Aßmus // destructor 36278c1c29bSStephan Aßmus ObjectWindow::~ObjectWindow() 36378c1c29bSStephan Aßmus { 36478c1c29bSStephan Aßmus } 36578c1c29bSStephan Aßmus 36678c1c29bSStephan Aßmus // QuitRequested 36778c1c29bSStephan Aßmus bool 36878c1c29bSStephan Aßmus ObjectWindow::QuitRequested() 36978c1c29bSStephan Aßmus { 37078c1c29bSStephan Aßmus be_app->PostMessage(B_QUIT_REQUESTED); 37178c1c29bSStephan Aßmus return true; 37278c1c29bSStephan Aßmus } 37378c1c29bSStephan Aßmus 37478c1c29bSStephan Aßmus // MessageReceived 37578c1c29bSStephan Aßmus void 37678c1c29bSStephan Aßmus ObjectWindow::MessageReceived(BMessage* message) 37778c1c29bSStephan Aßmus { 37878c1c29bSStephan Aßmus switch (message->what) { 37978c1c29bSStephan Aßmus case MSG_SET_OBJECT_TYPE: { 38078c1c29bSStephan Aßmus int32 type; 38178c1c29bSStephan Aßmus if (message->FindInt32("type", &type) >= B_OK) { 38278c1c29bSStephan Aßmus fObjectView->SetObjectType(type); 38378c1c29bSStephan Aßmus fFillCB->SetEnabled(type != OBJECT_LINE); 384e803c97cSStephan Aßmus if (!fFillCB->IsEnabled()) 385b7f478e2SStephan Aßmus fPenSizeS->SetEnabled(true); 386e803c97cSStephan Aßmus else 387b7f478e2SStephan Aßmus fPenSizeS->SetEnabled(fFillCB->Value() == B_CONTROL_OFF); 38878c1c29bSStephan Aßmus } 38978c1c29bSStephan Aßmus break; 39078c1c29bSStephan Aßmus } 39178c1c29bSStephan Aßmus case MSG_SET_FILL_OR_STROKE: { 39278c1c29bSStephan Aßmus int32 value; 39378c1c29bSStephan Aßmus if (message->FindInt32("be:value", &value) >= B_OK) { 39478c1c29bSStephan Aßmus fObjectView->SetStateFill(value); 395b7f478e2SStephan Aßmus fPenSizeS->SetEnabled(value == B_CONTROL_OFF); 39678c1c29bSStephan Aßmus } 39778c1c29bSStephan Aßmus break; 39878c1c29bSStephan Aßmus } 39978c1c29bSStephan Aßmus case MSG_SET_COLOR: 40078c1c29bSStephan Aßmus fObjectView->SetStateColor(_GetColor()); 40181cc749fSStephan Aßmus _UpdateColorControls(); 40278c1c29bSStephan Aßmus break; 40375bf993eSStephan Aßmus case MSG_OBJECT_ADDED: { 40475bf993eSStephan Aßmus State* object; 40575bf993eSStephan Aßmus if (message->FindPointer("object", (void**)&object) >= B_OK) { 40675bf993eSStephan Aßmus fObjectLV->AddItem(new ObjectItem("Object", object)); 407040ce757SStephan Aßmus } 40875bf993eSStephan Aßmus // fall through 40975bf993eSStephan Aßmus } 41075bf993eSStephan Aßmus case MSG_OBJECT_COUNT_CHANGED: 41175bf993eSStephan Aßmus fClearB->SetEnabled(fObjectView->CountObjects() > 0); 41278c1c29bSStephan Aßmus break; 41375bf993eSStephan Aßmus case MSG_OBJECT_SELECTED: 41475bf993eSStephan Aßmus if (ObjectItem* item = (ObjectItem*)fObjectLV->ItemAt(fObjectLV->CurrentSelection(0))) { 41575bf993eSStephan Aßmus fObjectView->SetState(item->Object()); 41675bf993eSStephan Aßmus } else 41775bf993eSStephan Aßmus fObjectView->SetState(NULL); 41875bf993eSStephan Aßmus break; 419269293b0SStephan Aßmus case MSG_REMOVE_OBJECT: 420269293b0SStephan Aßmus while (ObjectItem* item = (ObjectItem*)fObjectLV->ItemAt(fObjectLV->CurrentSelection(0))) { 421269293b0SStephan Aßmus fObjectView->RemoveObject(item->Object()); 422269293b0SStephan Aßmus fObjectLV->RemoveItem(item); 423269293b0SStephan Aßmus delete item; 424269293b0SStephan Aßmus } 425269293b0SStephan Aßmus break; 42678c1c29bSStephan Aßmus case MSG_NEW_OBJECT: 42778c1c29bSStephan Aßmus fObjectView->SetState(NULL); 42878c1c29bSStephan Aßmus break; 4294dfc2afbSAxel Dörfler case MSG_CLEAR: { 430269293b0SStephan Aßmus BAlert *alert = new BAlert("Playground", 431269293b0SStephan Aßmus "Do you really want to clear all drawing objects?", 432269293b0SStephan Aßmus "No", "Yes"); 433590fdd3fSStephan Aßmus if (alert->Go() == 1) { 43478c1c29bSStephan Aßmus fObjectView->MakeEmpty(); 435269293b0SStephan Aßmus fObjectLV->MakeEmpty(); 436590fdd3fSStephan Aßmus } 43778c1c29bSStephan Aßmus break; 4384dfc2afbSAxel Dörfler } 43978c1c29bSStephan Aßmus case MSG_SET_PEN_SIZE: 440b7f478e2SStephan Aßmus fObjectView->SetStatePenSize((float)fPenSizeS->Value()); 44178c1c29bSStephan Aßmus break; 4428e05e376SStephan Aßmus case MSG_SET_DRAWING_MODE: { 4438e05e376SStephan Aßmus drawing_mode mode; 4448e05e376SStephan Aßmus if (message->FindInt32("mode", (int32*)&mode) >= B_OK) { 4458e05e376SStephan Aßmus fObjectView->SetStateDrawingMode(mode); 4468e05e376SStephan Aßmus } 4478e05e376SStephan Aßmus break; 4488e05e376SStephan Aßmus } 44978c1c29bSStephan Aßmus default: 45078c1c29bSStephan Aßmus BWindow::MessageReceived(message); 45178c1c29bSStephan Aßmus } 45278c1c29bSStephan Aßmus } 45378c1c29bSStephan Aßmus 45478c1c29bSStephan Aßmus // _UpdateControls 45578c1c29bSStephan Aßmus void 45678c1c29bSStephan Aßmus ObjectWindow::_UpdateControls() const 45778c1c29bSStephan Aßmus { 45881cc749fSStephan Aßmus _UpdateColorControls(); 45981cc749fSStephan Aßmus 46081cc749fSStephan Aßmus // update buttons 46181cc749fSStephan Aßmus fClearB->SetEnabled(fObjectView->CountObjects() > 0); 46281cc749fSStephan Aßmus 46381cc749fSStephan Aßmus fFillCB->SetEnabled(fObjectView->ObjectType() != OBJECT_LINE); 46481cc749fSStephan Aßmus 46581cc749fSStephan Aßmus // pen size 466b7f478e2SStephan Aßmus fPenSizeS->SetValue((int32)fObjectView->StatePenSize()); 46781cc749fSStephan Aßmus 46881cc749fSStephan Aßmus // disable penSize if fill is on 46981cc749fSStephan Aßmus if (!fFillCB->IsEnabled()) 470b7f478e2SStephan Aßmus fPenSizeS->SetEnabled(true); 47181cc749fSStephan Aßmus else 472b7f478e2SStephan Aßmus fPenSizeS->SetEnabled(fFillCB->Value() == B_CONTROL_OFF); 47381cc749fSStephan Aßmus } 47481cc749fSStephan Aßmus 47581cc749fSStephan Aßmus // _UpdateColorControls 47681cc749fSStephan Aßmus void 47781cc749fSStephan Aßmus ObjectWindow::_UpdateColorControls() const 47881cc749fSStephan Aßmus { 47978c1c29bSStephan Aßmus // update color 48078c1c29bSStephan Aßmus rgb_color c = fObjectView->StateColor(); 48178c1c29bSStephan Aßmus char string[32]; 48278c1c29bSStephan Aßmus 48378c1c29bSStephan Aßmus sprintf(string, "%d", c.red); 48478c1c29bSStephan Aßmus fRedTC->SetText(string); 48578c1c29bSStephan Aßmus 48678c1c29bSStephan Aßmus sprintf(string, "%d", c.green); 48778c1c29bSStephan Aßmus fGreenTC->SetText(string); 48878c1c29bSStephan Aßmus 48978c1c29bSStephan Aßmus sprintf(string, "%d", c.blue); 49078c1c29bSStephan Aßmus fBlueTC->SetText(string); 49178c1c29bSStephan Aßmus 49278c1c29bSStephan Aßmus sprintf(string, "%d", c.alpha); 49378c1c29bSStephan Aßmus fAlphaTC->SetText(string); 49478c1c29bSStephan Aßmus } 49578c1c29bSStephan Aßmus 49678c1c29bSStephan Aßmus // _GetColor 49778c1c29bSStephan Aßmus rgb_color 49878c1c29bSStephan Aßmus ObjectWindow::_GetColor() const 49978c1c29bSStephan Aßmus { 50078c1c29bSStephan Aßmus rgb_color c; 50178c1c29bSStephan Aßmus c.red = max_c(0, min_c(255, atoi(fRedTC->Text()))); 50278c1c29bSStephan Aßmus c.green = max_c(0, min_c(255, atoi(fGreenTC->Text()))); 50378c1c29bSStephan Aßmus c.blue = max_c(0, min_c(255, atoi(fBlueTC->Text()))); 50478c1c29bSStephan Aßmus c.alpha = max_c(0, min_c(255, atoi(fAlphaTC->Text()))); 50578c1c29bSStephan Aßmus 50678c1c29bSStephan Aßmus return c; 50778c1c29bSStephan Aßmus } 50878c1c29bSStephan Aßmus 509