2 * Copyright 2016 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * John Scipione, jscipione@gmail.com
10 #include "ColorWhichListView.h"
19 #include "ColorWhichItem.h"
26 #define M_PHI 1.61803398874989484820
29 // #pragma mark - ColorWhichListView
32 ColorWhichListView::ColorWhichListView(const char* name
,
33 list_view_type type
, uint32 flags
)
35 BListView(name
, type
, flags
)
40 ColorWhichListView::~ColorWhichListView()
46 ColorWhichListView::InitiateDrag(BPoint where
, int32 index
, bool wasSelected
)
48 ColorWhichItem
* colorWhichItem
49 = dynamic_cast<ColorWhichItem
*>(ItemAt(index
));
50 if (colorWhichItem
== NULL
)
53 rgb_color color
= colorWhichItem
->Color();
56 sprintf(hexString
, "#%.2X%.2X%.2X", color
.red
, color
.green
, color
.blue
);
58 BMessage
message(B_PASTE
);
59 message
.AddData("text/plain", B_MIME_TYPE
, &hexString
, sizeof(hexString
));
60 message
.AddData("RGBColor", B_RGB_COLOR_TYPE
, &color
, sizeof(color
));
62 float itemHeight
= colorWhichItem
->Height() - 5;
63 BRect
rect(0.0f
, 0.0f
, roundf(itemHeight
* M_PHI
) - 1, itemHeight
- 1);
65 BBitmap
* bitmap
= new BBitmap(rect
, B_RGB32
, true);
67 BView
* view
= new BView(rect
, "", B_FOLLOW_NONE
, B_WILL_DRAW
);
68 bitmap
->AddChild(view
);
70 view
->SetHighColor(B_TRANSPARENT_COLOR
);
71 view
->FillRect(view
->Bounds());
76 view
->SetHighColor(0, 0, 0, 100);
78 rect
.OffsetBy(-1.0f
, -1.0f
);
80 view
->SetHighColor(std::min(255, (int)(1.2 * color
.red
+ 40)),
81 std::min(255, (int)(1.2 * color
.green
+ 40)),
82 std::min(255, (int)(1.2 * color
.blue
+ 40)));
83 view
->StrokeRect(rect
);
88 view
->SetHighColor((int32
)(0.8 * color
.red
),
89 (int32
)(0.8 * color
.green
),
90 (int32
)(0.8 * color
.blue
));
91 view
->StrokeRect(rect
);
96 view
->SetHighColor(color
.red
, color
.green
, color
.blue
);
103 DragMessage(&message
, bitmap
, B_OP_ALPHA
, BPoint(14.0f
, 14.0f
));