hrev44148 adds 3 changesets to branch 'master' old head: 4b140bad0d6ae1622d7461723e909844df9a803b new head: dbfa06fa45d0af8aaf396e8e8183d4658cc15025 ---------------------------------------------------------------------------- f50e7b8: Cleanup & small fixes * Style cleanup * Don't delete message in case they happen to be the passed in pointers. a184e9f: Style clean up. dbfa06f: Fixed dropping color on "current color" swatch * When the color of the "current color" swatch view (the bigger one) changes because of a color drop, adopt the new color just like when changing the color via other means. [ Stephan Aßmus <superstippi@xxxxxx> ] ---------------------------------------------------------------------------- 4 files changed, 162 insertions(+), 181 deletions(-) src/apps/icon-o-matic/generic/gui/SwatchView.cpp | 164 ++++++++---------- src/apps/icon-o-matic/generic/gui/SwatchView.h | 42 ++--- src/apps/icon-o-matic/gui/StyleView.cpp | 1 - src/apps/icon-o-matic/gui/SwatchGroup.cpp | 136 ++++++++------- ############################################################################ Commit: f50e7b8dc594beaaabf630f212852bb983882ddd URL: http://cgit.haiku-os.org/haiku/commit/?id=f50e7b8 Author: Stephan Aßmus <superstippi@xxxxxx> Date: Sat May 12 11:48:54 2012 UTC Cleanup & small fixes * Style cleanup * Don't delete message in case they happen to be the passed in pointers. ---------------------------------------------------------------------------- diff --git a/src/apps/icon-o-matic/generic/gui/SwatchView.cpp b/src/apps/icon-o-matic/generic/gui/SwatchView.cpp index 304d333..e657519 100644 --- a/src/apps/icon-o-matic/generic/gui/SwatchView.cpp +++ b/src/apps/icon-o-matic/generic/gui/SwatchView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2012, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -8,6 +8,7 @@ #include "SwatchView.h" +#include <new> #include <stdio.h> #include <Bitmap.h> @@ -22,62 +23,35 @@ #include "support.h" #include "support_ui.h" + #define DRAG_INIT_DIST 10.0 -// constructor -SwatchView::SwatchView(const char* name, BMessage* message, - BHandler* target, rgb_color color, - float width, float height) - : BView(BRect(0.0, 0.0, width, height), name, - B_FOLLOW_NONE, B_WILL_DRAW), - fColor(color), - fTrackingStart(-1.0, -1.0), - fActive(false), - fDropInvokes(false), - fClickMessage(message), - fDroppedMessage(NULL), - fTarget(target), - fWidth(width), - fHeight(height) + +SwatchView::SwatchView(const char* name, BMessage* message, BHandler* target, + rgb_color color, float width, float height) + : + BView(BRect(0.0, 0.0, width, height), name, B_FOLLOW_NONE, B_WILL_DRAW), + fColor(color), + fTrackingStart(-1.0, -1.0), + fActive(false), + fDropInvokes(false), + fClickMessage(message), + fDroppedMessage(NULL), + fTarget(target), + fWidth(width), + fHeight(height) { SetViewColor(B_TRANSPARENT_32_BIT); SetHighColor(fColor); } -// destructor + SwatchView::~SwatchView() { delete fClickMessage; delete fDroppedMessage; } -#if LIB_LAYOUT -// layoutprefs -minimax -SwatchView::layoutprefs() -{ - if (fWidth > 6.0 && fHeight > 6.0) { - mpm.mini.x = mpm.maxi.x = fWidth; - mpm.mini.y = mpm.maxi.y = fHeight; - } else { - mpm.mini.x = 6.0; - mpm.maxi.x = 10000.0; - mpm.mini.y = 6.0; - mpm.maxi.y = 10000.0; - } - mpm.weight = 1.0; - return mpm; -} - -// layout -BRect -SwatchView::layout(BRect frame) -{ - MoveTo(frame.LeftTop()); - ResizeTo(frame.Width(), frame.Height()); - return Frame(); -} -#endif // LIB_LAYOUT inline void blend_color(rgb_color& a, const rgb_color& b, float alpha) @@ -88,7 +62,7 @@ blend_color(rgb_color& a, const rgb_color& b, float alpha) a.blue = (uint8)(b.blue * alphaInv + a.blue * alpha); } -// Draw + void SwatchView::Draw(BRect updateRect) { @@ -148,27 +122,28 @@ SwatchView::Draw(BRect updateRect) } } -// MessageReceived + void SwatchView::MessageReceived(BMessage* message) { switch (message->what) { - case B_PASTE: { + case B_PASTE: + { rgb_color color; - if (restore_color_from_message(message, - color) >= B_OK) { + if (restore_color_from_message(message, color) == B_OK) { SetColor(color); _Invoke(fDroppedMessage); } break; } + default: BView::MessageReceived(message); break; } } -// MouseDown + void SwatchView::MouseDown(BPoint where) { @@ -176,29 +151,30 @@ SwatchView::MouseDown(BPoint where) fTrackingStart = where; } -// MouseUp + void SwatchView::MouseUp(BPoint where) { - if (Bounds().Contains(where) - && Bounds().Contains(fTrackingStart)) + if (Bounds().Contains(where) && Bounds().Contains(fTrackingStart)) _Invoke(fClickMessage); + fTrackingStart.x = -1.0; fTrackingStart.y = -1.0; } -// MouseMoved + void SwatchView::MouseMoved(BPoint where, uint32 transit, - const BMessage* dragMessage) + const BMessage* dragMessage) { if (transit == B_ENTERED_VIEW) { BCursor cursor(kDropperCursor); SetViewCursor(&cursor, true); } + if (Bounds().Contains(fTrackingStart)) { - if (point_point_distance(where, fTrackingStart) - > DRAG_INIT_DIST || transit == B_EXITED_VIEW) { + if (point_point_distance(where, fTrackingStart) > DRAG_INIT_DIST + || transit == B_EXITED_VIEW) { _DragColor(); fTrackingStart.x = -1.0; fTrackingStart.y = -1.0; @@ -206,7 +182,7 @@ SwatchView::MouseMoved(BPoint where, uint32 transit, } } -// SetColor + void SwatchView::SetColor(rgb_color color) { @@ -215,63 +191,73 @@ SwatchView::SetColor(rgb_color color) Invalidate(); } -// SetClickedMessage + void SwatchView::SetClickedMessage(BMessage* message) { - delete fClickMessage; + if (message != fClickMessage) + delete fClickMessage; fClickMessage = message; } -// SetDroppedMessage + void SwatchView::SetDroppedMessage(BMessage* message) { - delete fDroppedMessage; + if (message != fDroppedMessage) + delete fDroppedMessage; fDroppedMessage = message; } -// _Invoke + void SwatchView::_Invoke(const BMessage* _message) { - if (_message) { - BHandler* target = fTarget ? fTarget - : dynamic_cast<BHandler*>(Window()); - BLooper* looper; - if (target && (looper = target->Looper())) { - BMessage message(*_message); - message.AddPointer("be:source", (void*)this); - message.AddInt64("be:when", system_time()); - message.AddBool("begin", true); - store_color_in_message(&message, fColor); - looper->PostMessage(&message, target); - } - } + if (_message == NULL) + return; + + BHandler* target = fTarget; + if (target == NULL) + target = Window(); + + if (target == NULL) + return; + + BLooper* looper = target->Looper(); + if (looper == NULL) + return; + + BMessage message(*_message); + message.AddPointer("be:source", (void*)this); + message.AddInt64("be:when", system_time()); + message.AddBool("begin", true); + store_color_in_message(&message, fColor); + looper->PostMessage(&message, target); } -// _StrokeRect + void -SwatchView::_StrokeRect(BRect r, rgb_color leftTop, - rgb_color rightBottom) +SwatchView::_StrokeRect(BRect r, rgb_color leftTop, rgb_color rightBottom) { BeginLineArray(4); - AddLine(BPoint(r.left, r.bottom - 1), - BPoint(r.left, r.top), leftTop); - AddLine(BPoint(r.left + 1, r.top), - BPoint(r.right, r.top), leftTop); - AddLine(BPoint(r.right, r.top + 1), - BPoint(r.right, r.bottom), rightBottom); - AddLine(BPoint(r.right - 1, r.bottom), - BPoint(r.left, r.bottom), rightBottom); + + AddLine(BPoint(r.left, r.bottom - 1), BPoint(r.left, r.top), leftTop); + AddLine(BPoint(r.left + 1, r.top), BPoint(r.right, r.top), leftTop); + AddLine(BPoint(r.right, r.top + 1), BPoint(r.right, r.bottom), + rightBottom); + AddLine(BPoint(r.right - 1, r.bottom), BPoint(r.left, r.bottom), + rightBottom); + EndLineArray(); } -// _DragColor + void SwatchView::_DragColor() { - BBitmap *bitmap = new BBitmap(BRect(0.0, 0.0, 15.0, 15.0), B_RGB32); + BBitmap* bitmap = new(std::nothrow) BBitmap(BRect(0.0, 0.0, 15.0, 15.0), + B_RGB32); + BMessage message = make_color_drop_message(fColor, bitmap); DragMessage(&message, bitmap, B_OP_ALPHA, BPoint(9.0, 9.0)); diff --git a/src/apps/icon-o-matic/generic/gui/SwatchView.h b/src/apps/icon-o-matic/generic/gui/SwatchView.h index c6393ac..a8ac1b8 100644 --- a/src/apps/icon-o-matic/generic/gui/SwatchView.h +++ b/src/apps/icon-o-matic/generic/gui/SwatchView.h @@ -1,63 +1,47 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2012, Haiku. * Distributed under the terms of the MIT License. * * Authors: * Stephan Aßmus <superstippi@xxxxxx> */ - #ifndef SWATCH_VIEW_H #define SWATCH_VIEW_H #include <View.h> -#if LIB_LAYOUT -#include <layout.h> -#endif -class SwatchView : - #if LIB_LAYOUT - public MView, - #endif - public BView { - public: - SwatchView(const char* name, - BMessage* message, - BHandler* target, - rgb_color color, - float width = 24.0, - float height = 24.0); +class SwatchView : public BView { +public: + SwatchView(const char* name, BMessage* message, + BHandler* target, rgb_color color, + float width = 24.0, float height = 24.0); virtual ~SwatchView(); - #if LIB_LAYOUT - // MView - virtual minimax layoutprefs(); - virtual BRect layout(BRect frame); - #endif - - // BView + // BView virtual void Draw(BRect updateRect); virtual void MessageReceived(BMessage* message); virtual void MouseDown(BPoint where); virtual void MouseUp(BPoint where); virtual void MouseMoved(BPoint where, uint32 transit, - const BMessage* dragMessage); + const BMessage* dragMessage); - // SwatchView + // SwatchView void SetColor(rgb_color color); - rgb_color Color() const + inline rgb_color Color() const { return fColor; } void SetClickedMessage(BMessage* message); void SetDroppedMessage(BMessage* message); - private: +private: void _Invoke(const BMessage* message); void _StrokeRect(BRect frame, rgb_color leftTop, - rgb_color rightBottom); + rgb_color rightBottom); void _DragColor(); +private: rgb_color fColor; BPoint fTrackingStart; bool fActive; ############################################################################ Commit: a184e9f5b12a808984023b8a840a32f6747db8cb URL: http://cgit.haiku-os.org/haiku/commit/?id=a184e9f Author: Stephan Aßmus <superstippi@xxxxxx> Date: Sat May 12 11:56:09 2012 UTC Style clean up. ---------------------------------------------------------------------------- diff --git a/src/apps/icon-o-matic/gui/StyleView.cpp b/src/apps/icon-o-matic/gui/StyleView.cpp index 80f7944..db64c16 100644 --- a/src/apps/icon-o-matic/gui/StyleView.cpp +++ b/src/apps/icon-o-matic/gui/StyleView.cpp @@ -6,7 +6,6 @@ * Stephan Aßmus <superstippi@xxxxxx> */ - #include "StyleView.h" #include <new> diff --git a/src/apps/icon-o-matic/gui/SwatchGroup.cpp b/src/apps/icon-o-matic/gui/SwatchGroup.cpp index 38f6ba1..8d40192 100644 --- a/src/apps/icon-o-matic/gui/SwatchGroup.cpp +++ b/src/apps/icon-o-matic/gui/SwatchGroup.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2012, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -22,25 +22,28 @@ #include "Group.h" #include "SwatchView.h" + enum { MSG_SET_COLOR = 'stcl', MSG_COLOR_PICKER = 'clpk', MSG_ALPHA_SLIDER = 'alps', }; + #define SWATCH_VIEW_WIDTH 20 #define SWATCH_VIEW_HEIGHT 15 -// constructor + SwatchGroup::SwatchGroup(BRect frame) - : BView(frame, "style view", B_FOLLOW_NONE, 0), + : + BView(frame, "style view", B_FOLLOW_NONE, 0), - fCurrentColor(NULL), - fIgnoreNotifications(false), + fCurrentColor(NULL), + fIgnoreNotifications(false), - fColorPickerPanel(NULL), - fColorPickerMode(H_SELECTED), - fColorPickerFrame(100.0, 100.0, 200.0, 200.0) + fColorPickerPanel(NULL), + fColorPickerMode(H_SELECTED), + fColorPickerFrame(100.0, 100.0, 200.0, 200.0) { frame = BRect(0, 0, 100, 15); fTopSwatchViews = new Group(frame, "top swatch group"); @@ -62,32 +65,33 @@ SwatchGroup::SwatchGroup(BRect frame) h = ((float)(i - 9) / 10.0) * 6.0; v = 0.5; } + HSV_to_RGB(h, s, v, r, g, b); color.red = (uint8)(255.0 * r); color.green = (uint8)(255.0 * g); color.blue = (uint8)(255.0 * b); fSwatchViews[i] = new SwatchView("swatch", new BMessage(MSG_SET_COLOR), - this, color, - SWATCH_VIEW_WIDTH, - SWATCH_VIEW_HEIGHT); + this, color, SWATCH_VIEW_WIDTH, SWATCH_VIEW_HEIGHT); + fSwatchViews[i]->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); + if (i < 10) fTopSwatchViews->AddChild(fSwatchViews[i]); else fBottomSwatchViews->AddChild(fSwatchViews[i]); } - // crrate current color swatch view + + // create current color swatch view fCurrentColorSV = new SwatchView("current swatch", - new BMessage(MSG_COLOR_PICKER), - this, color, 28.0, 28.0); + new BMessage(MSG_COLOR_PICKER), this, color, 28.0, 28.0); // create color field and slider fColorField = new ColorField(BPoint(0.0, 0.0), H_SELECTED, - 1.0, B_HORIZONTAL); + 1.0, B_HORIZONTAL); fColorSlider = new ColorSlider(BPoint(0.0, 0.0), H_SELECTED, - 1.0, 1.0, B_HORIZONTAL); + 1.0, 1.0, B_HORIZONTAL); fAlphaSlider = new AlphaSlider(B_HORIZONTAL, - new BMessage(MSG_ALPHA_SLIDER)); + new BMessage(MSG_ALPHA_SLIDER)); // layout gui fTopSwatchViews->SetSpacing(0, 0); @@ -98,18 +102,18 @@ SwatchGroup::SwatchGroup(BRect frame) fBottomSwatchViews->SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); float paletteHeight = fBottomSwatchViews->Frame().Height() - + fTopSwatchViews->Frame().Height() + 1; + + fTopSwatchViews->Frame().Height() + 1; fTopSwatchViews->MoveTo(paletteHeight + 2, 4); fBottomSwatchViews->MoveTo(paletteHeight + 2, - fTopSwatchViews->Frame().bottom + 1); + fTopSwatchViews->Frame().bottom + 1); fCurrentColorSV->MoveTo(0, fTopSwatchViews->Frame().top); fCurrentColorSV->ResizeTo(paletteHeight, paletteHeight); fCurrentColorSV->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); float width = fTopSwatchViews->Frame().right - - fCurrentColorSV->Frame().left; + - fCurrentColorSV->Frame().left; fColorField->ResizeTo(width, 40); fColorField->FrameResized(width, 40); @@ -136,34 +140,32 @@ SwatchGroup::SwatchGroup(BRect frame) AddChild(fAlphaSlider); } -// destructor + SwatchGroup::~SwatchGroup() { SetCurrentColor(NULL); } -// ObjectChanged + void SwatchGroup::ObjectChanged(const Observable* object) { - if (object == fCurrentColor) { - rgb_color color = fCurrentColor->Color(); - - if (!fIgnoreNotifications) { - float h, s, v; - RGB_to_HSV(color.red / 255.0, - color.green / 255.0, - color.blue / 255.0, - h, s, v); - - _SetColor(h, s, v, color.alpha); - } - } + if (object != fCurrentColor || fIgnoreNotifications) + return; + + rgb_color color = fCurrentColor->Color(); + + float h, s, v; + RGB_to_HSV(color.red / 255.0, color.green / 255.0, color.blue / 255.0, + h, s, v); + + _SetColor(h, s, v, color.alpha); } + // #pragma mark - -// AttachedToWindow + void SwatchGroup::AttachedToWindow() { @@ -172,19 +174,20 @@ SwatchGroup::AttachedToWindow() fAlphaSlider->SetTarget(this); } -// MessageReceived + void SwatchGroup::MessageReceived(BMessage* message) { switch (message->what) { - case MSG_SET_COLOR: { + case MSG_SET_COLOR: + { rgb_color color; if (restore_color_from_message(message, color) == B_OK) { // TODO: fix color picker panel to respect alpha if (message->HasRect("panel frame")) color.alpha = fAlphaSlider->Value(); // - if (fCurrentColor) + if (fCurrentColor != NULL) fCurrentColor->SetColor(color); } // if message contains these fields, @@ -203,30 +206,33 @@ color.alpha = fAlphaSlider->Value(); } break; } - case MSG_COLOR_FIELD: { + + case MSG_COLOR_FIELD: + { // get h from color slider float h = ((255 - fColorSlider->Value()) / 255.0) * 6.0; float s, v; // s and v are comming from the message - if (message->FindFloat("value", &s) >= B_OK - && message->FindFloat("value", 1, &v) >= B_OK) { - + if (message->FindFloat("value", &s) == B_OK + && message->FindFloat("value", 1, &v) == B_OK) { _SetColor(h, s, v, fAlphaSlider->Value()); } break; } - case MSG_COLOR_SLIDER: { + + case MSG_COLOR_SLIDER: + { float h; float s, v; fColorSlider->GetOtherValues(&s, &v); // h is comming from the message - if (message->FindFloat("value", &h) >= B_OK) { - + if (message->FindFloat("value", &h) == B_OK) _SetColor(h, s, v, fAlphaSlider->Value()); - } break; } - case MSG_ALPHA_SLIDER: { + + case MSG_ALPHA_SLIDER: + { float h = (1.0 - (float)fColorSlider->Value() / 255.0) * 6; float s, v; fColorSlider->GetOtherValues(&s, &v); @@ -234,18 +240,16 @@ color.alpha = fAlphaSlider->Value(); break; } - case MSG_COLOR_PICKER: { + case MSG_COLOR_PICKER: + { rgb_color color; if (restore_color_from_message(message, color) < B_OK) break; - if (!fColorPickerPanel) { - fColorPickerPanel - = new ColorPickerPanel(fColorPickerFrame, - color, - fColorPickerMode, - Window(), - new BMessage(MSG_SET_COLOR), - this); + + if (fColorPickerPanel == NULL) { + fColorPickerPanel = new ColorPickerPanel(fColorPickerFrame, + color, fColorPickerMode, Window(), + new BMessage(MSG_SET_COLOR), this); fColorPickerPanel->Show(); } else { if (fColorPickerPanel->Lock()) { @@ -263,37 +267,39 @@ color.alpha = fAlphaSlider->Value(); } } + // #pragma mark - -// SetCurrentColor + void SwatchGroup::SetCurrentColor(CurrentColor* color) { if (fCurrentColor == color) return; - if (fCurrentColor) + if (fCurrentColor != NULL) fCurrentColor->RemoveObserver(this); fCurrentColor = color; - if (fCurrentColor) { + if (fCurrentColor != NULL) { fCurrentColor->AddObserver(this); ObjectChanged(fCurrentColor); } } + // #pragma mark - -// _SetColor + void SwatchGroup::_SetColor(rgb_color color) { fCurrentColorSV->SetColor(color); } -// _SetColor + void SwatchGroup::_SetColor(float h, float s, float v, uint8 a) { @@ -322,8 +328,10 @@ SwatchGroup::_SetColor(float h, float s, float v, uint8 a) } fIgnoreNotifications = true; + if (fCurrentColor) fCurrentColor->SetColor(color); _SetColor(color); + fIgnoreNotifications = false; } ############################################################################ Revision: hrev44148 Commit: dbfa06fa45d0af8aaf396e8e8183d4658cc15025 URL: http://cgit.haiku-os.org/haiku/commit/?id=dbfa06f Author: Stephan Aßmus <superstippi@xxxxxx> Date: Sat May 12 11:58:52 2012 UTC Fixed dropping color on "current color" swatch * When the color of the "current color" swatch view (the bigger one) changes because of a color drop, adopt the new color just like when changing the color via other means. ---------------------------------------------------------------------------- diff --git a/src/apps/icon-o-matic/gui/SwatchGroup.cpp b/src/apps/icon-o-matic/gui/SwatchGroup.cpp index 8d40192..0ad7593 100644 --- a/src/apps/icon-o-matic/gui/SwatchGroup.cpp +++ b/src/apps/icon-o-matic/gui/SwatchGroup.cpp @@ -85,6 +85,10 @@ SwatchGroup::SwatchGroup(BRect frame) fCurrentColorSV = new SwatchView("current swatch", new BMessage(MSG_COLOR_PICKER), this, color, 28.0, 28.0); + // When the color of this swatch changes via drag&drop, we want to + // adopt it as current color. + fCurrentColorSV->SetDroppedMessage(new BMessage(MSG_SET_COLOR)); + // create color field and slider fColorField = new ColorField(BPoint(0.0, 0.0), H_SELECTED, 1.0, B_HORIZONTAL);