From 622853ff8eea408a947c05f25a064132539fec9e Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sun, 29 Dec 2024 00:28:15 -0500 Subject: [PATCH] Appearance and Terminal: Move ColorPreview to shared Move ColorListView and ColorItem to shared in BPrivate namespace. ColorItem typedef to BPrivate::BColorItem for apps that are already using this class. Gravity screensaver: * ColorItem => BColorItem. * Use make_color() to set colors. Make color drop message name agnostic, check for B_RGB_COLOR_TYPE. Add be:sender and source to drag message. Add _SetTermColors() convenience method to set colors on all tabs. Change-Id: I5a9f55d3ab423ccaa341997cf444603373024553 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8846 Reviewed-by: John Scipione --- headers/private/shared/ColorItem.h | 30 +- headers/private/shared/ColorListView.h | 40 +++ headers/private/shared/ColorPreview.h | 47 +++ .../screen_savers/gravity/ConfigView.cpp | 17 +- src/apps/terminal/ColorListView.cpp | 148 --------- src/apps/terminal/ColorListView.h | 31 -- src/apps/terminal/ColorPreview.cpp | 284 ------------------ src/apps/terminal/ColorPreview.h | 51 ---- src/apps/terminal/Jamfile | 2 - src/apps/terminal/TermView.cpp | 8 - src/apps/terminal/TermWindow.cpp | 37 ++- src/apps/terminal/TermWindow.h | 9 +- src/apps/terminal/ThemeView.cpp | 96 +++--- src/apps/terminal/ThemeView.h | 14 +- src/kits/shared/ColorItem.cpp | 31 +- src/kits/shared/ColorListView.cpp | 164 ++++++++++ src/kits/shared/ColorPreview.cpp | 241 +++++++++++++++ src/kits/shared/Jamfile | 2 + src/preferences/appearance/APRView.cpp | 88 +++--- src/preferences/appearance/APRView.h | 8 +- src/preferences/appearance/ColorPreview.cpp | 284 ------------------ src/preferences/appearance/ColorPreview.h | 51 ---- src/preferences/appearance/ColorWhichItem.cpp | 83 ----- src/preferences/appearance/ColorWhichItem.h | 38 --- .../appearance/ColorWhichListView.cpp | 148 --------- .../appearance/ColorWhichListView.h | 31 -- src/preferences/appearance/Jamfile | 5 - src/preferences/appearance/defs.h | 4 - 28 files changed, 694 insertions(+), 1298 deletions(-) create mode 100644 headers/private/shared/ColorListView.h create mode 100755 headers/private/shared/ColorPreview.h delete mode 100644 src/apps/terminal/ColorListView.cpp delete mode 100644 src/apps/terminal/ColorListView.h delete mode 100644 src/apps/terminal/ColorPreview.cpp delete mode 100644 src/apps/terminal/ColorPreview.h create mode 100644 src/kits/shared/ColorListView.cpp create mode 100755 src/kits/shared/ColorPreview.cpp delete mode 100644 src/preferences/appearance/ColorPreview.cpp delete mode 100644 src/preferences/appearance/ColorPreview.h delete mode 100644 src/preferences/appearance/ColorWhichItem.cpp delete mode 100644 src/preferences/appearance/ColorWhichItem.h delete mode 100644 src/preferences/appearance/ColorWhichListView.cpp delete mode 100644 src/preferences/appearance/ColorWhichListView.h diff --git a/headers/private/shared/ColorItem.h b/headers/private/shared/ColorItem.h index 81d1a528a4..d616cc0d65 100644 --- a/headers/private/shared/ColorItem.h +++ b/headers/private/shared/ColorItem.h @@ -1,10 +1,7 @@ /* - * Copyright 2016-2022 Haiku, Inc. All rights reserved. + * Copyright 2016-2024 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * - * Authors: - * John Scipione, jscipione@gmail.com - * * Based on ColorWhichItem by DarkWyrm (bpmagic@columbus.rr.com) */ #ifndef _COLOR_ITEM_H @@ -15,17 +12,32 @@ #include -class ColorItem : public BStringItem { +namespace BPrivate { + + +class BColorItem : public BStringItem { public: - ColorItem(const char* string, rgb_color color); + BColorItem(const char* text, rgb_color color); + BColorItem(const char* text, color_which which, rgb_color color); virtual void DrawItem(BView* owner, BRect frame, bool complete); - void SetColor(rgb_color color) { fColor = color; } - rgb_color Color() const { return fColor; } + + void SetColor(rgb_color color) { fColor = color; }; + rgb_color Color() { return fColor; }; + + color_which ColorWhich() { return fColorWhich; }; private: rgb_color fColor; + color_which fColorWhich; }; -#endif // _COLOR_ITEM_H +} // namespace BPrivate + + +// remove once apps have been updated to use BColorItem +typedef BPrivate::BColorItem ColorItem; + + +#endif // _COLOR_ITEM_H diff --git a/headers/private/shared/ColorListView.h b/headers/private/shared/ColorListView.h new file mode 100644 index 0000000000..a141ac4230 --- /dev/null +++ b/headers/private/shared/ColorListView.h @@ -0,0 +1,40 @@ +/* + * Copyright 2016-2024 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm, darkwyrm@earthlink.net + * John Scipione, jscipione@gmail.com + */ +#ifndef _COLOR_LIST_VIEW_H +#define _COLOR_LIST_VIEW_H + + +#include + + +namespace BPrivate { + + +class BColorListView : public BListView { +public: + enum { + B_MESSAGE_SET_CURRENT_COLOR = 'sccl', + B_MESSAGE_SET_COLOR = 'sclr' + }; + + BColorListView(const char* name, + list_view_type type = B_SINGLE_SELECTION_LIST, + uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); + virtual ~BColorListView(); + + virtual bool InitiateDrag(BPoint where, int32 index, + bool wasSelected); + virtual void MessageReceived(BMessage* message); +}; + + +} // namespace BPrivate + + +#endif // _COLOR_LIST_VIEW_H diff --git a/headers/private/shared/ColorPreview.h b/headers/private/shared/ColorPreview.h new file mode 100755 index 0000000000..cb7708984e --- /dev/null +++ b/headers/private/shared/ColorPreview.h @@ -0,0 +1,47 @@ +/* + * Copyright 2009-2024 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _COLOR_PREVIEW_H +#define _COLOR_PREVIEW_H + + +#include + + +class BMessage; +class BMessageRunner; + + +namespace BPrivate { + + +class BColorPreview : public BControl { +public: + BColorPreview(const char* name, const char* label, + BMessage* message, uint32 flags = B_WILL_DRAW); + virtual ~BColorPreview(); + + virtual void Draw(BRect updateRect); + virtual status_t Invoke(BMessage* message = NULL); + virtual void MessageReceived(BMessage *message); + virtual void MouseDown(BPoint where); + virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* message); + virtual void MouseUp(BPoint where); + + rgb_color Color() const; + void SetColor(rgb_color color); + +private: + void _DragColor(BPoint where); + + rgb_color fColor; + + BMessageRunner* fMessageRunner; +}; + + +} // namespace BPrivate + + +#endif // _COLOR_PREVIEW_H diff --git a/src/add-ons/screen_savers/gravity/ConfigView.cpp b/src/add-ons/screen_savers/gravity/ConfigView.cpp index 8ff5bef569..5f27a83237 100644 --- a/src/add-ons/screen_savers/gravity/ConfigView.cpp +++ b/src/add-ons/screen_savers/gravity/ConfigView.cpp @@ -12,6 +12,7 @@ #include "ConfigView.h" +#include #include #include #include @@ -19,11 +20,13 @@ #include #include -#include "ColorItem.h" #include "Gravity.h" #include "RainbowItem.h" +using BPrivate::BColorItem; + + static const int32 kMsgSize = 'size'; static const int32 kMsgShade = 'shad'; @@ -44,12 +47,12 @@ ConfigView::ConfigView(BRect frame, Gravity* parent) SetViewUIColor(B_PANEL_BACKGROUND_COLOR); fShadeList->SetSelectionMessage(new BMessage(kMsgShade)); - fShadeList->AddItem(new ColorItem("Red", (rgb_color){ 255, 65, 54 })); - fShadeList->AddItem(new ColorItem("Green", (rgb_color){ 46, 204, 64 })); - fShadeList->AddItem(new ColorItem("Blue", (rgb_color){ 0, 116, 217 })); - fShadeList->AddItem(new ColorItem("Orange", (rgb_color){ 255, 133, 27 })); - fShadeList->AddItem(new ColorItem("Purple", (rgb_color){ 177, 13, 201 })); - fShadeList->AddItem(new ColorItem("White", (rgb_color){ 255, 255, 255 })); + fShadeList->AddItem(new BColorItem("Red", make_color(255, 65, 54))); + fShadeList->AddItem(new BColorItem("Green", make_color(46, 204, 64))); + fShadeList->AddItem(new BColorItem("Blue", make_color(0, 116, 217))); + fShadeList->AddItem(new BColorItem("Orange", make_color(255, 133, 27))); + fShadeList->AddItem(new BColorItem("Purple", make_color(177, 13, 201))); + fShadeList->AddItem(new BColorItem("White", make_color(255, 255, 255))); fShadeList->AddItem(new RainbowItem("Rainbow")); fShadeScroll = new BScrollView(B_EMPTY_STRING, fShadeList, diff --git a/src/apps/terminal/ColorListView.cpp b/src/apps/terminal/ColorListView.cpp deleted file mode 100644 index 9c51de01a8..0000000000 --- a/src/apps/terminal/ColorListView.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2016-2022 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * John Scipione, jscipione@gmail.com - */ - - -#include "ColorListView.h" - -#include - -#include -#include - -#include -#include - -#include "ColorItem.h" -#include "ThemeView.h" - - -// golden ratio -#ifdef M_PHI -# undef M_PHI -#endif -#define M_PHI 1.61803398874989484820 - - -// #pragma mark - ColorListView - - -ColorListView::ColorListView(const char* name, - list_view_type type, uint32 flags) - : - BListView(name, type, flags) -{ -} - - -ColorListView::~ColorListView() -{ -} - - -bool -ColorListView::InitiateDrag(BPoint where, int32 index, bool wasSelected) -{ - ColorItem* colorItem - = dynamic_cast(ItemAt(index)); - if (colorItem == NULL) - return false; - - rgb_color color = colorItem->Color(); - - BString hexStr; - hexStr.SetToFormat("#%.2X%.2X%.2X", color.red, color.green, color.blue); - - BMessage message(B_PASTE); - message.AddData("text/plain", B_MIME_TYPE, hexStr.String(), - hexStr.Length()); - message.AddData(kRGBColor, B_RGB_COLOR_TYPE, &color, sizeof(color)); - - float itemHeight = colorItem->Height() - 5; - BRect rect(0.0f, 0.0f, roundf(itemHeight * M_PHI) - 1, itemHeight - 1); - - BBitmap* bitmap = new BBitmap(rect, B_RGB32, true); - if (bitmap->Lock()) { - BView* view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW); - bitmap->AddChild(view); - - view->SetHighColor(B_TRANSPARENT_COLOR); - view->FillRect(view->Bounds()); - - ++rect.top; - ++rect.left; - - view->SetHighColor(0, 0, 0, 100); - view->FillRect(rect); - rect.OffsetBy(-1.0f, -1.0f); - - view->SetHighColor(std::min(255, (int)(1.2 * color.red + 40)), - std::min(255, (int)(1.2 * color.green + 40)), - std::min(255, (int)(1.2 * color.blue + 40))); - view->StrokeRect(rect); - - ++rect.left; - ++rect.top; - - view->SetHighColor((int32)(0.8 * color.red), - (int32)(0.8 * color.green), - (int32)(0.8 * color.blue)); - view->StrokeRect(rect); - - --rect.right; - --rect.bottom; - - view->SetHighColor(color.red, color.green, color.blue); - view->FillRect(rect); - view->Sync(); - - bitmap->Unlock(); - } - - DragMessage(&message, bitmap, B_OP_ALPHA, BPoint(14.0f, 14.0f)); - - return true; -} - - -void -ColorListView::MessageReceived(BMessage* message) -{ - // if we received a dropped message, see if it contains color data - if (message->WasDropped()) { - BPoint dropPoint = message->DropPoint(); - ConvertFromScreen(&dropPoint); - int32 index = IndexOf(dropPoint); - ColorItem* item = dynamic_cast(ItemAt(index)); - rgb_color* color; - ssize_t size; - if (item != NULL && message->FindData(kRGBColor, B_RGB_COLOR_TYPE, - (const void**)&color, &size) == B_OK) { - // build message to send to ThemeView - uint32 command = index == CurrentSelection() - ? MSG_SET_CURRENT_COLOR : MSG_SET_COLOR; - BMessage setColorMessage = BMessage(command); - setColorMessage.AddData(kRGBColor, B_RGB_COLOR_TYPE, color, size); - // if setting different color, add which color to set - if (command == MSG_SET_COLOR) - setColorMessage.AddString(kName, item->Text()); - - // build messenger and send message - BMessenger messenger = BMessenger(Parent()); - if (messenger.IsValid()) { - messenger.SendMessage(&setColorMessage); - if (command == MSG_SET_COLOR) { - // redraw item, MSG_SET_CURRENT_COLOR does this for us - item->SetColor(*color); - InvalidateItem(index); - } - } - } - } - - BListView::MessageReceived(message); -} diff --git a/src/apps/terminal/ColorListView.h b/src/apps/terminal/ColorListView.h deleted file mode 100644 index d57f0da076..0000000000 --- a/src/apps/terminal/ColorListView.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2016-2022 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * John Scipione, jscipione@gmail.com - */ -#ifndef COLORWHICH_LIST_VIEW_H -#define COLORWHICH_LIST_VIEW_H - - -#include - - -class ColorListView : public BListView -{ -public: - ColorListView(const char* name, - list_view_type type - = B_SINGLE_SELECTION_LIST, - uint32 flags = B_WILL_DRAW - | B_FRAME_EVENTS | B_NAVIGABLE); - virtual ~ColorListView(); - - virtual bool InitiateDrag(BPoint where, int32 index, - bool wasSelected); - virtual void MessageReceived(BMessage* message); -}; - - -#endif // COLORWHICH_LIST_VIEW_H diff --git a/src/apps/terminal/ColorPreview.cpp b/src/apps/terminal/ColorPreview.cpp deleted file mode 100644 index 98c88a586e..0000000000 --- a/src/apps/terminal/ColorPreview.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright 2002-2022 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * DarkWyrm, darkwyrm@earthlink.net - * John Scipione, jscipione@gmail.com - */ - - -#include "ColorPreview.h" - -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include "ThemeView.h" -#include "TermConst.h" - - -static const int32 kMsgMessageRunner = 'MsgR'; - - -// #pragma mark - ColorPreview - - -ColorPreview::ColorPreview(BMessage* message, uint32 flags) - : - BControl("ColorPreview", "", message, flags | B_WILL_DRAW), - fColor(ui_color(B_PANEL_BACKGROUND_COLOR)), - fDisabledColor((rgb_color){ 128, 128, 128 }), - fMessageRunner(NULL), - fIsRectangle(true) -{ - SetViewColor(B_TRANSPARENT_COLOR); - SetLowColor(0, 0, 0); - SetExplicitSize(BSize(StringWidth("M") * 8, StringWidth("M") * 7)); -} - - -ColorPreview::~ColorPreview(void) -{ -} - - -void -ColorPreview::Draw(BRect updateRect) -{ - rgb_color color; - if (IsEnabled()) - color = fColor; - else - color = fDisabledColor; - - if (fIsRectangle) { - if (IsEnabled()) { - rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR); - rgb_color shadow = tint_color(background, B_DARKEN_1_TINT); - rgb_color darkShadow = tint_color(background, B_DARKEN_3_TINT); - rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT); - - BRect bounds(Bounds()); - - BeginLineArray(4); - AddLine(BPoint(bounds.left, bounds.bottom), - BPoint(bounds.left, bounds.top), shadow); - AddLine(BPoint(bounds.left + 1.0, bounds.top), - BPoint(bounds.right, bounds.top), shadow); - AddLine(BPoint(bounds.right, bounds.top + 1.0), - BPoint(bounds.right, bounds.bottom), light); - AddLine(BPoint(bounds.right - 1.0, bounds.bottom), - BPoint(bounds.left + 1.0, bounds.bottom), light); - EndLineArray(); - bounds.InsetBy(1.0, 1.0); - - BeginLineArray(4); - AddLine(BPoint(bounds.left, bounds.bottom), - BPoint(bounds.left, bounds.top), darkShadow); - AddLine(BPoint(bounds.left + 1.0, bounds.top), - BPoint(bounds.right, bounds.top), darkShadow); - AddLine(BPoint(bounds.right, bounds.top + 1.0), - BPoint(bounds.right, bounds.bottom), background); - AddLine(BPoint(bounds.right - 1.0, bounds.bottom), - BPoint(bounds.left + 1.0, bounds.bottom), background); - EndLineArray(); - bounds.InsetBy(1.0, 1.0); - - SetHighColor(color); - FillRect(bounds); - } else { - SetHighColor(color); - FillRect(Bounds()); - } - } else { - // fill background - SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - FillRect(updateRect); - - SetHighColor(color); - FillEllipse(Bounds()); - - if (IsEnabled()) - StrokeEllipse(Bounds(), B_SOLID_LOW); - } -} - - -void -ColorPreview::MessageReceived(BMessage* message) -{ - // If we received a dropped message, see if it contains color data - if (message->WasDropped()) { - rgb_color* color; - ssize_t size; - if (message->FindData(kRGBColor, B_RGB_COLOR_TYPE, - (const void**)&color, &size) == B_OK) { - BMessage setColorMessage(MSG_SET_CURRENT_COLOR); - setColorMessage.AddData(kRGBColor, B_RGB_COLOR_TYPE, color, - sizeof(rgb_color)); - Invoke(&setColorMessage); - } - } else if ((int32)message->what == kMsgMessageRunner) { - BPoint where; - uint32 buttons; - GetMouse(&where, &buttons); - - _DragColor(where); - } - - BControl::MessageReceived(message); -} - - -void -ColorPreview::MouseDown(BPoint where) -{ - BWindow* window = Window(); - if (window != NULL) - window->Activate(); - - fMessageRunner = new BMessageRunner(this, new BMessage(kMsgMessageRunner), - 300000, 1); - - SetMouseEventMask(B_POINTER_EVENTS, - B_SUSPEND_VIEW_FOCUS | B_LOCK_WINDOW_FOCUS); - - BRect rect = Bounds().InsetByCopy(2.0f, 2.0f); - rect.top = roundf(rect.bottom / 2.0f + 1); - - if (rect.Contains(where)) { - Invalidate(); - Invoke(); - } - - BControl::MouseDown(where); -} - - -void -ColorPreview::MouseMoved(BPoint where, uint32 transit, const BMessage* message) -{ - if (fMessageRunner != NULL) - _DragColor(where); - - BControl::MouseMoved(where, transit, message); -} - - -void -ColorPreview::MouseUp(BPoint where) -{ - delete fMessageRunner; - fMessageRunner = NULL; - - BControl::MouseUp(where); -} - - -rgb_color -ColorPreview::Color(void) const -{ - return fColor; -} - - -void -ColorPreview::SetColor(rgb_color color) -{ - color.alpha = 255; - - SetHighColor(color); - fColor = color; - - Invalidate(); - Invoke(); -} - - -void -ColorPreview::SetColor(uint8 red, uint8 green, uint8 blue) -{ - SetHighColor(red, green, blue); - fColor.red = red; - fColor.green = green; - fColor.blue = blue; - fColor.alpha = 255; - - Invalidate(); - Invoke(); -} - - -void -ColorPreview::SetMode(bool rectangle) -{ - fIsRectangle = rectangle; -} - - -// #pragma mark - ColorPreview private methods - - -void -ColorPreview::_DragColor(BPoint where) -{ - BString hexStr; - hexStr.SetToFormat("#%.2X%.2X%.2X", fColor.red, fColor.green, fColor.blue); - - BMessage message(B_PASTE); - message.AddData("text/plain", B_MIME_TYPE, hexStr.String(), - hexStr.Length()); - message.AddData(kRGBColor, B_RGB_COLOR_TYPE, &fColor, sizeof(fColor)); - - BRect rect(0.0f, 0.0f, 20.0f, 20.0f); - - BBitmap* bitmap = new BBitmap(rect, B_RGB32, true); - if (bitmap->Lock()) { - BView* view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW); - bitmap->AddChild(view); - - view->SetHighColor(B_TRANSPARENT_COLOR); - view->FillRect(view->Bounds()); - - ++rect.top; - ++rect.left; - - view->SetHighColor(0, 0, 0, 100); - view->FillRect(rect); - rect.OffsetBy(-1.0f, -1.0f); - - view->SetHighColor(std::min(255, (int)(1.2 * fColor.red + 40)), - std::min(255, (int)(1.2 * fColor.green + 40)), - std::min(255, (int)(1.2 * fColor.blue + 40))); - view->StrokeRect(rect); - - ++rect.left; - ++rect.top; - - view->SetHighColor((int32)(0.8 * fColor.red), - (int32)(0.8 * fColor.green), - (int32)(0.8 * fColor.blue)); - view->StrokeRect(rect); - - --rect.right; - --rect.bottom; - - view->SetHighColor(fColor.red, fColor.green, fColor.blue); - view->FillRect(rect); - view->Sync(); - - bitmap->Unlock(); - } - - DragMessage(&message, bitmap, B_OP_ALPHA, BPoint(14.0f, 14.0f)); - - MouseUp(where); -} diff --git a/src/apps/terminal/ColorPreview.h b/src/apps/terminal/ColorPreview.h deleted file mode 100644 index 3794b25c3a..0000000000 --- a/src/apps/terminal/ColorPreview.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2002-2022 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * DarkWyrm, darkwyrm@earthlink.net - * John Scipione, jscipione@gmail.com - */ -#ifndef COLOR_PREVIEW_H_ -#define COLOR_PREVIEW_H_ - - -#include - - -class BMessage; -class BMessageRunner; - - -class ColorPreview : public BControl -{ -public: - ColorPreview(BMessage* message, - uint32 flags = B_WILL_DRAW); - ~ColorPreview(void); - - virtual void Draw(BRect updateRect); - virtual void MessageReceived(BMessage* message); - virtual void MouseDown(BPoint where); - virtual void MouseMoved(BPoint where, uint32 transit, - const BMessage* message); - virtual void MouseUp(BPoint where); - - rgb_color Color(void) const; - void SetColor(rgb_color color); - void SetColor(uint8 r, uint8 g, uint8 b); - - void SetMode(bool rectangle); - -private: - void _DragColor(BPoint where); - - rgb_color fColor; - rgb_color fDisabledColor; - - BMessageRunner* fMessageRunner; - - bool fIsRectangle; -}; - -#endif // COLOR_PREVIEW_H_ diff --git a/src/apps/terminal/Jamfile b/src/apps/terminal/Jamfile index ccb43d9f86..cca7d88659 100644 --- a/src/apps/terminal/Jamfile +++ b/src/apps/terminal/Jamfile @@ -11,8 +11,6 @@ Application Terminal : Arguments.cpp BasicTerminalBuffer.cpp Colors.cpp - ColorListView.cpp - ColorPreview.cpp FindWindow.cpp Globals.cpp HistoryBuffer.cpp diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index c233330e9b..e6f2be3fc8 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -1641,14 +1641,6 @@ TermView::MessageReceived(BMessage *message) _DoFileDrop(ref); } return; -#if 0 - } else if (message->FindData("RGBColor", B_RGB_COLOR_TYPE, - (const void **)&color, &numBytes) == B_OK - && numBytes == sizeof(color)) { - // TODO: handle color drop - // maybe only on replicants ? - return; -#endif } else if (message->FindData("text/plain", B_MIME_TYPE, (const void **)&text, &numBytes) == B_OK) { _WritePTY(text, numBytes); diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index c000f7f191..29a74e404a 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2007-2022, Haiku, Inc. All rights reserved. + * Copyright 2007-2025 Haiku, Inc. All rights reserved. * Copyright (c) 2004 Daniel Furrer * Copyright (c) 2003-2004 Kian Duffy * Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. @@ -26,10 +26,11 @@ #include #include #include -#include #include #include #include +#include +#include #include #include #include @@ -50,8 +51,8 @@ #include #include #include -#include #include +#include #include @@ -706,6 +707,9 @@ TermWindow::MessageReceived(BMessage *message) int32 encodingId; bool findresult; + if (message->WasDropped()) + _SetTermColors(); + switch (message->what) { case B_KEY_MAP_LOADED: _UpdateKeymap(); @@ -1003,18 +1007,12 @@ TermWindow::MessageReceived(BMessage *message) break; case MSG_COLOR_SCHEME_CHANGED: - case MSG_SET_CURRENT_COLOR: - case MSG_SET_COLOR: + case BColorListView::B_MESSAGE_SET_CURRENT_COLOR: + case BColorListView::B_MESSAGE_SET_COLOR: case MSG_UPDATE_COLOR: - { - for (int32 i = fTabView->CountTabs() - 1; i >= 0; i--) { - TermViewContainerView* container = _TermViewContainerViewAt(i); - _SetTermColors(container); - container->Invalidate(); - } - _ActiveTermView()->Invalidate(); + _SetTermColors(); break; - } + case MSG_SAVE_AS_DEFAULT: { BPath path; @@ -1220,6 +1218,19 @@ TermWindow::WindowActivated(bool activated) } +void +TermWindow::_SetTermColors() +{ + for (int32 index = fTabView->CountTabs() - 1; index >= 0; index--) { + TermViewContainerView* container = _TermViewContainerViewAt(index); + _SetTermColors(container); + container->Invalidate(); + } + + _ActiveTermView()->Invalidate(); +} + + void TermWindow::_SetTermColors(TermViewContainerView* containerView) { diff --git a/src/apps/terminal/TermWindow.h b/src/apps/terminal/TermWindow.h index d92475148f..5ec3505e4d 100644 --- a/src/apps/terminal/TermWindow.h +++ b/src/apps/terminal/TermWindow.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2010, Haiku. + * Copyright 2001-2025 Haiku, Inc. All rights reserved * Copyright (c) 2003-4 Kian Duffy * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * @@ -136,12 +136,11 @@ private: struct Session; private: - void _SetTermColors( - TermViewContainerView* containerView); + void _SetTermColors(); + void _SetTermColors(TermViewContainerView* containerView); void _InitWindow(); void _SetupMenu(); - static BMenu* _MakeFontSizeMenu(uint32 command, - uint8 defaultSize); + static BMenu* _MakeFontSizeMenu(uint32 command, uint8 defaultSize); void _UpdateSwitchTerminalsMenuItem(); status_t _GetWindowPositionFile(BFile* file, diff --git a/src/apps/terminal/ThemeView.cpp b/src/apps/terminal/ThemeView.cpp index 35a2f05cb6..53888c3966 100644 --- a/src/apps/terminal/ThemeView.cpp +++ b/src/apps/terminal/ThemeView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022 Haiku, Inc. All rights reserved. + * Copyright 2022-2025 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include #include @@ -23,19 +25,23 @@ #include "ThemeWindow.h" #include "Colors.h" -#include "ColorPreview.h" -#include "ColorListView.h" -#include "ColorItem.h" #include "TermConst.h" #include "PrefHandler.h" + #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "Terminal ThemeView" + #define COLOR_DROPPED 'cldp' #define DECORATOR_CHANGED 'dcch' +using BPrivate::BColorItem; +using BPrivate::BColorListView; +using BPrivate::BColorPreview; + + /* static */ const char* ThemeView::kColorTable[] = { B_TRANSLATE_MARK("Text"), @@ -72,7 +78,7 @@ ThemeView::ThemeView(const char* name, const BMessenger& messenger) SetViewUIColor(B_PANEL_BACKGROUND_COLOR); // Set up list of color attributes - fAttrList = new ColorListView("AttributeList"); + fAttrList = new BColorListView("AttributeList"); fScrollView = new BScrollView("ScrollView", fAttrList, 0, false, true); fScrollView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); @@ -80,17 +86,14 @@ ThemeView::ThemeView(const char* name, const BMessenger& messenger) PrefHandler* prefHandler = PrefHandler::Default(); for (const char** table = kColorTable; *table != NULL; ++table) { - fAttrList->AddItem(new ColorItem(B_TRANSLATE_NOCOLLECT(*table), - prefHandler->getRGB(*table))); + fAttrList->AddItem( + new BColorItem(B_TRANSLATE_NOCOLLECT(*table), prefHandler->getRGB(*table))); } fColorSchemeMenu = new BPopUpMenu(""); - fColorSchemeField = new BMenuField(B_TRANSLATE("Color scheme:"), - fColorSchemeMenu); + fColorSchemeField = new BMenuField(B_TRANSLATE("Color scheme:"), fColorSchemeMenu); - fColorPreview = new ColorPreview(new BMessage(COLOR_DROPPED), 0); - fColorPreview->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, - B_ALIGN_VERTICAL_CENTER)); + fColorPreview = new BColorPreview("color preview", "", new BMessage(COLOR_DROPPED)); fPicker = new BColorControl(B_ORIGIN, B_CELLS_32x8, 8.0, "picker", new BMessage(MSG_UPDATE_COLOR)); @@ -109,8 +112,7 @@ ThemeView::ThemeView(const char* name, const BMessenger& messenger) .AddGlue() .Add(fPicker); - fColorPreview->Parent()->SetExplicitMaxSize( - BSize(B_SIZE_UNSET, fPicker->Bounds().Height())); + fColorPreview->Parent()->SetExplicitMaxSize(BSize(B_SIZE_UNSET, fPicker->Bounds().Height())); fAttrList->SetSelectionMessage(new BMessage(MSG_COLOR_ATTRIBUTE_CHOSEN)); fScrollView->SetExplicitMinSize(BSize(B_SIZE_UNSET, 22 * 16)); fColorSchemeField->SetAlignment(B_ALIGN_RIGHT); @@ -277,45 +279,48 @@ ThemeView::UpdateMenu() void -ThemeView::MessageReceived(BMessage *msg) +ThemeView::MessageReceived(BMessage* message) { bool modified = false; - switch (msg->what) { + if (message->WasDropped()) { + char* name; + type_code type; + rgb_color* color; + ssize_t size; + if (message->GetInfo(B_RGB_COLOR_TYPE, 0, &name, &type) == B_OK + && message->FindData(name, type, (const void**)&color, &size) == B_OK) { + _SetCurrentColor(*color); + modified = true; + } + } + + switch (message->what) { case MSG_COLOR_SCHEME_CHANGED: { color_scheme* newScheme = NULL; - if (msg->FindPointer("color_scheme", - (void**)&newScheme) == B_OK) { + if (message->FindPointer("color_scheme", (void**)&newScheme) == B_OK) { _ChangeColorScheme(newScheme); modified = true; } break; } - case MSG_SET_COLOR: + case BColorListView::B_MESSAGE_SET_CURRENT_COLOR: + case BColorListView::B_MESSAGE_SET_COLOR: { + // Received from color list view when color changes + char* name; + type_code type; rgb_color* color; ssize_t size; - const char* name; - - if (msg->FindData(kRGBColor, B_RGB_COLOR_TYPE, - (const void**)&color, &size) == B_OK - && msg->FindString(kName, &name) == B_OK) { - _SetColor(name, *color); - modified = true; - } - break; - } - - case MSG_SET_CURRENT_COLOR: - { - rgb_color* color; - ssize_t size; - - if (msg->FindData(kRGBColor, B_RGB_COLOR_TYPE, - (const void**)&color, &size) == B_OK) { - _SetCurrentColor(*color); + if (message->GetInfo(B_RGB_COLOR_TYPE, 0, &name, &type) == B_OK + && message->FindData(name, type, (const void**)&color, &size) == B_OK) { + bool current = message->GetBool("current", false); + if (current) + _SetCurrentColor(*color); + else + _SetColor(name, *color); modified = true; } break; @@ -345,17 +350,17 @@ ThemeView::MessageReceived(BMessage *msg) case MSG_THEME_MODIFIED: _SetCurrentColorScheme(); - BView::MessageReceived(msg); + BView::MessageReceived(message); return; default: - BView::MessageReceived(msg); + BView::MessageReceived(message); break; } if (modified) { _UpdateStyle(); - fTerminalMessenger.SendMessage(msg); + fTerminalMessenger.SendMessage(message); BMessenger messenger(this); messenger.SendMessage(MSG_THEME_MODIFIED); @@ -370,13 +375,13 @@ ThemeView::SetDefaults() int32 count = fAttrList->CountItems(); for (int32 index = 0; index < count; ++index) { - ColorItem* item = (ColorItem*)fAttrList->ItemAt(index); + BColorItem* item = static_cast(fAttrList->ItemAt(index)); item->SetColor(prefHandler->getRGB(kColorTable[index])); fAttrList->InvalidateItem(index); } int32 currentIndex = fAttrList->CurrentSelection(); - ColorItem* item = (ColorItem*)fAttrList->ItemAt(currentIndex); + BColorItem* item = static_cast(fAttrList->ItemAt(currentIndex)); if (item != NULL) { rgb_color color = item->Color(); fPicker->SetValue(color); @@ -430,7 +435,7 @@ ThemeView::_ChangeColorScheme(color_scheme* scheme) int32 count = fAttrList->CountItems(); for (int32 index = 0; index < count; ++index) { - ColorItem* item = static_cast(fAttrList->ItemAt(index)); + BColorItem* item = static_cast(fAttrList->ItemAt(index)); rgb_color color = pref->getRGB(kColorTable[index]); item->SetColor(color); @@ -526,7 +531,7 @@ void ThemeView::_SetCurrentColor(rgb_color color) { int32 currentIndex = fAttrList->CurrentSelection(); - ColorItem* item = (ColorItem*)fAttrList->ItemAt(currentIndex); + BColorItem* item = static_cast(fAttrList->ItemAt(currentIndex)); if (item != NULL) { item->SetColor(color); fAttrList->InvalidateItem(currentIndex); @@ -536,7 +541,6 @@ ThemeView::_SetCurrentColor(rgb_color color) fPicker->SetValue(color); fColorPreview->SetColor(color); - fColorPreview->Invalidate(); } diff --git a/src/apps/terminal/ThemeView.h b/src/apps/terminal/ThemeView.h index e93f69ba58..4f480db7a1 100644 --- a/src/apps/terminal/ThemeView.h +++ b/src/apps/terminal/ThemeView.h @@ -1,5 +1,5 @@ /* - * Copyright 2022, Haiku. All rights reserved. + * Copyright 2022-2025 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef THEME_VIEW_H @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -27,18 +28,17 @@ #include "Colors.h" +using BPrivate::BColorPreview; + + static const uint32 MSG_COLOR_SCHEME_CHANGED = 'mccs'; -static const uint32 MSG_SET_CURRENT_COLOR = 'sccl'; static const uint32 MSG_UPDATE_COLOR = 'upcl'; static const uint32 MSG_COLOR_ATTRIBUTE_CHOSEN = 'atch'; static const uint32 MSG_THEME_MODIFIED = 'tmdf'; -static const uint32 MSG_SET_COLOR = 'sclr'; -static const char* const kRGBColor = "RGBColor"; -static const char* const kName = "name"; class ThemeWindow; -class ColorPreview; +class BColorPreview; class BMenu; class BMenuField; class BPopUpMenu; @@ -73,7 +73,7 @@ private: BListView* fAttrList; const char* fName; BScrollView* fScrollView; - ColorPreview* fColorPreview; + BColorPreview* fColorPreview; BMenuField* fColorSchemeField; BPopUpMenu* fColorSchemeMenu; BTextView* fPreview; diff --git a/src/kits/shared/ColorItem.cpp b/src/kits/shared/ColorItem.cpp index 0c1b0df212..8353f1343b 100644 --- a/src/kits/shared/ColorItem.cpp +++ b/src/kits/shared/ColorItem.cpp @@ -1,15 +1,18 @@ /* - * Copyright 2016-2022 Haiku, Inc. All rights reserved. + * Copyright 2016-2024 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: + * DarkWyrm, bpmagic@columbus.rr.com + * Rene Gollent, rene@gollent.com + * Ryan Leavengood, leavengood@gmail.com * John Scipione, jscipione@gmail.com * * Based on ColorWhichItem by DarkWyrm (bpmagic@columbus.rr.com) */ -#include "ColorItem.h" +#include #include @@ -24,19 +27,32 @@ #define M_PHI 1.61803398874989484820 -// #pragma mark - ColorItem +namespace BPrivate { -ColorItem::ColorItem(const char* string, rgb_color color) +// #pragma mark - BColorItem + + +BColorItem::BColorItem(const char* string, rgb_color color) : BStringItem(string, 0, false), - fColor(color) + fColor(color), + fColorWhich(B_NO_COLOR) +{ +} + + +BColorItem::BColorItem(const char* string, color_which which, rgb_color color) + : + BStringItem(string, 0, false), + fColor(color), + fColorWhich(which) { } void -ColorItem::DrawItem(BView* owner, BRect frame, bool complete) +BColorItem::DrawItem(BView* owner, BRect frame, bool complete) { rgb_color highColor = owner->HighColor(); rgb_color lowColor = owner->LowColor(); @@ -87,3 +103,6 @@ ColorItem::DrawItem(BView* owner, BRect frame, bool complete) owner->SetHighColor(highColor); owner->SetLowColor(lowColor); } + + +} // namespace BPrivate diff --git a/src/kits/shared/ColorListView.cpp b/src/kits/shared/ColorListView.cpp new file mode 100644 index 0000000000..4edc141fc9 --- /dev/null +++ b/src/kits/shared/ColorListView.cpp @@ -0,0 +1,164 @@ +/* + * Copyright 2016-2024 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm, darkwyrm@earthlink.net + * John Scipione, jscipione@gmail.com + */ + + +#include + +#include + +#include +#include + +#include +#include +#include + + +// golden ratio +#ifdef M_PHI +# undef M_PHI +#endif +#define M_PHI 1.61803398874989484820 + + +namespace BPrivate { + + +// #pragma mark - ColorListView + + +BColorListView::BColorListView(const char* name, list_view_type type, uint32 flags) + : + BListView(name, type, flags) +{ +} + + +BColorListView::~BColorListView() +{ +} + + +bool +BColorListView::InitiateDrag(BPoint where, int32 index, bool wasSelected) +{ + BColorItem* item = dynamic_cast(ItemAt(index)); + if (item == NULL) + return false; + + rgb_color color = item->Color(); + + BString hexStr; + hexStr.SetToFormat("#%.2X%.2X%.2X", color.red, color.green, color.blue); + + BMessage message(B_PASTE); + message.AddData("text/plain", B_MIME_TYPE, hexStr.String(), hexStr.Length()); + message.AddData("RGBColor", B_RGB_COLOR_TYPE, &color, sizeof(color)); + message.AddMessenger("be:sender", BMessenger(this)); + message.AddPointer("source", this); + message.AddInt64("when", (int64)system_time()); + + float itemHeight = item->Height() - 5; + BRect rect(0, 0, roundf(itemHeight * M_PHI) - 1, itemHeight - 1); + + BBitmap* bitmap = new BBitmap(rect, B_RGB32, true); + if (bitmap->Lock()) { + BView* view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW); + bitmap->AddChild(view); + + view->SetHighColor(B_TRANSPARENT_COLOR); + view->FillRect(view->Bounds()); + + ++rect.top; + ++rect.left; + + view->SetHighColor(0, 0, 0, 100); + view->FillRect(rect); + rect.OffsetBy(-1, -1); + + int32 red = (int32)std::min(255, (int)(1.2 * color.red + 40)); + int32 green = (int32)std::min(255, (int)(1.2 * color.green + 40)); + int32 blue = (int32)std::min(255, (int)(1.2 * color.blue + 40)); + + view->SetHighColor(red, green, blue); + view->StrokeRect(rect); + + ++rect.left; + ++rect.top; + + red = (int32)(0.8 * color.red); + green = (int32)(0.8 * color.green); + blue = (int32)(0.8 * color.blue); + + view->SetHighColor(red, green, blue); + view->StrokeRect(rect); + + --rect.right; + --rect.bottom; + + view->SetHighColor(color.red, color.green, color.blue); + view->FillRect(rect); + view->Sync(); + + bitmap->Unlock(); + } + + DragMessage(&message, bitmap, B_OP_ALPHA, BPoint(14, 14)); + + return true; +} + + +void +BColorListView::MessageReceived(BMessage* message) +{ + // if we received a dropped message, see if it contains color data + if (!message->WasDropped()) + return BListView::MessageReceived(message); + + BPoint dropPoint = message->DropPoint(); + ConvertFromScreen(&dropPoint); + int32 index = IndexOf(dropPoint); + BColorItem* item = dynamic_cast(ItemAt(index)); + if (item == NULL) + return BListView::MessageReceived(message); + + char* name; + type_code type; + rgb_color* color; + ssize_t size; + if (message->GetInfo(B_RGB_COLOR_TYPE, 0, &name, &type) == B_OK + && message->FindData(name, type, (const void**)&color, &size) == B_OK) { + // set message command to set current color or new + bool current = index == CurrentSelection(); + uint32 command = (current ? BColorListView::B_MESSAGE_SET_CURRENT_COLOR + : BColorListView::B_MESSAGE_SET_COLOR); + message->what = command; + + // if setting different color, add which color to set + if (current) + message->AddBool("current", true); + else + message->AddUInt32("which", (uint32)item->ColorWhich()); + + // build messenger and send message + BMessenger messenger = BMessenger(Parent()); + if (messenger.IsValid()) + messenger.SendMessage(message); + + // set current color redraws for us + if (!current) { + item->SetColor(*color); + InvalidateItem(index); + } + } +} + + +} // namespace BPrivate diff --git a/src/kits/shared/ColorPreview.cpp b/src/kits/shared/ColorPreview.cpp new file mode 100755 index 0000000000..23f73f0ebd --- /dev/null +++ b/src/kits/shared/ColorPreview.cpp @@ -0,0 +1,241 @@ +/* + * Copyright 2009-2024 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm, darkwyrm@earthlink.net + * John Scipione, jscipione@gmail.com + */ + + +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + + +static const int32 kMsgMessageRunner = 'MsgR'; + +static const rgb_color kRed = make_color(255, 0, 0, 255); + + +namespace BPrivate { + + +BColorPreview::BColorPreview(const char* name, const char* label, BMessage* message, uint32 flags) + : + BControl(name, label, message, flags), + fColor(kRed), + fMessageRunner(NULL) +{ + SetExplicitSize(BSize(roundf(StringWidth("M") * 6), roundf(StringWidth("M") * 6))); + SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER)); +} + + +BColorPreview::~BColorPreview() +{ +} + + +void +BColorPreview::Draw(BRect updateRect) +{ + rgb_color color = fColor; + + rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR); + rgb_color outer = tint_color(bg, B_DARKEN_1_TINT); + rgb_color inner = tint_color(bg, B_DARKEN_3_TINT); + rgb_color light = tint_color(bg, B_LIGHTEN_MAX_TINT); + + BRect bounds(Bounds()); + + BeginLineArray(4); + AddLine(BPoint(bounds.left, bounds.bottom), BPoint(bounds.left, bounds.top), outer); + AddLine(BPoint(bounds.left + 1, bounds.top), BPoint(bounds.right, bounds.top), outer); + AddLine(BPoint(bounds.right, bounds.top + 1), BPoint(bounds.right, bounds.bottom), light); + AddLine(BPoint(bounds.right - 1, bounds.bottom), BPoint(bounds.left + 1, bounds.bottom), + light); + EndLineArray(); + + bounds.InsetBy(1, 1); + + BeginLineArray(4); + AddLine(BPoint(bounds.left, bounds.bottom), BPoint(bounds.left, bounds.top), inner); + AddLine(BPoint(bounds.left + 1, bounds.top), BPoint(bounds.right, bounds.top), inner); + AddLine(BPoint(bounds.right, bounds.top + 1), BPoint(bounds.right, bounds.bottom), bg); + AddLine(BPoint(bounds.right - 1, bounds.bottom), BPoint(bounds.left + 1, bounds.bottom), bg); + EndLineArray(); + + bounds.InsetBy(1, 1); + + SetHighColor(color); + FillRect(bounds); +} + + +status_t +BColorPreview::Invoke(BMessage* message) +{ + if (message == NULL) + message = new BMessage(B_PASTE); + + if (message->CountNames(B_RGB_COLOR_TYPE) == 0) + message->AddData("RGBColor", B_RGB_COLOR_TYPE, &fColor, sizeof(fColor)); + + return BControl::Invoke(message); +} + + +void +BColorPreview::MessageReceived(BMessage* message) +{ + if (message->WasDropped()) { + char* name; + type_code type; + rgb_color* color; + ssize_t size; + if (message->GetInfo(B_RGB_COLOR_TYPE, 0, &name, &type) == B_OK + && message->FindData(name, type, (const void**)&color, &size) == B_OK) { + SetColor(*color); + Invoke(message); + } + } + + switch (message->what) { + case kMsgMessageRunner: + { + BPoint where; + uint32 buttons; + GetMouse(&where, &buttons); + + _DragColor(where); + break; + } + + default: + BControl::MessageReceived(message); + break; + } +} + + +void +BColorPreview::MouseDown(BPoint where) +{ + fMessageRunner = new BMessageRunner(this, new BMessage(kMsgMessageRunner), 300000, 1); + + BControl::MouseDown(where); +} + + +void +BColorPreview::MouseMoved(BPoint where, uint32 transit, const BMessage* message) +{ + if (fMessageRunner != NULL) + _DragColor(where); + + BControl::MouseMoved(where, transit, message); +} + + +void +BColorPreview::MouseUp(BPoint where) +{ + delete fMessageRunner; + fMessageRunner = NULL; + + BControl::MouseUp(where); +} + + +rgb_color +BColorPreview::Color() const +{ + return fColor; +} + + +void +BColorPreview::SetColor(rgb_color color) +{ + color.alpha = 255; + fColor = color; + + Invalidate(); +} + + +void +BColorPreview::_DragColor(BPoint where) +{ + BString hexStr; + hexStr.SetToFormat("#%.2X%.2X%.2X", fColor.red, fColor.green, fColor.blue); + + BMessage message(B_PASTE); + message.AddData("text/plain", B_MIME_TYPE, hexStr.String(), hexStr.Length()); + message.AddData("RGBColor", B_RGB_COLOR_TYPE, &fColor, sizeof(fColor)); + message.AddMessenger("be:sender", BMessenger(this)); + message.AddPointer("source", this); + message.AddInt64("when", (int64)system_time()); + + BRect rect(0, 0, 16, 16); + + BBitmap* bitmap = new BBitmap(rect, B_RGB32, true); + if (bitmap->Lock()) { + BView* view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW); + bitmap->AddChild(view); + + view->SetHighColor(B_TRANSPARENT_COLOR); + view->FillRect(view->Bounds()); + + ++rect.top; + ++rect.left; + + view->SetHighColor(0, 0, 0, 100); + view->FillRect(rect); + rect.OffsetBy(-1, -1); + + int32 red = std::min(255, (int)(1.2 * fColor.red + 40)); + int32 green = std::min(255, (int)(1.2 * fColor.green + 40)); + int32 blue = std::min(255, (int)(1.2 * fColor.blue + 40)); + + view->SetHighColor(red, green, blue); + view->StrokeRect(rect); + + ++rect.left; + ++rect.top; + + red = (int32)(0.8 * fColor.red); + green = (int32)(0.8 * fColor.green); + blue = (int32)(0.8 * fColor.blue); + + view->SetHighColor(red, green, blue); + view->StrokeRect(rect); + + --rect.right; + --rect.bottom; + + view->SetHighColor(fColor.red, fColor.green, fColor.blue); + view->FillRect(rect); + view->Sync(); + + bitmap->Unlock(); + } + + DragMessage(&message, bitmap, B_OP_ALPHA, BPoint(14.0f, 14.0f)); + + MouseUp(where); +} + + +} // namespace BPrivate diff --git a/src/kits/shared/Jamfile b/src/kits/shared/Jamfile index 3c2d0a1fe2..08fc206733 100644 --- a/src/kits/shared/Jamfile +++ b/src/kits/shared/Jamfile @@ -32,6 +32,8 @@ for architectureObject in [ MultiArchSubDirSetup ] { BitmapButton.cpp CalendarView.cpp ColorItem.cpp + ColorListView.cpp + ColorPreview.cpp ColorQuantizer.cpp CommandPipe.cpp DateTimeEdit.cpp diff --git a/src/preferences/appearance/APRView.cpp b/src/preferences/appearance/APRView.cpp index 12fe3baa9a..05a065698d 100644 --- a/src/preferences/appearance/APRView.cpp +++ b/src/preferences/appearance/APRView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 Haiku, Inc. All rights reserved. + * Copyright 2002-2025 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -16,6 +16,8 @@ #include #include +#include +#include #include #include #include @@ -29,19 +31,22 @@ #include "APRWindow.h" #include "defs.h" -#include "ColorPreview.h" #include "Colors.h" -#include "ColorWhichListView.h" -#include "ColorWhichItem.h" #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "Colors tab" + #define COLOR_DROPPED 'cldp' #define AUTO_ADJUST_CHANGED 'madj' +using BPrivate::BColorItem; +using BPrivate::BColorListView; +using BPrivate::BColorPreview; + + APRView::APRView(const char* name) : BView(name, B_WILL_DRAW) @@ -55,16 +60,14 @@ APRView::APRView(const char* name) fAutoSelectCheckBox->SetValue(true); // Set up list of color attributes - fAttrList = new ColorWhichListView("AttributeList"); + fAttrList = new BColorListView("AttributeList"); fScrollView = new BScrollView("ScrollView", fAttrList, 0, false, true); fScrollView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); _CreateItems(); - fColorPreview = new ColorPreview(new BMessage(COLOR_DROPPED), 0); - fColorPreview->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, - B_ALIGN_VERTICAL_CENTER)); + fColorPreview = new BColorPreview("color preview", "", new BMessage(COLOR_DROPPED)); fPicker = new BColorControl(B_ORIGIN, B_CELLS_32x8, 8.0, "picker", new BMessage(UPDATE_COLOR)); @@ -79,8 +82,7 @@ APRView::APRView(const char* name) .End() .SetInsets(B_USE_WINDOW_SPACING); - fColorPreview->Parent()->SetExplicitMaxSize( - BSize(B_SIZE_UNSET, fPicker->Bounds().Height())); + fColorPreview->Parent()->SetExplicitMaxSize(BSize(B_SIZE_UNSET, fPicker->Bounds().Height())); fAttrList->SetSelectionMessage(new BMessage(ATTRIBUTE_CHOSEN)); } @@ -104,32 +106,54 @@ APRView::AttachedToWindow() void -APRView::MessageReceived(BMessage *msg) +APRView::MessageReceived(BMessage* message) { - switch (msg->what) { - case SET_COLOR: + if (message->WasDropped()) { + // Received from color preview when dropped on + char* name; + type_code type; + rgb_color* color; + ssize_t size; + if (message->GetInfo(B_RGB_COLOR_TYPE, 0, &name, &type) == B_OK + && message->FindData(name, type, (const void**)&color, &size) == B_OK) { + _SetCurrentColor(*color); + Window()->PostMessage(kMsgUpdate); + } + + return BView::MessageReceived(message); + } + + switch (message->what) { + // Received from color preview when dropped on + case COLOR_DROPPED: + // Received from the color list view when color changes + case BColorListView::B_MESSAGE_SET_CURRENT_COLOR: { + char* name; + type_code type; rgb_color* color; ssize_t size; - color_which which; - if (msg->FindData(kRGBColor, B_RGB_COLOR_TYPE, - (const void**)&color, &size) == B_OK - && msg->FindUInt32(kWhich, (uint32*)&which) == B_OK) { - _SetColor(which, *color); + if (message->GetInfo(B_RGB_COLOR_TYPE, 0, &name, &type) == B_OK + && message->FindData(name, type, (const void**)&color, &size) == B_OK) { + _SetCurrentColor(*color); Window()->PostMessage(kMsgUpdate); } break; } - case SET_CURRENT_COLOR: + case BColorListView::B_MESSAGE_SET_COLOR: { + char* name; + type_code type; rgb_color* color; ssize_t size; + color_which which; - if (msg->FindData(kRGBColor, B_RGB_COLOR_TYPE, - (const void**)&color, &size) == B_OK) { - _SetCurrentColor(*color); + if (message->GetInfo(B_RGB_COLOR_TYPE, 0, &name, &type) == B_OK + && message->FindData(name, type, (const void**)&color, &size) == B_OK + && message->FindUInt32("which", (uint32*)&which) == B_OK) { + _SetColor(which, *color); Window()->PostMessage(kMsgUpdate); } break; @@ -140,7 +164,6 @@ APRView::MessageReceived(BMessage *msg) // Received from the color fPicker when its color changes rgb_color color = fPicker->ValueAsColor(); _SetCurrentColor(color); - Window()->PostMessage(kMsgUpdate); break; } @@ -149,11 +172,8 @@ APRView::MessageReceived(BMessage *msg) { // Received when the user chooses a GUI fAttribute from the list - ColorWhichItem* item = (ColorWhichItem*) - fAttrList->ItemAt(fAttrList->CurrentSelection()); - if (item == NULL) - break; - + BColorItem* item + = static_cast(fAttrList->ItemAt(fAttrList->CurrentSelection())); fWhich = item->ColorWhich(); rgb_color color = ui_color(fWhich); _SetCurrentColor(color); @@ -167,7 +187,7 @@ APRView::MessageReceived(BMessage *msg) } default: - BView::MessageReceived(msg); + BView::MessageReceived(message); break; } } @@ -206,8 +226,7 @@ APRView::Revert() _SetUIColors(fPrevColors); _UpdatePreviews(fPrevColors); - rgb_color color = fPrevColors.GetColor(ui_color_name(fWhich), - make_color(255, 0, 255)); + rgb_color color = fPrevColors.GetColor(ui_color_name(fWhich), make_color(255, 0, 255)); fPicker->SetValue(color); fColorPreview->SetColor(color); fColorPreview->Invalidate(); @@ -250,7 +269,7 @@ APRView::_CreateItems() } const char* text = B_TRANSLATE_NOCOLLECT(description.text); - fAttrList->AddItem(new ColorWhichItem(text, which, ui_color(which))); + fAttrList->AddItem(new BColorItem(text, which, ui_color(which))); } if (Window() != NULL) @@ -263,7 +282,7 @@ APRView::_UpdatePreviews(const BMessage& colors) { rgb_color color; for (int32 i = color_description_count() - 1; i >= 0; i--) { - ColorWhichItem* item = static_cast(fAttrList->ItemAt(i)); + BColorItem* item = static_cast(fAttrList->ItemAt(i)); if (item == NULL) continue; @@ -290,7 +309,7 @@ APRView::_SetCurrentColor(rgb_color color) _SetColor(fWhich, color); int32 currentIndex = fAttrList->CurrentSelection(); - ColorWhichItem* item = (ColorWhichItem*)fAttrList->ItemAt(currentIndex); + BColorItem* item = static_cast(fAttrList->ItemAt(currentIndex)); if (item != NULL) { item->SetColor(color); fAttrList->InvalidateItem(currentIndex); @@ -298,7 +317,6 @@ APRView::_SetCurrentColor(rgb_color color) fPicker->SetValue(color); fColorPreview->SetColor(color); - fColorPreview->Invalidate(); } diff --git a/src/preferences/appearance/APRView.h b/src/preferences/appearance/APRView.h index df0044bf6c..a1a5c66c2e 100644 --- a/src/preferences/appearance/APRView.h +++ b/src/preferences/appearance/APRView.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +33,10 @@ class APRWindow; -class ColorPreview; + + +using BPrivate::BColorPreview; + class APRView : public BView { public: @@ -69,7 +73,7 @@ private: BScrollView* fScrollView; - ColorPreview* fColorPreview; + BColorPreview* fColorPreview; BMessage fPrevColors; BMessage fDefaultColors; diff --git a/src/preferences/appearance/ColorPreview.cpp b/src/preferences/appearance/ColorPreview.cpp deleted file mode 100644 index 2bc98f987b..0000000000 --- a/src/preferences/appearance/ColorPreview.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright 2002-2022 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * DarkWyrm, darkwyrm@earthlink.net - * John Scipione, jscipione@gmail.com - */ - - -#include "ColorPreview.h" - -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include "defs.h" - - - -static const int32 kMsgMessageRunner = 'MsgR'; - - -// #pragma mark - ColorPreview - - -ColorPreview::ColorPreview(BMessage* message, uint32 flags) - : - BControl("ColorPreview", "", message, flags | B_WILL_DRAW), - fColor(ui_color(B_PANEL_BACKGROUND_COLOR)), - fDisabledColor((rgb_color){ 128, 128, 128 }), - fMessageRunner(NULL), - fIsRectangle(true) -{ - SetViewColor(B_TRANSPARENT_COLOR); - SetLowColor(0, 0, 0); - SetExplicitSize(BSize(StringWidth("M") * 8, StringWidth("M") * 7)); -} - - -ColorPreview::~ColorPreview(void) -{ -} - - -void -ColorPreview::Draw(BRect updateRect) -{ - rgb_color color; - if (IsEnabled()) - color = fColor; - else - color = fDisabledColor; - - if (fIsRectangle) { - if (IsEnabled()) { - rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR); - rgb_color shadow = tint_color(background, B_DARKEN_1_TINT); - rgb_color darkShadow = tint_color(background, B_DARKEN_3_TINT); - rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT); - - BRect bounds(Bounds()); - - BeginLineArray(4); - AddLine(BPoint(bounds.left, bounds.bottom), - BPoint(bounds.left, bounds.top), shadow); - AddLine(BPoint(bounds.left + 1.0, bounds.top), - BPoint(bounds.right, bounds.top), shadow); - AddLine(BPoint(bounds.right, bounds.top + 1.0), - BPoint(bounds.right, bounds.bottom), light); - AddLine(BPoint(bounds.right - 1.0, bounds.bottom), - BPoint(bounds.left + 1.0, bounds.bottom), light); - EndLineArray(); - bounds.InsetBy(1.0, 1.0); - - BeginLineArray(4); - AddLine(BPoint(bounds.left, bounds.bottom), - BPoint(bounds.left, bounds.top), darkShadow); - AddLine(BPoint(bounds.left + 1.0, bounds.top), - BPoint(bounds.right, bounds.top), darkShadow); - AddLine(BPoint(bounds.right, bounds.top + 1.0), - BPoint(bounds.right, bounds.bottom), background); - AddLine(BPoint(bounds.right - 1.0, bounds.bottom), - BPoint(bounds.left + 1.0, bounds.bottom), background); - EndLineArray(); - bounds.InsetBy(1.0, 1.0); - - SetHighColor(color); - FillRect(bounds); - } else { - SetHighColor(color); - FillRect(Bounds()); - } - } else { - // fill background - SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - FillRect(updateRect); - - SetHighColor(color); - FillEllipse(Bounds()); - - if (IsEnabled()) - StrokeEllipse(Bounds(), B_SOLID_LOW); - } -} - - -void -ColorPreview::MessageReceived(BMessage* message) -{ - // If we received a dropped message, see if it contains color data - if (message->WasDropped()) { - rgb_color* color; - ssize_t size; - if (message->FindData(kRGBColor, B_RGB_COLOR_TYPE, - (const void**)&color, &size) == B_OK) { - BMessage setColorMessage(SET_CURRENT_COLOR); - setColorMessage.AddData(kRGBColor, B_RGB_COLOR_TYPE, color, - sizeof(rgb_color)); - Invoke(&setColorMessage); - } - } else if ((int32)message->what == kMsgMessageRunner) { - BPoint where; - uint32 buttons; - GetMouse(&where, &buttons); - - _DragColor(where); - } - - BControl::MessageReceived(message); -} - - -void -ColorPreview::MouseDown(BPoint where) -{ - BWindow* window = Window(); - if (window != NULL) - window->Activate(); - - fMessageRunner = new BMessageRunner(this, new BMessage(kMsgMessageRunner), - 300000, 1); - - SetMouseEventMask(B_POINTER_EVENTS, - B_SUSPEND_VIEW_FOCUS | B_LOCK_WINDOW_FOCUS); - - BRect rect = Bounds().InsetByCopy(2.0f, 2.0f); - rect.top = roundf(rect.bottom / 2.0f + 1); - - if (rect.Contains(where)) { - Invalidate(); - Invoke(); - } - - BControl::MouseDown(where); -} - - -void -ColorPreview::MouseMoved(BPoint where, uint32 transit, const BMessage* message) -{ - if (fMessageRunner != NULL) - _DragColor(where); - - BControl::MouseMoved(where, transit, message); -} - - -void -ColorPreview::MouseUp(BPoint where) -{ - delete fMessageRunner; - fMessageRunner = NULL; - - BControl::MouseUp(where); -} - - -rgb_color -ColorPreview::Color(void) const -{ - return fColor; -} - - -void -ColorPreview::SetColor(rgb_color color) -{ - color.alpha = 255; - - SetHighColor(color); - fColor = color; - - Invalidate(); - Invoke(); -} - - -void -ColorPreview::SetColor(uint8 red, uint8 green, uint8 blue) -{ - SetHighColor(red, green, blue); - fColor.red = red; - fColor.green = green; - fColor.blue = blue; - fColor.alpha = 255; - - Invalidate(); - Invoke(); -} - - -void -ColorPreview::SetMode(bool rectangle) -{ - fIsRectangle = rectangle; -} - - -// #pragma mark - ColorPreview private methods - - -void -ColorPreview::_DragColor(BPoint where) -{ - BString hexStr; - hexStr.SetToFormat("#%.2X%.2X%.2X", fColor.red, fColor.green, fColor.blue); - - BMessage message(B_PASTE); - message.AddData("text/plain", B_MIME_TYPE, hexStr.String(), - hexStr.Length()); - message.AddData(kRGBColor, B_RGB_COLOR_TYPE, &fColor, sizeof(fColor)); - - BRect rect(0.0f, 0.0f, 20.0f, 20.0f); - - BBitmap* bitmap = new BBitmap(rect, B_RGB32, true); - if (bitmap->Lock()) { - BView* view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW); - bitmap->AddChild(view); - - view->SetHighColor(B_TRANSPARENT_COLOR); - view->FillRect(view->Bounds()); - - ++rect.top; - ++rect.left; - - view->SetHighColor(0, 0, 0, 100); - view->FillRect(rect); - rect.OffsetBy(-1.0f, -1.0f); - - view->SetHighColor(std::min(255, (int)(1.2 * fColor.red + 40)), - std::min(255, (int)(1.2 * fColor.green + 40)), - std::min(255, (int)(1.2 * fColor.blue + 40))); - view->StrokeRect(rect); - - ++rect.left; - ++rect.top; - - view->SetHighColor((int32)(0.8 * fColor.red), - (int32)(0.8 * fColor.green), - (int32)(0.8 * fColor.blue)); - view->StrokeRect(rect); - - --rect.right; - --rect.bottom; - - view->SetHighColor(fColor.red, fColor.green, fColor.blue); - view->FillRect(rect); - view->Sync(); - - bitmap->Unlock(); - } - - DragMessage(&message, bitmap, B_OP_ALPHA, BPoint(14.0f, 14.0f)); - - MouseUp(where); -} diff --git a/src/preferences/appearance/ColorPreview.h b/src/preferences/appearance/ColorPreview.h deleted file mode 100644 index 3794b25c3a..0000000000 --- a/src/preferences/appearance/ColorPreview.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2002-2022 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * DarkWyrm, darkwyrm@earthlink.net - * John Scipione, jscipione@gmail.com - */ -#ifndef COLOR_PREVIEW_H_ -#define COLOR_PREVIEW_H_ - - -#include - - -class BMessage; -class BMessageRunner; - - -class ColorPreview : public BControl -{ -public: - ColorPreview(BMessage* message, - uint32 flags = B_WILL_DRAW); - ~ColorPreview(void); - - virtual void Draw(BRect updateRect); - virtual void MessageReceived(BMessage* message); - virtual void MouseDown(BPoint where); - virtual void MouseMoved(BPoint where, uint32 transit, - const BMessage* message); - virtual void MouseUp(BPoint where); - - rgb_color Color(void) const; - void SetColor(rgb_color color); - void SetColor(uint8 r, uint8 g, uint8 b); - - void SetMode(bool rectangle); - -private: - void _DragColor(BPoint where); - - rgb_color fColor; - rgb_color fDisabledColor; - - BMessageRunner* fMessageRunner; - - bool fIsRectangle; -}; - -#endif // COLOR_PREVIEW_H_ diff --git a/src/preferences/appearance/ColorWhichItem.cpp b/src/preferences/appearance/ColorWhichItem.cpp deleted file mode 100644 index c0c18e6061..0000000000 --- a/src/preferences/appearance/ColorWhichItem.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2001-2016 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * DarkWyrm, darkwyrm@earthlink.net - * Rene Gollent, rene@gollent.com - * Ryan Leavengood, leavengood@gmail.com - * John Scipione, jscipione@gmail.com - */ - - -#include "ColorWhichItem.h" - -#include - -#include - - -// golden ratio -#ifdef M_PHI -# undef M_PHI -#endif -#define M_PHI 1.61803398874989484820 - - -ColorWhichItem::ColorWhichItem(const char* text, color_which which, - rgb_color color) - : - BStringItem(text, 0, false), - fColorWhich(which), - fColor(color) -{ -} - - -void -ColorWhichItem::DrawItem(BView* owner, BRect frame, bool complete) -{ - rgb_color highColor = owner->HighColor(); - rgb_color lowColor = owner->LowColor(); - - if (IsSelected() || complete) { - if (IsSelected()) { - owner->SetHighUIColor(B_LIST_SELECTED_BACKGROUND_COLOR); - owner->SetLowColor(owner->HighColor()); - } else - owner->SetHighColor(lowColor); - - owner->FillRect(frame); - } - - float spacer = ceilf(be_control_look->DefaultItemSpacing() / 2); - - BRect colorRect(frame); - colorRect.InsetBy(2.0f, 2.0f); - colorRect.left += spacer; - colorRect.right = colorRect.left + floorf(colorRect.Height() * M_PHI); - owner->SetHighColor(fColor); - owner->FillRect(colorRect); - owner->SetHighUIColor(B_CONTROL_BORDER_COLOR); - owner->StrokeRect(colorRect); - - owner->MovePenTo(colorRect.right + spacer, frame.top + BaselineOffset()); - - if (!IsEnabled()) { - rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR); - if (textColor.red + textColor.green + textColor.blue > 128 * 3) - owner->SetHighColor(tint_color(textColor, B_DARKEN_2_TINT)); - else - owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT)); - } else { - if (IsSelected()) - owner->SetHighUIColor(B_LIST_SELECTED_ITEM_TEXT_COLOR); - else - owner->SetHighUIColor(B_LIST_ITEM_TEXT_COLOR); - } - - owner->DrawString(Text()); - - owner->SetHighColor(highColor); - owner->SetLowColor(lowColor); -} diff --git a/src/preferences/appearance/ColorWhichItem.h b/src/preferences/appearance/ColorWhichItem.h deleted file mode 100644 index 98a90e08b8..0000000000 --- a/src/preferences/appearance/ColorWhichItem.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2001-2016 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * DarkWyrm, bpmagic@columbus.rr.com - * Rene Gollent, rene@gollent.com - * Ryan Leavengood, leavengood@gmail.com - * John Scipione, jscipione@gmail.com - */ -#ifndef COLORWHICH_ITEM_H -#define COLORWHICH_ITEM_H - - -#include -#include - - -class ColorWhichItem : public BStringItem -{ -public: - ColorWhichItem(const char* text, color_which which, - rgb_color color); - - virtual void DrawItem(BView* owner, BRect frame, bool complete); - - color_which ColorWhich() { return fColorWhich; }; - - rgb_color Color() { return fColor; }; - void SetColor(rgb_color color) { fColor = color; }; - -private: - color_which fColorWhich; - rgb_color fColor; -}; - - -#endif diff --git a/src/preferences/appearance/ColorWhichListView.cpp b/src/preferences/appearance/ColorWhichListView.cpp deleted file mode 100644 index 9545c62f88..0000000000 --- a/src/preferences/appearance/ColorWhichListView.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2016 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * John Scipione, jscipione@gmail.com - */ - - -#include "ColorWhichListView.h" - -#include - -#include -#include - -#include -#include - -#include "ColorWhichItem.h" -#include "defs.h" - - -// golden ratio -#ifdef M_PHI -# undef M_PHI -#endif -#define M_PHI 1.61803398874989484820 - - -// #pragma mark - ColorWhichListView - - -ColorWhichListView::ColorWhichListView(const char* name, - list_view_type type, uint32 flags) - : - BListView(name, type, flags) -{ -} - - -ColorWhichListView::~ColorWhichListView() -{ -} - - -bool -ColorWhichListView::InitiateDrag(BPoint where, int32 index, bool wasSelected) -{ - ColorWhichItem* colorWhichItem - = dynamic_cast(ItemAt(index)); - if (colorWhichItem == NULL) - return false; - - rgb_color color = colorWhichItem->Color(); - - BString hexStr; - hexStr.SetToFormat("#%.2X%.2X%.2X", color.red, color.green, color.blue); - - BMessage message(B_PASTE); - message.AddData("text/plain", B_MIME_TYPE, hexStr.String(), - hexStr.Length()); - message.AddData(kRGBColor, B_RGB_COLOR_TYPE, &color, sizeof(color)); - - float itemHeight = colorWhichItem->Height() - 5; - BRect rect(0.0f, 0.0f, roundf(itemHeight * M_PHI) - 1, itemHeight - 1); - - BBitmap* bitmap = new BBitmap(rect, B_RGB32, true); - if (bitmap->Lock()) { - BView* view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW); - bitmap->AddChild(view); - - view->SetHighColor(B_TRANSPARENT_COLOR); - view->FillRect(view->Bounds()); - - ++rect.top; - ++rect.left; - - view->SetHighColor(0, 0, 0, 100); - view->FillRect(rect); - rect.OffsetBy(-1.0f, -1.0f); - - view->SetHighColor(std::min(255, (int)(1.2 * color.red + 40)), - std::min(255, (int)(1.2 * color.green + 40)), - std::min(255, (int)(1.2 * color.blue + 40))); - view->StrokeRect(rect); - - ++rect.left; - ++rect.top; - - view->SetHighColor((int32)(0.8 * color.red), - (int32)(0.8 * color.green), - (int32)(0.8 * color.blue)); - view->StrokeRect(rect); - - --rect.right; - --rect.bottom; - - view->SetHighColor(color.red, color.green, color.blue); - view->FillRect(rect); - view->Sync(); - - bitmap->Unlock(); - } - - DragMessage(&message, bitmap, B_OP_ALPHA, BPoint(14.0f, 14.0f)); - - return true; -} - - -void -ColorWhichListView::MessageReceived(BMessage* message) -{ - // if we received a dropped message, see if it contains color data - if (message->WasDropped()) { - BPoint dropPoint = message->DropPoint(); - ConvertFromScreen(&dropPoint); - int32 index = IndexOf(dropPoint); - ColorWhichItem* item = dynamic_cast(ItemAt(index)); - rgb_color* color; - ssize_t size; - if (item != NULL && message->FindData(kRGBColor, B_RGB_COLOR_TYPE, - (const void**)&color, &size) == B_OK) { - // build message to send to APRView - int32 command = index == CurrentSelection() - ? SET_CURRENT_COLOR : SET_COLOR; - BMessage setColorMessage = BMessage(command); - setColorMessage.AddData(kRGBColor, B_RGB_COLOR_TYPE, color, size); - // if setting different color, add which color to set - if (command == SET_COLOR) - setColorMessage.AddUInt32(kWhich, (uint32)item->ColorWhich()); - - // build messenger and send message - BMessenger messenger = BMessenger(Parent()); - if (messenger.IsValid()) { - messenger.SendMessage(&setColorMessage); - if (command == SET_COLOR) { - // redraw item, SET_CURRENT_COLOR does this for us - item->SetColor(*color); - InvalidateItem(index); - } - } - } - } - - BListView::MessageReceived(message); -} diff --git a/src/preferences/appearance/ColorWhichListView.h b/src/preferences/appearance/ColorWhichListView.h deleted file mode 100644 index f069406bf4..0000000000 --- a/src/preferences/appearance/ColorWhichListView.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2016 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * John Scipione, jscipione@gmail.com - */ -#ifndef COLORWHICH_LIST_VIEW_H -#define COLORWHICH_LIST_VIEW_H - - -#include - - -class ColorWhichListView : public BListView -{ -public: - ColorWhichListView(const char* name, - list_view_type type - = B_SINGLE_SELECTION_LIST, - uint32 flags = B_WILL_DRAW - | B_FRAME_EVENTS | B_NAVIGABLE); - virtual ~ColorWhichListView(); - - virtual bool InitiateDrag(BPoint where, int32 index, - bool wasSelected); - virtual void MessageReceived(BMessage* message); -}; - - -#endif // COLORWHICH_LIST_VIEW_H diff --git a/src/preferences/appearance/Jamfile b/src/preferences/appearance/Jamfile index b097ec83e5..e69d2e57c5 100644 --- a/src/preferences/appearance/Jamfile +++ b/src/preferences/appearance/Jamfile @@ -13,10 +13,7 @@ Preference Appearance : FontView.cpp APRView.cpp APRWindow.cpp - ColorPreview.cpp Colors.cpp - ColorWhichItem.cpp - ColorWhichListView.cpp # These are currently disabled while everything else is being worked on #CurView.cpp @@ -33,9 +30,7 @@ DoCatalogs Appearance : AntialiasingSettingsView.cpp APRView.cpp APRWindow.cpp - ColorPreview.cpp Colors.cpp - ColorWhichItem.cpp LookAndFeelSettingsView.cpp FontView.cpp FontSelectionView.cpp diff --git a/src/preferences/appearance/defs.h b/src/preferences/appearance/defs.h index 2249439dda..48b5843943 100644 --- a/src/preferences/appearance/defs.h +++ b/src/preferences/appearance/defs.h @@ -37,10 +37,6 @@ #define SET_UI_COLORS 'suic' #define PREFS_CHOSEN 'prch' -// constants -static const char* const kRGBColor = "RGBColor"; -static const char* const kWhich = "which"; - // user interface const uint32 kBorderSpace = 10; const uint32 kItemSpace = 7;