uses a slider now, uses SetSizeLimits, objects can now be edited after they have been created
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12940 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
45ca1c948c
commit
b7f478e26d
@ -17,7 +17,7 @@ if ( $(TARGET_PLATFORM) = haiku ) {
|
||||
} else {
|
||||
# for running in the Haiku app_server under R5:
|
||||
LinkSharedOSLibs Playground :
|
||||
<boot!home!config!lib>libopenbeos.so ;
|
||||
# be ;
|
||||
# <boot!home!config!lib>libopenbeos.so ;
|
||||
be ;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Message.h>
|
||||
#include <String.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "States.h"
|
||||
@ -22,9 +23,8 @@ ObjectView::ObjectView(BRect frame, const char* name,
|
||||
fScrolling(false),
|
||||
fLastMousePos(0.0, 0.0)
|
||||
{
|
||||
rgb_color bg = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_1_TINT);
|
||||
SetViewColor(bg);
|
||||
SetLowColor(bg);
|
||||
|
||||
SetLowColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_1_TINT));
|
||||
|
||||
BFont font;
|
||||
GetFont(&font);
|
||||
@ -37,12 +37,15 @@ ObjectView::ObjectView(BRect frame, const char* name,
|
||||
void
|
||||
ObjectView::AttachedToWindow()
|
||||
{
|
||||
SetViewColor(B_TRANSPARENT_COLOR);
|
||||
}
|
||||
|
||||
// Draw
|
||||
void
|
||||
ObjectView::Draw(BRect updateRect)
|
||||
{
|
||||
FillRect(updateRect, B_SOLID_LOW);
|
||||
|
||||
rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
rgb_color shadow = tint_color(noTint, B_DARKEN_2_TINT);
|
||||
rgb_color light = tint_color(noTint, B_LIGHTEN_MAX_TINT);
|
||||
@ -95,16 +98,18 @@ ObjectView::MouseDown(BPoint where)
|
||||
Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
|
||||
fScrolling = buttons & B_SECONDARY_MOUSE_BUTTON;
|
||||
|
||||
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
||||
|
||||
if (fScrolling) {
|
||||
fLastMousePos = where;
|
||||
} else {
|
||||
if (!fState)
|
||||
SetState(State::StateFor(fObjectType, fColor, fFill, fPenSize));
|
||||
AddObject(State::StateFor(fObjectType, fColor, fFill, fPenSize));
|
||||
|
||||
if (fState) {
|
||||
Invalidate(fState->Bounds());
|
||||
// Invalidate(fState->Bounds());
|
||||
fState->MouseDown(where);
|
||||
Invalidate(fState->Bounds());
|
||||
// Invalidate(fState->Bounds());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -148,11 +153,18 @@ ObjectView::MouseMoved(BPoint where, uint32 transit,
|
||||
void
|
||||
ObjectView::SetState(State* state)
|
||||
{
|
||||
fState = state;
|
||||
|
||||
if (fState) {
|
||||
Invalidate(fState->Bounds());
|
||||
AddObject(fState);
|
||||
if (fState != state) {
|
||||
if (fState) {
|
||||
fState->SetEditing(false);
|
||||
Invalidate(fState->Bounds());
|
||||
}
|
||||
|
||||
fState = state;
|
||||
|
||||
if (fState) {
|
||||
fState->SetEditing(true);
|
||||
Invalidate(fState->Bounds());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,6 +185,8 @@ ObjectView::AddObject(State* state)
|
||||
if (state) {
|
||||
fStateList.AddItem((void*)state);
|
||||
Window()->PostMessage(MSG_OBJECT_COUNT_CHANGED);
|
||||
|
||||
SetState(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <Slider.h>
|
||||
#include <String.h>
|
||||
#include <RadioButton.h>
|
||||
#include <TextControl.h>
|
||||
@ -40,7 +41,16 @@ enum {
|
||||
|
||||
// constructor
|
||||
ObjectWindow::ObjectWindow(BRect frame, const char* name)
|
||||
: BWindow(frame, name, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
||||
: BWindow(frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||
B_ASYNCHRONOUS_CONTROLS)
|
||||
// : BWindow(frame, name, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||
// 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)
|
||||
{
|
||||
BRect b(Bounds());
|
||||
|
||||
@ -192,9 +202,23 @@ ObjectWindow::ObjectWindow(BRect frame, const char* name)
|
||||
|
||||
// pen size text control
|
||||
b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
|
||||
fPenSizeTC = new BTextControl(b, "width text control", "Width", "",
|
||||
new BMessage(MSG_SET_PEN_SIZE));
|
||||
controlGroup->AddChild(fPenSizeTC);
|
||||
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);
|
||||
|
||||
// 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;
|
||||
float maxHeight = minHeight;
|
||||
SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
|
||||
|
||||
_UpdateControls();
|
||||
}
|
||||
@ -223,9 +247,9 @@ ObjectWindow::MessageReceived(BMessage* message)
|
||||
fObjectView->SetObjectType(type);
|
||||
fFillCB->SetEnabled(type != OBJECT_LINE);
|
||||
if (!fFillCB->IsEnabled())
|
||||
fPenSizeTC->SetEnabled(true);
|
||||
fPenSizeS->SetEnabled(true);
|
||||
else
|
||||
fPenSizeTC->SetEnabled(fFillCB->Value() == B_CONTROL_OFF);
|
||||
fPenSizeS->SetEnabled(fFillCB->Value() == B_CONTROL_OFF);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -233,7 +257,7 @@ ObjectWindow::MessageReceived(BMessage* message)
|
||||
int32 value;
|
||||
if (message->FindInt32("be:value", &value) >= B_OK) {
|
||||
fObjectView->SetStateFill(value);
|
||||
fPenSizeTC->SetEnabled(value == B_CONTROL_OFF);
|
||||
fPenSizeS->SetEnabled(value == B_CONTROL_OFF);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -254,7 +278,7 @@ ObjectWindow::MessageReceived(BMessage* message)
|
||||
break;
|
||||
}
|
||||
case MSG_SET_PEN_SIZE:
|
||||
fObjectView->SetStatePenSize(atof(fPenSizeTC->Text()));
|
||||
fObjectView->SetStatePenSize((float)fPenSizeS->Value());
|
||||
break;
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
@ -273,15 +297,13 @@ ObjectWindow::_UpdateControls() const
|
||||
fFillCB->SetEnabled(fObjectView->ObjectType() != OBJECT_LINE);
|
||||
|
||||
// pen size
|
||||
char string[32];
|
||||
sprintf(string, "%.1f", fObjectView->StatePenSize());
|
||||
fPenSizeTC->SetText(string);
|
||||
fPenSizeS->SetValue((int32)fObjectView->StatePenSize());
|
||||
|
||||
// disable penSize if fill is on
|
||||
if (!fFillCB->IsEnabled())
|
||||
fPenSizeTC->SetEnabled(true);
|
||||
fPenSizeS->SetEnabled(true);
|
||||
else
|
||||
fPenSizeTC->SetEnabled(fFillCB->Value() == B_CONTROL_OFF);
|
||||
fPenSizeS->SetEnabled(fFillCB->Value() == B_CONTROL_OFF);
|
||||
}
|
||||
|
||||
// _UpdateColorControls
|
||||
|
@ -9,6 +9,7 @@ class BButton;
|
||||
class BCheckBox;
|
||||
class BMenuField;
|
||||
class BTextControl;
|
||||
class BSlider;
|
||||
class ObjectView;
|
||||
|
||||
class ObjectWindow : public BWindow {
|
||||
@ -41,7 +42,7 @@ class ObjectWindow : public BWindow {
|
||||
BTextControl* fAlphaTC;
|
||||
|
||||
BCheckBox* fFillCB;
|
||||
BTextControl* fPenSizeTC;
|
||||
BSlider* fPenSizeS;
|
||||
};
|
||||
|
||||
#endif // OBJECT_WINDOW_H
|
||||
|
@ -7,9 +7,10 @@
|
||||
// constructor
|
||||
State::State(rgb_color color, bool fill, float penSize)
|
||||
: fValid(false),
|
||||
fTracking(false),
|
||||
fTrackingStart(-1.0, -1.0),
|
||||
fLastMousePos(-1.0, -1.0),
|
||||
fEditing(true),
|
||||
fTracking(TRACKING_NONE),
|
||||
fStartPoint(-1.0, -1.0),
|
||||
fEndPoint(-1.0, -1.0),
|
||||
fColor(color),
|
||||
fFill(fill),
|
||||
fPenSize(penSize)
|
||||
@ -20,23 +21,35 @@ State::State(rgb_color color, bool fill, float penSize)
|
||||
void
|
||||
State::MouseDown(BPoint where)
|
||||
{
|
||||
fTracking = true;
|
||||
fTrackingStart = fLastMousePos = where;
|
||||
if (_HitTest(where, fStartPoint)) {
|
||||
fTracking = TRACKING_START;
|
||||
fClickOffset = fStartPoint - where;
|
||||
} else if (_HitTest(where, fEndPoint)) {
|
||||
fTracking = TRACKING_END;
|
||||
fClickOffset = fEndPoint - where;
|
||||
} else if (!fValid) {
|
||||
fTracking = TRACKING_END;
|
||||
fStartPoint = fEndPoint = where;
|
||||
fClickOffset.Set(0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
// MouseUp
|
||||
void
|
||||
State::MouseUp(BPoint where)
|
||||
{
|
||||
fTracking = false;
|
||||
fTracking = TRACKING_NONE;
|
||||
}
|
||||
|
||||
// MouseMoved
|
||||
void
|
||||
State::MouseMoved(BPoint where)
|
||||
{
|
||||
if (fTracking) {
|
||||
fLastMousePos = where;
|
||||
if (fTracking == TRACKING_START) {
|
||||
fStartPoint = where + fClickOffset;
|
||||
fValid = true;
|
||||
} else if (fTracking == TRACKING_END) {
|
||||
fEndPoint = where + fClickOffset;
|
||||
fValid = true;
|
||||
}
|
||||
}
|
||||
@ -62,29 +75,86 @@ State::SetPenSize(float penSize)
|
||||
fPenSize = penSize;
|
||||
}
|
||||
|
||||
// SetEditing
|
||||
void
|
||||
State::SetEditing(bool editing)
|
||||
{
|
||||
fEditing = editing;
|
||||
}
|
||||
|
||||
// Bounds
|
||||
BRect
|
||||
State::Bounds() const
|
||||
{
|
||||
if (fValid) {
|
||||
BRect r = _ValidRect();
|
||||
if (!fFill) {
|
||||
float inset = -ceilf(fPenSize / 2.0);
|
||||
r.InsetBy(inset, inset);
|
||||
float inset = -2.0; // for the dots
|
||||
if (!SupportsFill() || !fFill) {
|
||||
inset = min_c(inset, -ceilf(fPenSize / 2.0));
|
||||
}
|
||||
r.InsetBy(inset, inset);
|
||||
return r;
|
||||
}
|
||||
return BRect(0.0, 0.0, -1.0, -1.0);
|
||||
}
|
||||
|
||||
// Draw
|
||||
void
|
||||
State::Draw(BView* view) const
|
||||
{
|
||||
if (fValid && fEditing) {
|
||||
_RenderDot(view, fStartPoint);
|
||||
_RenderDot(view, fEndPoint);
|
||||
}
|
||||
}
|
||||
|
||||
// _ValidRect
|
||||
BRect
|
||||
State::_ValidRect() const
|
||||
{
|
||||
return BRect(min_c(fTrackingStart.x, fLastMousePos.x),
|
||||
min_c(fTrackingStart.y, fLastMousePos.y),
|
||||
max_c(fTrackingStart.x, fLastMousePos.x),
|
||||
max_c(fTrackingStart.y, fLastMousePos.y));
|
||||
return BRect(min_c(fStartPoint.x, fEndPoint.x),
|
||||
min_c(fStartPoint.y, fEndPoint.y),
|
||||
max_c(fStartPoint.x, fEndPoint.x),
|
||||
max_c(fStartPoint.y, fEndPoint.y));
|
||||
}
|
||||
|
||||
// _RenderDot
|
||||
void
|
||||
State::_RenderDot(BView* view, BPoint where) const
|
||||
{
|
||||
view->SetHighColor(0, 0, 0, 255);
|
||||
view->SetPenSize(1.0);
|
||||
view->SetDrawingMode(B_OP_COPY);
|
||||
BRect r(where, where);
|
||||
r.InsetBy(-2.0, -2.0);
|
||||
view->StrokeRect(r);
|
||||
view->SetHighColor(255, 255, 255, 255);
|
||||
r.InsetBy(1.0, 1.0);
|
||||
view->FillRect(r);
|
||||
}
|
||||
|
||||
// _AdjustViewState
|
||||
void
|
||||
State::_AdjustViewState(BView* view) const
|
||||
{
|
||||
if (fColor.alpha < 255)
|
||||
view->SetDrawingMode(B_OP_ALPHA);
|
||||
else
|
||||
view->SetDrawingMode(B_OP_OVER);
|
||||
|
||||
view->SetHighColor(fColor);
|
||||
|
||||
if (!SupportsFill() || !fFill)
|
||||
view->SetPenSize(fPenSize);
|
||||
}
|
||||
|
||||
// _HitTest
|
||||
bool
|
||||
State::_HitTest(BPoint where, BPoint point) const
|
||||
{
|
||||
BRect r(point, point);
|
||||
r.InsetBy(-8.0, -8.0);
|
||||
return r.Contains(where);
|
||||
}
|
||||
|
||||
// LineState
|
||||
@ -93,22 +163,17 @@ class LineState : public State {
|
||||
LineState(rgb_color color, bool fill, float penSize)
|
||||
: State(color, fill, penSize) {}
|
||||
|
||||
virtual BRect Bounds() const
|
||||
{
|
||||
if (fValid) {
|
||||
BRect r = _ValidRect();
|
||||
r.InsetBy(-fPenSize, -fPenSize);
|
||||
return r;
|
||||
}
|
||||
return BRect(0.0, 0.0, -1.0, -1.0);
|
||||
}
|
||||
virtual void Draw(BView* view) const
|
||||
{
|
||||
if (fValid) {
|
||||
view->SetHighColor(fColor);
|
||||
view->SetPenSize(fPenSize);
|
||||
view->StrokeLine(fTrackingStart, fLastMousePos);
|
||||
_AdjustViewState(view);
|
||||
view->StrokeLine(fStartPoint, fEndPoint);
|
||||
}
|
||||
State::Draw(view);
|
||||
}
|
||||
virtual bool SupportsFill() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@ -121,14 +186,13 @@ class RectState : public State {
|
||||
virtual void Draw(BView* view) const
|
||||
{
|
||||
if (fValid) {
|
||||
view->SetHighColor(fColor);
|
||||
_AdjustViewState(view);
|
||||
if (fFill)
|
||||
view->FillRect(_ValidRect());
|
||||
else {
|
||||
view->SetPenSize(fPenSize);
|
||||
else
|
||||
view->StrokeRect(_ValidRect());
|
||||
}
|
||||
}
|
||||
State::Draw(view);
|
||||
}
|
||||
};
|
||||
|
||||
@ -141,16 +205,15 @@ class RoundRectState : public State {
|
||||
virtual void Draw(BView* view) const
|
||||
{
|
||||
if (fValid) {
|
||||
view->SetHighColor(fColor);
|
||||
_AdjustViewState(view);
|
||||
BRect r = _ValidRect();
|
||||
float radius = min_c(r.Width() / 3.0, r.Height() / 3.0);
|
||||
if (fFill)
|
||||
view->FillRoundRect(r, radius, radius);
|
||||
else {
|
||||
view->SetPenSize(fPenSize);
|
||||
else
|
||||
view->StrokeRoundRect(r, radius, radius);
|
||||
}
|
||||
}
|
||||
State::Draw(view);
|
||||
}
|
||||
};
|
||||
|
||||
@ -163,14 +226,13 @@ class EllipseState : public State {
|
||||
virtual void Draw(BView* view) const
|
||||
{
|
||||
if (fValid) {
|
||||
view->SetHighColor(fColor);
|
||||
_AdjustViewState(view);
|
||||
if (fFill)
|
||||
view->FillEllipse(_ValidRect());
|
||||
else {
|
||||
view->SetPenSize(fPenSize);
|
||||
else
|
||||
view->StrokeEllipse(_ValidRect());
|
||||
}
|
||||
}
|
||||
State::Draw(view);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -32,8 +32,12 @@ class State {
|
||||
void SetFill(bool fill);
|
||||
void SetPenSize(float penSize);
|
||||
|
||||
virtual BRect Bounds() const;
|
||||
virtual void Draw(BView* view) const = 0;
|
||||
void SetEditing(bool editing);
|
||||
|
||||
BRect Bounds() const;
|
||||
virtual void Draw(BView* view) const;
|
||||
virtual bool SupportsFill() const
|
||||
{ return true; }
|
||||
|
||||
static State* StateFor(int32 objectType,
|
||||
rgb_color color,
|
||||
@ -41,12 +45,26 @@ class State {
|
||||
|
||||
protected:
|
||||
BRect _ValidRect() const;
|
||||
void _RenderDot(BView* view, BPoint where) const;
|
||||
void _AdjustViewState(BView* view) const;
|
||||
|
||||
bool _HitTest(BPoint where, BPoint point) const;
|
||||
|
||||
bool fValid;
|
||||
|
||||
bool fTracking;
|
||||
BPoint fTrackingStart;
|
||||
BPoint fLastMousePos;
|
||||
bool fEditing;
|
||||
|
||||
enum {
|
||||
TRACKING_NONE = 0,
|
||||
TRACKING_START,
|
||||
TRACKING_END
|
||||
};
|
||||
|
||||
uint32 fTracking;
|
||||
BPoint fClickOffset;
|
||||
|
||||
BPoint fStartPoint;
|
||||
BPoint fEndPoint;
|
||||
|
||||
rgb_color fColor;
|
||||
bool fFill;
|
||||
|
@ -4,4 +4,5 @@
|
||||
sleep 1s
|
||||
../../../../../distro/x86.R1/beos/system/servers/obos_registrar &
|
||||
sleep 1s
|
||||
#../../../../../distro/x86.R1/beos/apps/MiniTerminal
|
||||
../../../../../distro/x86.R1/beos/apps/Playground
|
||||
|
Loading…
Reference in New Issue
Block a user