From 3b4c5d90b5c77f605d0820e27e958dc0434063d2 Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Tue, 20 Aug 2002 00:16:10 +0000 Subject: [PATCH] Initial checkin of ColorWell control git-svn-id: file:///srv/svn/repos/haiku/trunk/current@830 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/appearance/ColorWell.cpp | 105 +++++++++++++++++++++++++++++ src/prefs/appearance/ColorWell.h | 27 ++++++++ src/prefs/appearance/Jamfile | 2 +- 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 src/prefs/appearance/ColorWell.cpp create mode 100644 src/prefs/appearance/ColorWell.h diff --git a/src/prefs/appearance/ColorWell.cpp b/src/prefs/appearance/ColorWell.cpp new file mode 100644 index 0000000000..6cb94a5e2a --- /dev/null +++ b/src/prefs/appearance/ColorWell.cpp @@ -0,0 +1,105 @@ +#include "ColorWell.h" + +ColorWell::ColorWell(BRect frame, BMessage *msg, bool is_rectangle=false) + : BView(frame,"ColorWell", B_FOLLOW_ALL_SIDES, B_WILL_DRAW) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + SetLowColor(0,0,0); + invoker=new BInvoker(msg,this); + disabledcol.red=128; + disabledcol.green=128; + disabledcol.blue=128; + disabledcol.alpha=255; + is_enabled=true; + is_rect=is_rectangle; +} + +ColorWell::~ColorWell(void) +{ + delete invoker; +} + +void ColorWell::SetTarget(BHandler *tgt) +{ + invoker->SetTarget(tgt); +} + +void ColorWell::SetColor(rgb_color col) +{ + SetHighColor(col); + currentcol=col; + Draw(Bounds()); +// Invalidate(); + invoker->Invoke(); +} + +void ColorWell::SetColor(uint8 r,uint8 g, uint8 b) +{ + SetHighColor(r,g,b); + currentcol.red=r; + currentcol.green=g; + currentcol.blue=b; + Draw(Bounds()); + //Invalidate(); + invoker->Invoke(); +} + +void ColorWell::MessageReceived(BMessage *msg) +{ + // If we received a dropped message, try to see if it has color data + // in it + if(msg->WasDropped()) + { + rgb_color *col; + uint8 *ptr; + ssize_t size; + if(msg->FindData("RGBColor",(type_code)'RGBC',(const void**)&ptr,&size)==B_OK) + { + col=(rgb_color*)ptr; + SetHighColor(*col); + } + } + + // The default + BView::MessageReceived(msg); +} + +void ColorWell::SetEnabled(bool value) +{ + if(is_enabled!=value) + { + is_enabled=value; + Invalidate(); + } +} + +void ColorWell::Draw(BRect update) +{ + if(is_enabled) + SetHighColor(currentcol); + else + SetHighColor(disabledcol); + + if(is_rect) + { + FillRect(Bounds()); + if(is_enabled) + StrokeRect(Bounds(),B_SOLID_LOW); + } + else + { + FillEllipse(Bounds()); + if(is_enabled) + StrokeEllipse(Bounds(),B_SOLID_LOW); + } +} + +rgb_color ColorWell::Color(void) const +{ + return currentcol; +} + +void ColorWell::SetMode(bool is_rectangle) +{ + is_rect=is_rectangle; +} \ No newline at end of file diff --git a/src/prefs/appearance/ColorWell.h b/src/prefs/appearance/ColorWell.h new file mode 100644 index 0000000000..ffbb8c1103 --- /dev/null +++ b/src/prefs/appearance/ColorWell.h @@ -0,0 +1,27 @@ +#ifndef COLORWELL_H_ +#define COLORWELL_H_ + +#include +#include +#include + +class ColorWell : public BView +{ +public: + ColorWell(BRect frame, BMessage *msg, bool is_rectangle=false); + ~ColorWell(void); + void SetColor(rgb_color col); + rgb_color Color(void) const; + void SetColor(uint8 r,uint8 g, uint8 b); + virtual void MessageReceived(BMessage *msg); + virtual void Draw(BRect update); + virtual void SetTarget(BHandler *tgt); + virtual void SetEnabled(bool value); + void SetMode(bool is_rectangle); +protected: + BInvoker *invoker; + bool is_enabled, is_rect; + rgb_color disabledcol, currentcol; +}; + +#endif \ No newline at end of file diff --git a/src/prefs/appearance/Jamfile b/src/prefs/appearance/Jamfile index 4383d18646..c71075e8e1 100644 --- a/src/prefs/appearance/Jamfile +++ b/src/prefs/appearance/Jamfile @@ -2,6 +2,6 @@ SubDir OBOS_TOP src prefs appearance ; AddResources Appearance : Appearance.rsrc ; -Preference Appearance : APRMain.cpp APRView.cpp APRWindow.cpp Decorator.cpp DecView.cpp DisplayDriver.cpp PortLink.cpp PreviewDriver.cpp RGBColor.cpp SPoint.cpp SRect.cpp ; +Preference Appearance : APRMain.cpp APRView.cpp APRWindow.cpp Decorator.cpp DecView.cpp DisplayDriver.cpp PortLink.cpp PreviewDriver.cpp RGBColor.cpp SPoint.cpp SRect.cpp ColorWell.cpp ; LinkSharedOSLibs Appearance : be ;