Appearance: Make color which items draggable
Create a ColorWhichListView class which impliments InitiateDrag() to drag a color square out of the list view. You can then drop the color anywhere that accepts a color drop. This allows you to drag and drop colors between list items for example.
This commit is contained in:
parent
2446f53bc8
commit
46b84951f7
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
106
src/preferences/appearance/ColorWhichListView.cpp
Normal file
106
src/preferences/appearance/ColorWhichListView.cpp
Normal file
@ -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 <algorithm>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Bitmap.h>
|
||||
|
||||
#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<ColorWhichItem*>(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;
|
||||
}
|
29
src/preferences/appearance/ColorWhichListView.h
Normal file
29
src/preferences/appearance/ColorWhichListView.h
Normal file
@ -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 <ListView.h>
|
||||
|
||||
|
||||
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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user