diff --git a/src/preferences/appearance/APRView.cpp b/src/preferences/appearance/APRView.cpp index 59a6a9d55a..4a4a526e85 100644 --- a/src/preferences/appearance/APRView.cpp +++ b/src/preferences/appearance/APRView.cpp @@ -29,6 +29,7 @@ #include "defs.h" #include "ColorPreview.h" #include "Colors.h" +#include "ColorWhichListView.h" #include "ColorWhichItem.h" @@ -74,7 +75,7 @@ APRView::APRView(const char* name) LoadSettings(); // Set up list of color attributes - fAttrList = new BListView("AttributeList", B_SINGLE_SELECTION_LIST); + fAttrList = new ColorWhichListView("AttributeList"); fScrollView = new BScrollView("ScrollView", fAttrList, 0, false, true); fScrollView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); diff --git a/src/preferences/appearance/ColorWhichItem.cpp b/src/preferences/appearance/ColorWhichItem.cpp index 2cd96c750b..55926a195f 100644 --- a/src/preferences/appearance/ColorWhichItem.cpp +++ b/src/preferences/appearance/ColorWhichItem.cpp @@ -82,17 +82,3 @@ ColorWhichItem::DrawItem(BView* owner, BRect frame, bool complete) owner->SetHighColor(highColor); owner->SetLowColor(lowColor); } - - -color_which -ColorWhichItem::ColorWhich(void) -{ - return fColorWhich; -} - - -void -ColorWhichItem::SetColor(rgb_color color) -{ - fColor = color; -} diff --git a/src/preferences/appearance/ColorWhichItem.h b/src/preferences/appearance/ColorWhichItem.h index 24850a7812..7e21eceee6 100644 --- a/src/preferences/appearance/ColorWhichItem.h +++ b/src/preferences/appearance/ColorWhichItem.h @@ -24,8 +24,11 @@ public: rgb_color color); virtual void DrawItem(BView* owner, BRect frame, bool complete); - color_which ColorWhich(void); - void SetColor(rgb_color color); + + color_which ColorWhich() { return fColorWhich; }; + + rgb_color Color() { return fColor; }; + void SetColor(rgb_color color) { fColor = color; }; private: color_which fColorWhich; diff --git a/src/preferences/appearance/ColorWhichListView.cpp b/src/preferences/appearance/ColorWhichListView.cpp new file mode 100644 index 0000000000..6bd4e9654d --- /dev/null +++ b/src/preferences/appearance/ColorWhichListView.cpp @@ -0,0 +1,106 @@ +/* + * 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 "ColorWhichItem.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(); + + char hexString[7]; + sprintf(hexString, "#%.2X%.2X%.2X", color.red, color.green, color.blue); + + BMessage message(B_PASTE); + message.AddData("text/plain", B_MIME_TYPE, &hexString, sizeof(hexString)); + message.AddData("RGBColor", 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; +} diff --git a/src/preferences/appearance/ColorWhichListView.h b/src/preferences/appearance/ColorWhichListView.h new file mode 100644 index 0000000000..0bbcd546a7 --- /dev/null +++ b/src/preferences/appearance/ColorWhichListView.h @@ -0,0 +1,29 @@ +/* + * 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); +}; + +#endif // COLORWHICH_LIST_VIEW_H diff --git a/src/preferences/appearance/Jamfile b/src/preferences/appearance/Jamfile index e6fcb43b4d..5bbe71f1b4 100644 --- a/src/preferences/appearance/Jamfile +++ b/src/preferences/appearance/Jamfile @@ -20,6 +20,7 @@ Preference Appearance : ColorPreview.cpp Colors.cpp ColorWhichItem.cpp + ColorWhichListView.cpp # These are currently disabled while everything else is being worked on #CurView.cpp