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 <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
012d90c553
commit
622853ff8e
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "ConfigView.h"
|
||||
|
||||
#include <ColorItem.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <ListView.h>
|
||||
#include <ScrollView.h>
|
||||
@@ -19,11 +20,13 @@
|
||||
#include <StringView.h>
|
||||
#include <View.h>
|
||||
|
||||
#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,
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2022 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
#include "ColorListView.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <String.h>
|
||||
|
||||
#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<ColorItem*>(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<ColorItem*>(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);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2022 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
#ifndef COLORWHICH_LIST_VIEW_H
|
||||
#define COLORWHICH_LIST_VIEW_H
|
||||
|
||||
|
||||
#include <ListView.h>
|
||||
|
||||
|
||||
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
|
||||
@@ -1,284 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2022 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* DarkWyrm, [email protected]
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
#include "ColorPreview.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <Message.h>
|
||||
#include <MessageRunner.h>
|
||||
#include <String.h>
|
||||
#include <View.h>
|
||||
#include <Window.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2022 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* DarkWyrm, [email protected]
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
#ifndef COLOR_PREVIEW_H_
|
||||
#define COLOR_PREVIEW_H_
|
||||
|
||||
|
||||
#include <Control.h>
|
||||
|
||||
|
||||
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_
|
||||
@@ -11,8 +11,6 @@ Application Terminal :
|
||||
Arguments.cpp
|
||||
BasicTerminalBuffer.cpp
|
||||
Colors.cpp
|
||||
ColorListView.cpp
|
||||
ColorPreview.cpp
|
||||
FindWindow.cpp
|
||||
Globals.cpp
|
||||
HistoryBuffer.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);
|
||||
|
||||
@@ -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 <[email protected]>
|
||||
* Copyright (c) 2003-2004 Kian Duffy <[email protected]>
|
||||
* Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||
@@ -26,10 +26,11 @@
|
||||
#include <Alert.h>
|
||||
#include <Application.h>
|
||||
#include <Catalog.h>
|
||||
#include <ControlLook.h>
|
||||
#include <CharacterSet.h>
|
||||
#include <CharacterSetRoster.h>
|
||||
#include <Clipboard.h>
|
||||
#include <ColorListView.h>
|
||||
#include <ControlLook.h>
|
||||
#include <Dragger.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
@@ -50,8 +51,8 @@
|
||||
#include <ScrollBar.h>
|
||||
#include <ScrollView.h>
|
||||
#include <String.h>
|
||||
#include <UnicodeChar.h>
|
||||
#include <UTF8.h>
|
||||
#include <UnicodeChar.h>
|
||||
|
||||
#include <AutoLocker.h>
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2010, Haiku.
|
||||
* Copyright 2001-2025 Haiku, Inc. All rights reserved
|
||||
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
|
||||
* 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,
|
||||
|
||||
@@ -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 <Alert.h>
|
||||
#include <Catalog.h>
|
||||
#include <ColorItem.h>
|
||||
#include <ColorListView.h>
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
@@ -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<BColorItem*>(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<BColorItem*>(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<ColorItem*>(fAttrList->ItemAt(index));
|
||||
BColorItem* item = static_cast<BColorItem*>(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<BColorItem*>(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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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 <Button.h>
|
||||
#include <ColorControl.h>
|
||||
#include <ColorPreview.h>
|
||||
#include <GroupView.h>
|
||||
#include <ListItem.h>
|
||||
#include <ListView.h>
|
||||
@@ -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;
|
||||
|
||||
@@ -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 <ColorItem.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <ColorListView.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <ColorItem.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
// 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<BColorItem*>(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<BColorItem*>(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
|
||||
Executable
+241
@@ -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 <ColorPreview.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include <Application.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Message.h>
|
||||
#include <MessageRunner.h>
|
||||
#include <String.h>
|
||||
#include <Window.h>
|
||||
|
||||
|
||||
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
|
||||
@@ -32,6 +32,8 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
BitmapButton.cpp
|
||||
CalendarView.cpp
|
||||
ColorItem.cpp
|
||||
ColorListView.cpp
|
||||
ColorPreview.cpp
|
||||
ColorQuantizer.cpp
|
||||
CommandPipe.cpp
|
||||
DateTimeEdit.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 <Alert.h>
|
||||
#include <Catalog.h>
|
||||
#include <ColorItem.h>
|
||||
#include <ColorListView.h>
|
||||
#include <DefaultColors.h>
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
@@ -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<BColorItem*>(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<ColorWhichItem*>(fAttrList->ItemAt(i));
|
||||
BColorItem* item = static_cast<BColorItem*>(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<BColorItem*>(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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <Button.h>
|
||||
#include <CheckBox.h>
|
||||
#include <ColorControl.h>
|
||||
#include <ColorPreview.h>
|
||||
#include <ListItem.h>
|
||||
#include <ListView.h>
|
||||
#include <Menu.h>
|
||||
@@ -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;
|
||||
|
||||
@@ -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 <algorithm>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <Message.h>
|
||||
#include <MessageRunner.h>
|
||||
#include <String.h>
|
||||
#include <View.h>
|
||||
#include <Window.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
@@ -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 <Control.h>
|
||||
|
||||
|
||||
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_
|
||||
@@ -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 <math.h>
|
||||
|
||||
#include <ControlLook.h>
|
||||
|
||||
|
||||
// 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);
|
||||
}
|
||||
@@ -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 <InterfaceDefs.h>
|
||||
#include <StringItem.h>
|
||||
|
||||
|
||||
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
|
||||
@@ -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 <algorithm>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <String.h>
|
||||
|
||||
#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<ColorWhichItem*>(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<ColorWhichItem*>(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);
|
||||
}
|
||||
@@ -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 <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);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
};
|
||||
|
||||
|
||||
#endif // COLORWHICH_LIST_VIEW_H
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user