Initial checkin of ColorWell control
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@830 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
6012f6c679
commit
3b4c5d90b5
105
src/prefs/appearance/ColorWell.cpp
Normal file
105
src/prefs/appearance/ColorWell.cpp
Normal file
@ -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;
|
||||
}
|
27
src/prefs/appearance/ColorWell.h
Normal file
27
src/prefs/appearance/ColorWell.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef COLORWELL_H_
|
||||
#define COLORWELL_H_
|
||||
|
||||
#include <View.h>
|
||||
#include <Message.h>
|
||||
#include <Invoker.h>
|
||||
|
||||
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
|
@ -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 ;
|
||||
|
Loading…
Reference in New Issue
Block a user