2005-05-18 00:15:58 +00:00
|
|
|
// main.cpp
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
#include <Application.h>
|
2005-05-20 00:00:52 +00:00
|
|
|
#include <Alert.h>
|
2005-12-13 19:08:18 +00:00
|
|
|
#include <Bitmap.h>
|
2005-05-18 00:15:58 +00:00
|
|
|
#include <Box.h>
|
|
|
|
|
#include <Button.h>
|
|
|
|
|
#include <CheckBox.h>
|
2005-12-13 19:08:18 +00:00
|
|
|
#include <ListItem.h>
|
|
|
|
|
#include <ListView.h>
|
2005-05-18 00:15:58 +00:00
|
|
|
#include <Menu.h>
|
|
|
|
|
#include <MenuBar.h>
|
2005-05-20 23:30:17 +00:00
|
|
|
#include <MenuField.h>
|
2005-05-18 00:15:58 +00:00
|
|
|
#include <MenuItem.h>
|
2005-05-20 23:30:17 +00:00
|
|
|
#include <PopUpMenu.h>
|
2005-07-05 15:40:59 +00:00
|
|
|
#include <ScrollBar.h>
|
|
|
|
|
#include <ScrollView.h>
|
2005-06-03 19:24:36 +00:00
|
|
|
#include <Slider.h>
|
2005-05-18 00:15:58 +00:00
|
|
|
#include <String.h>
|
|
|
|
|
#include <RadioButton.h>
|
2005-12-13 19:08:18 +00:00
|
|
|
#include <TabView.h>
|
2005-05-18 00:15:58 +00:00
|
|
|
#include <TextControl.h>
|
|
|
|
|
#include <TextView.h>
|
|
|
|
|
|
|
|
|
|
#include "ObjectView.h"
|
|
|
|
|
#include "States.h"
|
|
|
|
|
|
|
|
|
|
#include "ObjectWindow.h"
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
MSG_SET_OBJECT_TYPE = 'stot',
|
|
|
|
|
MSG_SET_FILL_OR_STROKE = 'stfs',
|
|
|
|
|
MSG_SET_COLOR = 'stcl',
|
|
|
|
|
MSG_SET_PEN_SIZE = 'stps',
|
2005-05-20 23:30:17 +00:00
|
|
|
MSG_SET_DRAWING_MODE = 'stdm',
|
2005-05-18 00:15:58 +00:00
|
|
|
|
|
|
|
|
MSG_NEW_OBJECT = 'nobj',
|
|
|
|
|
|
|
|
|
|
MSG_UNDO = 'undo',
|
|
|
|
|
MSG_REDO = 'redo',
|
|
|
|
|
|
|
|
|
|
MSG_CLEAR = 'clir',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// constructor
|
|
|
|
|
ObjectWindow::ObjectWindow(BRect frame, const char* name)
|
2005-12-13 19:08:18 +00:00
|
|
|
: BWindow(frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
2005-10-20 13:17:18 +00:00
|
|
|
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
|
2005-06-03 19:24:36 +00:00
|
|
|
// : BWindow(frame, name, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
2005-12-13 19:08:18 +00:00
|
|
|
// B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
|
|
|
|
|
// : BWindow(frame, name, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
2005-06-03 19:24:36 +00:00
|
|
|
// B_ASYNCHRONOUS_CONTROLS)
|
|
|
|
|
// : BWindow(frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
|
|
|
|
// B_ASYNCHRONOUS_CONTROLS)
|
|
|
|
|
// : BWindow(frame, name, B_BORDERED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
|
|
|
|
// B_ASYNCHRONOUS_CONTROLS)
|
|
|
|
|
// : BWindow(frame, name, B_NO_BORDER_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
|
|
|
|
// B_ASYNCHRONOUS_CONTROLS)
|
2005-05-18 00:15:58 +00:00
|
|
|
{
|
|
|
|
|
BRect b(Bounds());
|
|
|
|
|
|
|
|
|
|
b.bottom = b.top + 8;
|
|
|
|
|
BMenuBar* menuBar = new BMenuBar(b, "menu bar");
|
|
|
|
|
AddChild(menuBar);
|
|
|
|
|
|
2005-06-07 13:30:56 +00:00
|
|
|
BMenu* menu = new BMenu("File");
|
2005-05-18 00:15:58 +00:00
|
|
|
menuBar->AddItem(menu);
|
|
|
|
|
|
2005-06-07 13:10:45 +00:00
|
|
|
BMenuItem* menuItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED),
|
2005-06-07 13:30:56 +00:00
|
|
|
'Q');
|
2005-05-18 00:15:58 +00:00
|
|
|
menu->AddItem(menuItem);
|
|
|
|
|
|
|
|
|
|
b = Bounds();
|
|
|
|
|
b.top = menuBar->Bounds().bottom + 1;
|
2005-12-13 19:08:18 +00:00
|
|
|
b.right = ceilf((b.left + b.right) / 2.0);
|
2005-07-05 15:40:59 +00:00
|
|
|
BBox* bg = new BBox(b, "bg box", B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW, B_PLAIN_BORDER);
|
2005-05-18 00:15:58 +00:00
|
|
|
|
|
|
|
|
AddChild(bg);
|
|
|
|
|
bg->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
|
|
|
|
2005-07-05 15:40:59 +00:00
|
|
|
// object view occupies the right side of the window
|
|
|
|
|
b.left = b.right + 1.0;
|
|
|
|
|
b.right = Bounds().right - B_V_SCROLL_BAR_WIDTH;
|
|
|
|
|
b.bottom -= B_H_SCROLL_BAR_HEIGHT;
|
2005-05-18 00:15:58 +00:00
|
|
|
fObjectView = new ObjectView(b, "object view", B_FOLLOW_ALL,
|
|
|
|
|
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
|
2005-07-05 15:40:59 +00:00
|
|
|
// wrap a scroll view around the object view
|
|
|
|
|
BScrollView* scrollView = new BScrollView("object scroller", fObjectView,
|
|
|
|
|
B_FOLLOW_ALL, 0, true, true,
|
|
|
|
|
B_NO_BORDER);
|
|
|
|
|
|
|
|
|
|
if (BScrollBar* scrollBar = fObjectView->ScrollBar(B_VERTICAL)) {
|
|
|
|
|
scrollBar->SetRange(0.0, fObjectView->Bounds().Height());
|
|
|
|
|
scrollBar->SetProportion(0.5);
|
2005-12-13 19:08:18 +00:00
|
|
|
// scrollBar->SetRange(0.0, 0.0);
|
2005-07-05 15:40:59 +00:00
|
|
|
}
|
|
|
|
|
if (BScrollBar* scrollBar = fObjectView->ScrollBar(B_HORIZONTAL)) {
|
|
|
|
|
scrollBar->SetRange(0.0, fObjectView->Bounds().Width());
|
|
|
|
|
scrollBar->SetProportion(0.5);
|
2005-12-13 19:08:18 +00:00
|
|
|
// scrollBar->SetRange(0.0, 0.0);
|
2005-07-05 15:40:59 +00:00
|
|
|
}
|
|
|
|
|
AddChild(scrollView);
|
2005-05-18 00:15:58 +00:00
|
|
|
|
|
|
|
|
b = bg->Bounds();
|
|
|
|
|
// controls occupy the left side of the window
|
2005-07-05 15:40:59 +00:00
|
|
|
b.InsetBy(5.0, 5.0);
|
2005-05-18 00:15:58 +00:00
|
|
|
BBox* controlGroup = new BBox(b, "controls box", B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM,
|
|
|
|
|
B_WILL_DRAW, B_FANCY_BORDER);
|
|
|
|
|
|
|
|
|
|
controlGroup->SetLabel("Controls");
|
|
|
|
|
bg->AddChild(controlGroup);
|
|
|
|
|
|
|
|
|
|
b = controlGroup->Bounds();
|
|
|
|
|
b.top += 10.0;
|
|
|
|
|
b.bottom = b.top + 25.0;
|
|
|
|
|
b.InsetBy(5.0, 5.0);
|
2005-12-13 19:08:18 +00:00
|
|
|
b.right = b.left + b.Width() / 2.0 - 3.0;
|
2005-05-18 00:15:58 +00:00
|
|
|
|
|
|
|
|
// new button
|
|
|
|
|
fNewB = new BButton(b, "new button", "New Object", new BMessage(MSG_NEW_OBJECT));
|
|
|
|
|
controlGroup->AddChild(fNewB);
|
2005-12-13 19:08:18 +00:00
|
|
|
SetDefaultButton(fNewB);
|
2005-05-18 00:15:58 +00:00
|
|
|
|
|
|
|
|
// clear button
|
|
|
|
|
b.OffsetBy(0, fNewB->Bounds().Height() + 5.0);
|
|
|
|
|
fClearB = new BButton(b, "clear button", "Clear", new BMessage(MSG_CLEAR));
|
|
|
|
|
controlGroup->AddChild(fClearB);
|
|
|
|
|
|
|
|
|
|
// object type radio buttons
|
|
|
|
|
BMessage* message;
|
|
|
|
|
BRadioButton* radioButton;
|
|
|
|
|
|
|
|
|
|
b.OffsetBy(0, fClearB->Bounds().Height() + 5.0);
|
|
|
|
|
message = new BMessage(MSG_SET_OBJECT_TYPE);
|
|
|
|
|
message->AddInt32("type", OBJECT_LINE);
|
|
|
|
|
radioButton = new BRadioButton(b, "radio 1", "Line", message);
|
|
|
|
|
controlGroup->AddChild(radioButton);
|
|
|
|
|
|
|
|
|
|
radioButton->SetValue(B_CONTROL_ON);
|
|
|
|
|
|
|
|
|
|
b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
|
|
|
|
|
message = new BMessage(MSG_SET_OBJECT_TYPE);
|
|
|
|
|
message->AddInt32("type", OBJECT_RECT);
|
|
|
|
|
radioButton = new BRadioButton(b, "radio 2", "Rect", message);
|
|
|
|
|
controlGroup->AddChild(radioButton);
|
|
|
|
|
|
|
|
|
|
b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
|
|
|
|
|
message = new BMessage(MSG_SET_OBJECT_TYPE);
|
|
|
|
|
message->AddInt32("type", OBJECT_ROUND_RECT);
|
|
|
|
|
radioButton = new BRadioButton(b, "radio 3", "Round Rect", message);
|
|
|
|
|
controlGroup->AddChild(radioButton);
|
|
|
|
|
|
|
|
|
|
b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
|
|
|
|
|
message = new BMessage(MSG_SET_OBJECT_TYPE);
|
|
|
|
|
message->AddInt32("type", OBJECT_ELLIPSE);
|
|
|
|
|
radioButton = new BRadioButton(b, "radio 4", "Ellipse", message);
|
|
|
|
|
controlGroup->AddChild(radioButton);
|
|
|
|
|
|
2005-05-20 23:30:17 +00:00
|
|
|
// drawing mode
|
2005-06-17 13:23:06 +00:00
|
|
|
BPopUpMenu* popupMenu = new BPopUpMenu("<pick>");
|
2005-05-20 23:30:17 +00:00
|
|
|
|
|
|
|
|
message = new BMessage(MSG_SET_DRAWING_MODE);
|
|
|
|
|
message->AddInt32("mode", B_OP_COPY);
|
2005-06-17 13:23:06 +00:00
|
|
|
popupMenu->AddItem(new BMenuItem("Copy", message));
|
2005-05-20 23:30:17 +00:00
|
|
|
|
|
|
|
|
message = new BMessage(MSG_SET_DRAWING_MODE);
|
|
|
|
|
message->AddInt32("mode", B_OP_OVER);
|
2005-06-17 13:23:06 +00:00
|
|
|
popupMenu->AddItem(new BMenuItem("Over", message));
|
|
|
|
|
|
|
|
|
|
message = new BMessage(MSG_SET_DRAWING_MODE);
|
|
|
|
|
message->AddInt32("mode", B_OP_INVERT);
|
|
|
|
|
popupMenu->AddItem(new BMenuItem("Invert", message));
|
|
|
|
|
|
|
|
|
|
message = new BMessage(MSG_SET_DRAWING_MODE);
|
|
|
|
|
message->AddInt32("mode", B_OP_BLEND);
|
|
|
|
|
popupMenu->AddItem(new BMenuItem("Blend", message));
|
|
|
|
|
|
|
|
|
|
message = new BMessage(MSG_SET_DRAWING_MODE);
|
|
|
|
|
message->AddInt32("mode", B_OP_SELECT);
|
|
|
|
|
popupMenu->AddItem(new BMenuItem("Select", message));
|
|
|
|
|
|
|
|
|
|
message = new BMessage(MSG_SET_DRAWING_MODE);
|
|
|
|
|
message->AddInt32("mode", B_OP_ERASE);
|
|
|
|
|
popupMenu->AddItem(new BMenuItem("Erase", message));
|
|
|
|
|
|
|
|
|
|
message = new BMessage(MSG_SET_DRAWING_MODE);
|
|
|
|
|
message->AddInt32("mode", B_OP_ADD);
|
|
|
|
|
popupMenu->AddItem(new BMenuItem("Add", message));
|
|
|
|
|
|
|
|
|
|
message = new BMessage(MSG_SET_DRAWING_MODE);
|
|
|
|
|
message->AddInt32("mode", B_OP_SUBTRACT);
|
|
|
|
|
popupMenu->AddItem(new BMenuItem("Subtract", message));
|
|
|
|
|
|
|
|
|
|
message = new BMessage(MSG_SET_DRAWING_MODE);
|
|
|
|
|
message->AddInt32("mode", B_OP_MIN);
|
|
|
|
|
popupMenu->AddItem(new BMenuItem("Min", message));
|
|
|
|
|
|
|
|
|
|
message = new BMessage(MSG_SET_DRAWING_MODE);
|
|
|
|
|
message->AddInt32("mode", B_OP_MAX);
|
|
|
|
|
popupMenu->AddItem(new BMenuItem("Max", message));
|
|
|
|
|
|
|
|
|
|
message = new BMessage(MSG_SET_DRAWING_MODE);
|
|
|
|
|
message->AddInt32("mode", B_OP_ALPHA);
|
2005-12-13 19:08:18 +00:00
|
|
|
BMenuItem* item = new BMenuItem("Alpha", message);
|
|
|
|
|
item->SetMarked(true);
|
|
|
|
|
popupMenu->AddItem(item);
|
2005-05-20 23:30:17 +00:00
|
|
|
|
|
|
|
|
b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
|
|
|
|
|
fDrawingModeMF = new BMenuField(b, "drawing mode field", "Mode",
|
|
|
|
|
popupMenu);
|
|
|
|
|
|
|
|
|
|
controlGroup->AddChild(fDrawingModeMF);
|
|
|
|
|
|
|
|
|
|
fDrawingModeMF->SetDivider(fDrawingModeMF->StringWidth(fDrawingModeMF->Label()) + 10.0);
|
2005-06-17 13:23:06 +00:00
|
|
|
|
2005-05-18 00:15:58 +00:00
|
|
|
// red text control
|
2005-06-17 13:23:06 +00:00
|
|
|
b.OffsetBy(0, fDrawingModeMF->Bounds().Height() + 5.0);
|
2005-05-18 00:15:58 +00:00
|
|
|
fRedTC = new BTextControl(b, "red text control", "Red", "",
|
|
|
|
|
new BMessage(MSG_SET_COLOR));
|
|
|
|
|
controlGroup->AddChild(fRedTC);
|
|
|
|
|
|
|
|
|
|
// green text control
|
|
|
|
|
b.OffsetBy(0, fRedTC->Bounds().Height() + 5.0);
|
|
|
|
|
fGreenTC = new BTextControl(b, "green text control", "Green", "",
|
|
|
|
|
new BMessage(MSG_SET_COLOR));
|
|
|
|
|
controlGroup->AddChild(fGreenTC);
|
|
|
|
|
|
|
|
|
|
// blue text control
|
|
|
|
|
b.OffsetBy(0, fGreenTC->Bounds().Height() + 5.0);
|
|
|
|
|
fBlueTC = new BTextControl(b, "blue text control", "Blue", "",
|
|
|
|
|
new BMessage(MSG_SET_COLOR));
|
|
|
|
|
controlGroup->AddChild(fBlueTC);
|
|
|
|
|
|
|
|
|
|
// alpha text control
|
|
|
|
|
b.OffsetBy(0, fBlueTC->Bounds().Height() + 5.0);
|
|
|
|
|
fAlphaTC = new BTextControl(b, "alpha text control", "Alpha", "",
|
|
|
|
|
new BMessage(MSG_SET_COLOR));
|
|
|
|
|
controlGroup->AddChild(fAlphaTC);
|
2005-07-05 15:40:59 +00:00
|
|
|
|
2005-05-18 00:15:58 +00:00
|
|
|
// divide text controls the same
|
2005-07-05 15:40:59 +00:00
|
|
|
float mWidth = fDrawingModeMF->StringWidth(fDrawingModeMF->Label());
|
2005-05-18 00:15:58 +00:00
|
|
|
float rWidth = fRedTC->StringWidth(fRedTC->Label());
|
|
|
|
|
float gWidth = fGreenTC->StringWidth(fGreenTC->Label());
|
|
|
|
|
float bWidth = fBlueTC->StringWidth(fBlueTC->Label());
|
|
|
|
|
float aWidth = fAlphaTC->StringWidth(fAlphaTC->Label());
|
|
|
|
|
|
2005-07-05 15:40:59 +00:00
|
|
|
float width = max_c(mWidth, max_c(rWidth, max_c(gWidth, max_c(bWidth, aWidth)))) + 10.0;
|
|
|
|
|
fDrawingModeMF->SetDivider(width);
|
2005-05-18 00:15:58 +00:00
|
|
|
fRedTC->SetDivider(width);
|
|
|
|
|
fGreenTC->SetDivider(width);
|
|
|
|
|
fBlueTC->SetDivider(width);
|
2005-07-05 15:40:59 +00:00
|
|
|
fAlphaTC->SetDivider(width);
|
2005-05-18 00:15:58 +00:00
|
|
|
|
|
|
|
|
// fill check box
|
|
|
|
|
b.OffsetBy(0, fAlphaTC->Bounds().Height() + 5.0);
|
|
|
|
|
fFillCB = new BCheckBox(b, "fill check box", "Fill",
|
|
|
|
|
new BMessage(MSG_SET_FILL_OR_STROKE));
|
|
|
|
|
controlGroup->AddChild(fFillCB);
|
|
|
|
|
|
|
|
|
|
// pen size text control
|
|
|
|
|
b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
|
2005-06-03 19:24:36 +00:00
|
|
|
b.bottom = b.top + 10.0;//35;
|
|
|
|
|
fPenSizeS = new BSlider(b, "width slider", "Width",
|
|
|
|
|
NULL, 1, 100, B_TRIANGLE_THUMB);
|
|
|
|
|
fPenSizeS->SetLimitLabels("1", "100");
|
|
|
|
|
fPenSizeS->SetModificationMessage(new BMessage(MSG_SET_PEN_SIZE));
|
|
|
|
|
fPenSizeS->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
|
|
|
|
fPenSizeS->SetHashMarkCount(10);
|
|
|
|
|
|
|
|
|
|
controlGroup->AddChild(fPenSizeS);
|
|
|
|
|
|
2005-12-13 19:08:18 +00:00
|
|
|
// list view with objects
|
|
|
|
|
b = controlGroup->Bounds();
|
|
|
|
|
b.top += 10.0;
|
|
|
|
|
b.InsetBy(9.0, 7.0);
|
|
|
|
|
b.left = b.left + b.Width() / 2.0 + 6.0;
|
|
|
|
|
b.right = b.right - B_V_SCROLL_BAR_WIDTH;
|
|
|
|
|
b.bottom = fDrawingModeMF->Frame().top - 5.0;
|
|
|
|
|
|
|
|
|
|
fObjectLV = new BListView(b, "object list", B_MULTIPLE_SELECTION_LIST);
|
|
|
|
|
|
|
|
|
|
// wrap a scroll view around the list view
|
|
|
|
|
scrollView = new BScrollView("list scroller", fObjectLV,
|
|
|
|
|
B_FOLLOW_NONE, 0, false, true,
|
|
|
|
|
B_FANCY_BORDER);
|
|
|
|
|
controlGroup->AddChild(scrollView);
|
|
|
|
|
|
2005-06-03 19:24:36 +00:00
|
|
|
// enforce some size limits
|
|
|
|
|
float minWidth = controlGroup->Frame().Width() + 30.0;
|
|
|
|
|
float minHeight = fPenSizeS->Frame().bottom +
|
|
|
|
|
menuBar->Bounds().Height() + 15.0;
|
|
|
|
|
float maxWidth = minWidth * 4.0;
|
2005-12-13 19:08:18 +00:00
|
|
|
float maxHeight = minHeight + 100;
|
2005-06-03 19:24:36 +00:00
|
|
|
SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
|
2005-05-18 00:15:58 +00:00
|
|
|
|
2005-06-04 11:14:25 +00:00
|
|
|
ResizeTo(max_c(frame.Width(), minWidth), max_c(frame.Height(), minHeight));
|
|
|
|
|
|
2005-05-18 00:15:58 +00:00
|
|
|
_UpdateControls();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// destructor
|
|
|
|
|
ObjectWindow::~ObjectWindow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QuitRequested
|
|
|
|
|
bool
|
|
|
|
|
ObjectWindow::QuitRequested()
|
|
|
|
|
{
|
|
|
|
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MessageReceived
|
|
|
|
|
void
|
|
|
|
|
ObjectWindow::MessageReceived(BMessage* message)
|
|
|
|
|
{
|
|
|
|
|
switch (message->what) {
|
|
|
|
|
case MSG_SET_OBJECT_TYPE: {
|
|
|
|
|
int32 type;
|
|
|
|
|
if (message->FindInt32("type", &type) >= B_OK) {
|
|
|
|
|
fObjectView->SetObjectType(type);
|
|
|
|
|
fFillCB->SetEnabled(type != OBJECT_LINE);
|
2005-05-18 00:51:15 +00:00
|
|
|
if (!fFillCB->IsEnabled())
|
2005-06-03 19:24:36 +00:00
|
|
|
fPenSizeS->SetEnabled(true);
|
2005-05-18 00:51:15 +00:00
|
|
|
else
|
2005-06-03 19:24:36 +00:00
|
|
|
fPenSizeS->SetEnabled(fFillCB->Value() == B_CONTROL_OFF);
|
2005-05-18 00:15:58 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case MSG_SET_FILL_OR_STROKE: {
|
|
|
|
|
int32 value;
|
|
|
|
|
if (message->FindInt32("be:value", &value) >= B_OK) {
|
|
|
|
|
fObjectView->SetStateFill(value);
|
2005-06-03 19:24:36 +00:00
|
|
|
fPenSizeS->SetEnabled(value == B_CONTROL_OFF);
|
2005-05-18 00:15:58 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case MSG_SET_COLOR:
|
|
|
|
|
fObjectView->SetStateColor(_GetColor());
|
2005-05-20 23:30:17 +00:00
|
|
|
_UpdateColorControls();
|
2005-05-18 00:15:58 +00:00
|
|
|
break;
|
2005-12-13 19:08:18 +00:00
|
|
|
case MSG_OBJECT_COUNT_CHANGED: {
|
|
|
|
|
int32 count = fObjectView->CountObjects();
|
|
|
|
|
//printf("MSG_OBJECT_COUNT_CHANGED: %ld\n", count);
|
|
|
|
|
fClearB->SetEnabled(count > 0);
|
|
|
|
|
int32 listCount = fObjectLV->CountItems();
|
|
|
|
|
int32 diff = count - listCount;
|
|
|
|
|
if (diff >= 0) {
|
|
|
|
|
for (int32 i = 0; i < diff; i++)
|
|
|
|
|
fObjectLV->AddItem(new BStringItem("Object"));
|
|
|
|
|
} else {
|
|
|
|
|
for (int32 i = listCount - 1; i >= count; i--)
|
|
|
|
|
delete fObjectLV->RemoveItem(i);
|
|
|
|
|
}
|
2005-05-18 00:15:58 +00:00
|
|
|
break;
|
2005-12-13 19:08:18 +00:00
|
|
|
}
|
2005-05-18 00:15:58 +00:00
|
|
|
case MSG_NEW_OBJECT:
|
|
|
|
|
fObjectView->SetState(NULL);
|
|
|
|
|
break;
|
2005-05-20 00:00:52 +00:00
|
|
|
case MSG_CLEAR: {
|
2005-06-07 13:10:45 +00:00
|
|
|
BAlert *alert = new BAlert("Playground", "Do you really want to clear all drawing objects?", "No", "Yes");
|
|
|
|
|
if (alert->Go() == 1) {
|
2005-05-20 00:00:52 +00:00
|
|
|
fObjectView->MakeEmpty();
|
2005-06-07 13:10:45 +00:00
|
|
|
}
|
2005-05-18 00:15:58 +00:00
|
|
|
break;
|
2005-05-20 00:00:52 +00:00
|
|
|
}
|
2005-05-18 00:15:58 +00:00
|
|
|
case MSG_SET_PEN_SIZE:
|
2005-06-03 19:24:36 +00:00
|
|
|
fObjectView->SetStatePenSize((float)fPenSizeS->Value());
|
2005-05-18 00:15:58 +00:00
|
|
|
break;
|
2005-07-05 15:40:59 +00:00
|
|
|
case MSG_SET_DRAWING_MODE: {
|
|
|
|
|
drawing_mode mode;
|
|
|
|
|
if (message->FindInt32("mode", (int32*)&mode) >= B_OK) {
|
|
|
|
|
fObjectView->SetStateDrawingMode(mode);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-05-18 00:15:58 +00:00
|
|
|
default:
|
|
|
|
|
BWindow::MessageReceived(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _UpdateControls
|
|
|
|
|
void
|
|
|
|
|
ObjectWindow::_UpdateControls() const
|
2005-05-20 23:30:17 +00:00
|
|
|
{
|
|
|
|
|
_UpdateColorControls();
|
|
|
|
|
|
|
|
|
|
// update buttons
|
|
|
|
|
fClearB->SetEnabled(fObjectView->CountObjects() > 0);
|
|
|
|
|
|
|
|
|
|
fFillCB->SetEnabled(fObjectView->ObjectType() != OBJECT_LINE);
|
|
|
|
|
|
|
|
|
|
// pen size
|
2005-06-03 19:24:36 +00:00
|
|
|
fPenSizeS->SetValue((int32)fObjectView->StatePenSize());
|
2005-05-20 23:30:17 +00:00
|
|
|
|
|
|
|
|
// disable penSize if fill is on
|
|
|
|
|
if (!fFillCB->IsEnabled())
|
2005-06-03 19:24:36 +00:00
|
|
|
fPenSizeS->SetEnabled(true);
|
2005-05-20 23:30:17 +00:00
|
|
|
else
|
2005-06-03 19:24:36 +00:00
|
|
|
fPenSizeS->SetEnabled(fFillCB->Value() == B_CONTROL_OFF);
|
2005-05-20 23:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _UpdateColorControls
|
|
|
|
|
void
|
|
|
|
|
ObjectWindow::_UpdateColorControls() const
|
2005-05-18 00:15:58 +00:00
|
|
|
{
|
|
|
|
|
// update color
|
|
|
|
|
rgb_color c = fObjectView->StateColor();
|
|
|
|
|
char string[32];
|
|
|
|
|
|
|
|
|
|
sprintf(string, "%d", c.red);
|
|
|
|
|
fRedTC->SetText(string);
|
|
|
|
|
|
|
|
|
|
sprintf(string, "%d", c.green);
|
|
|
|
|
fGreenTC->SetText(string);
|
|
|
|
|
|
|
|
|
|
sprintf(string, "%d", c.blue);
|
|
|
|
|
fBlueTC->SetText(string);
|
|
|
|
|
|
|
|
|
|
sprintf(string, "%d", c.alpha);
|
|
|
|
|
fAlphaTC->SetText(string);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _GetColor
|
|
|
|
|
rgb_color
|
|
|
|
|
ObjectWindow::_GetColor() const
|
|
|
|
|
{
|
|
|
|
|
rgb_color c;
|
|
|
|
|
c.red = max_c(0, min_c(255, atoi(fRedTC->Text())));
|
|
|
|
|
c.green = max_c(0, min_c(255, atoi(fGreenTC->Text())));
|
|
|
|
|
c.blue = max_c(0, min_c(255, atoi(fBlueTC->Text())));
|
|
|
|
|
c.alpha = max_c(0, min_c(255, atoi(fAlphaTC->Text())));
|
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|