From 614fabb05bad16b8bc5850c7573a594cefe84493 Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Thu, 8 Aug 2002 21:37:02 +0000 Subject: [PATCH] Added Decorator tab git-svn-id: file:///srv/svn/repos/haiku/trunk/current@657 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/appearance/ColorSet.h | 27 ++ src/prefs/appearance/DecView.cpp | 280 ++++++++++++++++++++ src/prefs/appearance/DecView.h | 42 +++ src/prefs/appearance/Decorator.cpp | 238 +++++++++++++++++ src/prefs/appearance/Decorator.h | 119 +++++++++ src/prefs/appearance/DisplayDriver.cpp | 85 +++++++ src/prefs/appearance/DisplayDriver.h | 115 +++++++++ src/prefs/appearance/LayerData.h | 35 +++ src/prefs/appearance/PreviewDriver.cpp | 338 +++++++++++++++++++++++++ src/prefs/appearance/PreviewDriver.h | 79 ++++++ src/prefs/appearance/RGBColor.cpp | 157 ++++++++++++ src/prefs/appearance/RGBColor.h | 32 +++ src/prefs/appearance/SPoint.cpp | 92 +++++++ src/prefs/appearance/SPoint.h | 80 ++++++ src/prefs/appearance/SRect.cpp | 205 +++++++++++++++ src/prefs/appearance/SRect.h | 187 ++++++++++++++ src/prefs/appearance/defs.h | 21 ++ 17 files changed, 2132 insertions(+) create mode 100644 src/prefs/appearance/ColorSet.h create mode 100644 src/prefs/appearance/DecView.cpp create mode 100644 src/prefs/appearance/DecView.h create mode 100644 src/prefs/appearance/Decorator.cpp create mode 100644 src/prefs/appearance/Decorator.h create mode 100644 src/prefs/appearance/DisplayDriver.cpp create mode 100644 src/prefs/appearance/DisplayDriver.h create mode 100644 src/prefs/appearance/LayerData.h create mode 100644 src/prefs/appearance/PreviewDriver.cpp create mode 100644 src/prefs/appearance/PreviewDriver.h create mode 100644 src/prefs/appearance/RGBColor.cpp create mode 100644 src/prefs/appearance/RGBColor.h create mode 100644 src/prefs/appearance/SPoint.cpp create mode 100644 src/prefs/appearance/SPoint.h create mode 100644 src/prefs/appearance/SRect.cpp create mode 100644 src/prefs/appearance/SRect.h create mode 100644 src/prefs/appearance/defs.h diff --git a/src/prefs/appearance/ColorSet.h b/src/prefs/appearance/ColorSet.h new file mode 100644 index 0000000000..5e24821b1a --- /dev/null +++ b/src/prefs/appearance/ColorSet.h @@ -0,0 +1,27 @@ +#ifndef COLORSET_H_ +#define COLORSET_H_ + +#include "RGBColor.h" + +typedef struct +{ + RGBColor panel_background, + panel_text, + document_background, + document_text, + control_background, + control_text, + control_border, + control_highlight, + tooltip_background, + tooltip_text, + menu_background, + menu_selected_background, + menu_text, + menu_selected_text, + menu_separator_high, + menu_separator_low, + menu_triggers; +} ColorSet; + +#endif \ No newline at end of file diff --git a/src/prefs/appearance/DecView.cpp b/src/prefs/appearance/DecView.cpp new file mode 100644 index 0000000000..53f8bccc13 --- /dev/null +++ b/src/prefs/appearance/DecView.cpp @@ -0,0 +1,280 @@ +/* + DecView.cpp: The Appearance app's decorator handler + + Utilizes app_server graphics module emulation to allows decorators to display + a preview. Saves the chosen decorator's path in a settings file in the app_server + settings directory. +*/ + +#include +#include +#include +#include +#include +#include "DecView.h" +#include "PortLink.h" +#include +#include +#include +#include "defs.h" +#include "PreviewDriver.h" +#include "Decorator.h" + +#define DEBUG_DECORATOR + +DecView::DecView(BRect frame, const char *name, int32 resize, int32 flags) + :BView(frame,name,resize,flags) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + // Set up list of color attributes + declist=new BListView(BRect(10,10,110,110),"DecoratorList"); + + scrollview=new BScrollView("ScrollView",declist, B_FOLLOW_LEFT | + B_FOLLOW_TOP, 0, false, true); + AddChild(scrollview); + scrollview->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + declist->SetSelectionMessage(new BMessage(DECORATOR_CHOSEN)); + + BRect cvrect(0,0,50,25); + + cvrect.OffsetTo(Bounds().right-60, + scrollview->Frame().top); + + apply=new BButton(cvrect,"ApplyButton","Apply", + new BMessage(APPLY_SETTINGS),B_FOLLOW_LEFT |B_FOLLOW_TOP, + B_WILL_DRAW | B_NAVIGABLE); + AddChild(apply); + + // set up app_server emulation + + driver=new PreviewDriver(); + if(!driver->Initialize()) + printf("Uh-oh... Couldn't initialize graphics module for server emu!\n"); + else + { + preview=driver->View(); + AddChild(preview); + preview->MoveTo(scrollview->Frame().right+20,scrollview->Frame().top); + } + + LayerData ldata; + ldata.highcolor.SetColor(51,102,160); + uint64 pat=0xFFFFFFFFFFFFFFFFLL; + driver->FillRect(preview_bounds,&ldata,(int8*)&pat); + + decorator=NULL; + decorator_id=-1; + GetDecorators(); + LoadSettings(); +} + +DecView::~DecView(void) +{ + driver->Shutdown(); + delete driver; + if(decorator!=NULL) + delete decorator; +} + +void DecView::AttachedToWindow(void) +{ + declist->SetTarget(this); + apply->SetTarget(this); + declist->Select(0); +} + +void DecView::MessageReceived(BMessage *msg) +{ + switch(msg->what) + { + case APPLY_SETTINGS: + { + SaveSettings(); + NotifyServer(); + break; + } + case DECORATOR_CHOSEN: + { +#ifdef DEBUG_DECORATOR +printf("MSG: Decorator Chosen - #%ld\n",declist->CurrentSelection()); +#endif + bool success=false; + + success=LoadDecorator( ConvertIndexToPath( declist->CurrentSelection() ) ); + + if(!success) + break; + + LayerData ldata; + ldata.highcolor.SetColor(ui_color(B_DESKTOP_COLOR)); + uint64 pat=0xFFFFFFFFFFFFFFFFLL; + driver->FillRect(preview_bounds,&ldata,(int8*)&pat); + if(decorator) + decorator->Draw(); + break; + } + default: + BView::MessageReceived(msg); + break; + } +} + +void DecView::SaveSettings(void) +{ + BString path(SETTINGS_DIR); + path+="DecoratorSettings"; + printf("%s\n",path.String()); + BFile file(path.String(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE); + + settings.Flatten(&file); +} + +void DecView::LoadSettings(void) +{ + settings.MakeEmpty(); + + BDirectory dir,newdir; + if(dir.SetTo(SETTINGS_DIR)==B_ENTRY_NOT_FOUND) + create_directory(SETTINGS_DIR,0777); + + BString path(SETTINGS_DIR); + path+="DecoratorSettings"; + BFile file(path.String(),B_READ_ONLY); + + if(file.InitCheck()==B_OK) + { + if(settings.Unflatten(&file)==B_OK) + { + // Get the color for the current attribute here + return; + } + printf("Error unflattening settings file %s\n",path.String()); + } + + // If we get this far, we have encountered an error, so reset the settings + // to the defaults + SetDefaults(); +} + +void DecView::SetDefaults(void) +{ + settings.MakeEmpty(); + + // Add default settings here +} + +void DecView::NotifyServer(void) +{ + // Send a message to the app_server with the settings which we have. + // While it might be worthwhile to someday have a separate protocol for + // updating just one color, for now, we just need something to get things + // done. Extract all the colors from the settings BMessage, attach them + // to a PortLink message and fire it off to the server. + + // Name taken from ServerProtocol.h + port_id serverport=find_port("OBappserver"); + + if(serverport==B_NAME_NOT_FOUND) + return; + + PortLink *pl=new PortLink(serverport); + +// pl->SetOpCode(SET_UI_COLORS); + + // extract settings from settings object and attach to portlink object + +// pl->Flush(); + delete pl; +} + +void DecView::GetDecorators(void) +{ +#ifdef DEBUG_DECORATOR +printf("GetDecorators\n"); +#endif + BDirectory dir; + BEntry entry; + BPath path; + BString name; + BStringItem *item; + + if(dir.SetTo(DECORATORS_DIR)!=B_OK) + return; + + int32 count=dir.CountEntries(); + + for(int32 i=0;iAddItem(item); + } + +} + +bool DecView::LoadDecorator(const char *path) +{ + if(!path) + return false; + create_decorator *pcreatefunc=NULL; + get_decorator_version *pversionfunc=NULL; + status_t stat; + image_id addon; + + addon=load_add_on(path); + + stat=get_image_symbol(addon, "get_decorator_version", B_SYMBOL_TYPE_TEXT, (void**)&pversionfunc); + if(stat!=B_OK) + { + unload_add_on(addon); +#ifdef DEBUG_DECORATOR +printf("LoadDecorator(%s): Couldn't get version symbol\n",path); +#endif + return false; + } + + // As of now, we do nothing with decorator versions, but the possibility exists + // that the API will change even though I cannot forsee any reason to do so. If + // we *did* do anything with decorator versions, the assignment to a global would + // go here. + + stat=get_image_symbol(addon, "instantiate_decorator", B_SYMBOL_TYPE_TEXT, (void**)&pcreatefunc); + if(stat!=B_OK) + { + unload_add_on(addon); +#ifdef DEBUG_DECORATOR +printf("LoadDecorator(%s): Couldn't get allocation symbol\n",path); +#endif + return false; + } + if(decorator!=NULL) + { +#ifdef DEBUG_DECORATOR +printf("LoadDecorator(): Deleting old decorator\n"); +#endif + delete decorator; + unload_add_on(decorator_id); + } + decorator_id=addon; + decorator=pcreatefunc(SRect(50,50,150,150),WLOOK_TITLED,WFEEL_NORMAL,0); + decorator->SetDriver(driver); + decorator->SetFocus(true); +// decorator->Draw(); + return true; +} + +const char * DecView::ConvertIndexToPath(int32 index) +{ + BStringItem *item=(BStringItem*)declist->ItemAt(index); + if(!item) + return NULL; + BString path(DECORATORS_DIR); + path+=item->Text(); + return path.String(); +} diff --git a/src/prefs/appearance/DecView.h b/src/prefs/appearance/DecView.h new file mode 100644 index 0000000000..ec294090f8 --- /dev/null +++ b/src/prefs/appearance/DecView.h @@ -0,0 +1,42 @@ +#ifndef DEC_VIEW_H_ +#define DEC_VIEW_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +class PreviewDriver; +class Decorator; + +class DecView : public BView +{ +public: + DecView(BRect frame, const char *name, int32 resize, int32 flags); + ~DecView(void); + void AttachedToWindow(void); + void MessageReceived(BMessage *msg); + void SaveSettings(void); + void LoadSettings(void); + void SetDefaults(void); + void NotifyServer(void); + void GetDecorators(void); + bool LoadDecorator(const char *path); + const char * ConvertIndexToPath(int32 index); +protected: + BButton *apply; + BListView *declist; + BMessage settings; + BScrollView *scrollview; + PreviewDriver *driver; + BView *preview; + Decorator *decorator; + image_id decorator_id; + BString decpath; +}; + +#endif diff --git a/src/prefs/appearance/Decorator.cpp b/src/prefs/appearance/Decorator.cpp new file mode 100644 index 0000000000..67962ad1ea --- /dev/null +++ b/src/prefs/appearance/Decorator.cpp @@ -0,0 +1,238 @@ +#include "Decorator.h" +#include + +Decorator::Decorator(SRect rect, int32 wlook, int32 wfeel, int32 wflags) +{ + close_state=false; + minimize_state=false; + zoom_state=false; + title_string=NULL; + driver=NULL; + + closerect.Set(0,0,1,1); + zoomrect.Set(0,0,1,1); + minimizerect.Set(0,0,1,1); + resizerect.Set(0,0,1,1); + frame=rect; + tabrect.Set(rect.left,rect.top,rect.right, rect.top+((rect.bottom-rect.top)/4)); + + look=wlook; + feel=wfeel; + flags=wflags; + + colors=new ColorSet(); +} + +Decorator::~Decorator(void) +{ + delete colors; + if(title_string) + delete title_string; +} + +void Decorator::SetColors(ColorSet cset) +{ + *colors=cset; +} + +void Decorator::SetDriver(DisplayDriver *d) +{ + driver=d; +} + +void Decorator::SetClose(bool is_down) +{ + close_state=is_down; +} + +void Decorator::SetMinimize(bool is_down) +{ + zoom_state=is_down; +} + +void Decorator::SetZoom(bool is_down) +{ + minimize_state=is_down; +} + +void Decorator::SetFlags(int32 wflags) +{ + flags=wflags; +} + +void Decorator::SetFeel(int32 wfeel) +{ + feel=wfeel; +} + +void Decorator::SetLook(int32 wlook) +{ + look=wlook; +} + +bool Decorator::GetClose(void) +{ + return close_state; +} + +bool Decorator::GetMinimize(void) +{ + return minimize_state; +} + +bool Decorator::GetZoom(void) +{ + return zoom_state; +} + +int32 Decorator::GetLook(void) +{ + return look; +} + +int32 Decorator::GetFeel(void) +{ + return feel; +} + +int32 Decorator::GetFlags(void) +{ + return flags; +} + +void Decorator::SetTitle(const char *string) +{ + if(string) + { + size_t size=strlen(string); + if(!(size>0)) + return; + delete title_string; + title_string=new char[size]; + strcpy(title_string,string); + } + else + { + delete title_string; + title_string=NULL; + } +} + +const char *Decorator::GetTitle(void) +{ + return title_string; +} + +void Decorator::SetFocus(bool is_active) +{ + has_focus=is_active; + _SetFocus(); +} + +/* +void Decorator::SetFont(SFont *sf) +{ +} +*/ +void Decorator::_ClipTitle(void) +{ +} + +//------------------------------------------------------------------------- +// Virtual Methods +//------------------------------------------------------------------------- +void Decorator::MoveBy(float x, float y) +{ +} + +void Decorator::MoveBy(SPoint pt) +{ +} + +void Decorator::ResizeBy(float x, float y) +{ +} + +void Decorator::ResizeBy(SPoint pt) +{ +} + +void Decorator::Draw(SRect r) +{ + _DrawTab(r & tabrect); + _DrawFrame(r & frame); +} + +void Decorator::Draw(void) +{ + _DrawTab(tabrect); + _DrawFrame(frame); +} + +void Decorator::DrawClose(void) +{ + _DrawClose(closerect); +} + +void Decorator::DrawFrame(void) +{ + _DrawFrame(frame); +} + +void Decorator::DrawMinimize(void) +{ + _DrawTab(minimizerect); +} + +void Decorator::DrawTab(void) +{ + _DrawTab(tabrect); + _DrawZoom(zoomrect); + _DrawMinimize(minimizerect); + _DrawTitle(tabrect); + _DrawClose(closerect); +} + +void Decorator::DrawTitle(void) +{ + _DrawTitle(tabrect); +} + +void Decorator::DrawZoom(void) +{ + _DrawZoom(zoomrect); +} + +void Decorator::_DrawClose(SRect r) +{ +} + +void Decorator::_DrawFrame(SRect r) +{ +} + +void Decorator::_DrawMinimize(SRect r) +{ +} + +void Decorator::_DrawTab(SRect r) +{ +} + +void Decorator::_DrawTitle(SRect r) +{ +} + +void Decorator::_DrawZoom(SRect r) +{ +} +/* +SRegion Decorator::GetFootprint(void) +{ +} +*/ +click_type Decorator::Clicked(SPoint pt, int32 buttons, int32 modifiers) +{ + return CLICK_NONE; +} + diff --git a/src/prefs/appearance/Decorator.h b/src/prefs/appearance/Decorator.h new file mode 100644 index 0000000000..223e787ed8 --- /dev/null +++ b/src/prefs/appearance/Decorator.h @@ -0,0 +1,119 @@ +#ifndef _DECORATOR_H_ +#define _DECORATOR_H_ + +#include +#include "SRect.h" +#include "ColorSet.h" +#include "LayerData.h" + +class DisplayDriver; + +typedef enum { CLICK_NONE=0, CLICK_ZOOM, CLICK_CLOSE, CLICK_MINIMIZE, + CLICK_TAB, CLICK_DRAG, CLICK_MOVETOBACK, CLICK_MOVETOFRONT, + + CLICK_RESIZE, CLICK_RESIZE_L, CLICK_RESIZE_T, + CLICK_RESIZE_R, CLICK_RESIZE_B, CLICK_RESIZE_LT, CLICK_RESIZE_RT, + CLICK_RESIZE_LB, CLICK_RESIZE_RB } click_type; + +// Definitions which are used in place of including Window.h +// window_look and window_feel are enumerated types, so we convert them +// to uint32's in order to ensure a constant size when sending via PortLink +// instead of depending on magic numbers in the header file. + +#define WLOOK_NO_BORDER 0 +#define WLOOK_BORDERED 1 +#define WLOOK_TITLED 2 +#define WLOOK_DOCUMENT 3 +#define WLOOK_MODAL 4 +#define WLOOK_FLOATING 5 + +#define WFEEL_NORMAL 0 +#define WFEEL_MODAL_SUBSET 1 +#define WFEEL_MODAL_APP 2 +#define WFEEL_MODAL_WINDOW 3 +#define WFEEL_FLOATING_SUBSET 4 +#define WFEEL_FLOATING_APP 5 +#define WFEEL_FLOATING_WINDOW 6 + +#define NOT_MOVABLE 0x00000001 +#define NOT_CLOSABLE 0x00000020 +#define NOT_ZOOMABLE 0x00000040 +#define NOT_MINIMIZABLE 0x00004000 +#define NOT_RESIZABLE 0x00000002 +#define NOT_H_RESIZABLE 0x00000004 +#define NOT_V_RESIZABLE 0x00000008 +#define AVOID_FRONT 0x00000080 +#define AVOID_FOCUS 0x00002000 +#define WILL_ACCEPT_FIRST_CLICK 0x00000010 +#define OUTLINE_RESIZE 0x00001000 +#define NO_WORKSPACE_ACTIVATION 0x00000100 +#define NOT_ANCHORED_ON_ACTIVATE 0x00020000 +#define ASYNCHRONOUS_CONTROLS 0x00080000 +#define QUIT_ON_WINDOW_CLOSE 0x00100000 + +class Decorator +{ +public: + Decorator(SRect rect, int32 wlook, int32 wfeel, int32 wflags); + virtual ~Decorator(void); + void SetColors(ColorSet cset); + void SetDriver(DisplayDriver *d); + void SetClose(bool is_down); + void SetMinimize(bool is_down); + void SetZoom(bool is_down); + void SetFlags(int32 wflags); + void SetFeel(int32 wfeel); + void SetLook(int32 wlook); + bool GetClose(void); + bool GetMinimize(void); + bool GetZoom(void); + int32 GetLook(void); + int32 GetFeel(void); + int32 GetFlags(void); + void SetTitle(const char *string); + void SetFocus(bool is_active); + bool GetFocus(void) { return has_focus; }; + const char *GetTitle(void); +// void SetFont(SFont *sf); + void _ClipTitle(void); + + virtual void MoveBy(float x, float y); + virtual void MoveBy(SPoint pt); + virtual void ResizeBy(float x, float y); + virtual void ResizeBy(SPoint pt); + virtual void Draw(SRect r); + virtual void Draw(void); + virtual void DrawClose(void); + virtual void DrawFrame(void); + virtual void DrawMinimize(void); + virtual void DrawTab(void); + virtual void DrawTitle(void); + virtual void DrawZoom(void); + //virtual SRegion GetFootprint(void); + virtual click_type Clicked(SPoint pt, int32 buttons, int32 modifiers); + +protected: + virtual void _DrawClose(SRect r); + virtual void _DrawFrame(SRect r); + virtual void _DrawMinimize(SRect r); + virtual void _DrawTab(SRect r); + virtual void _DrawTitle(SRect r); + virtual void _DrawZoom(SRect r); + virtual void _SetFocus(void)=0; + virtual void _DoLayout(void)=0; + ColorSet *colors; + int32 look, feel, flags; + DisplayDriver *driver; + LayerData layerdata; + SRect zoomrect,closerect,minimizerect,tabrect,frame, + resizerect,borderrect; +private: + bool close_state, zoom_state, minimize_state; + bool has_focus; + char *title_string; +}; + +typedef uint16 get_decorator_version(void); +typedef Decorator *create_decorator(SRect rect, int32 wlook, int32 wfeel, int32 wflags); + +#endif diff --git a/src/prefs/appearance/DisplayDriver.cpp b/src/prefs/appearance/DisplayDriver.cpp new file mode 100644 index 0000000000..d36510f3e4 --- /dev/null +++ b/src/prefs/appearance/DisplayDriver.cpp @@ -0,0 +1,85 @@ +/* + DisplayDriver.cpp + Modular class to allow the server to not care what the ultimate output is + for graphics calls. +*/ +#include "DisplayDriver.h" +#include "LayerData.h" + +DisplayDriver::DisplayDriver(void) +{ + lock_sem=create_sem(1,"displaydriver_lock"); + buffer_depth=0; + buffer_width=0; + buffer_height=0; + buffer_mode=-1; +} + +DisplayDriver::~DisplayDriver(void) +{ + delete_sem(lock_sem); +} + +bool DisplayDriver::Initialize(void) +{ + return false; +} + +uint8 DisplayDriver::GetDepth(void) +{ + return buffer_depth; +} + +uint16 DisplayDriver::GetHeight(void) +{ + return buffer_height; +} + +uint16 DisplayDriver::GetWidth(void) +{ + return buffer_width; +} + +int32 DisplayDriver::GetMode(void) +{ + return buffer_mode; +} + +bool DisplayDriver::DumpToFile(const char *path) +{ + return false; +} + +//--------------------------------------------------------- +// Private Methods +//--------------------------------------------------------- + +void DisplayDriver::Lock(void) +{ + acquire_sem(lock_sem); +} + +void DisplayDriver::Unlock(void) +{ + release_sem(lock_sem); +} + +void DisplayDriver::SetDepthInternal(uint8 d) +{ + buffer_depth=d; +} + +void DisplayDriver::SetHeightInternal(uint16 h) +{ + buffer_height=h; +} + +void DisplayDriver::SetWidthInternal(uint16 w) +{ + buffer_width=w; +} + +void DisplayDriver::SetModeInternal(int32 m) +{ + buffer_mode=m; +} diff --git a/src/prefs/appearance/DisplayDriver.h b/src/prefs/appearance/DisplayDriver.h new file mode 100644 index 0000000000..251824eae4 --- /dev/null +++ b/src/prefs/appearance/DisplayDriver.h @@ -0,0 +1,115 @@ +#ifndef _DISPLAY_DRIVER_H_ +#define _DISPLAY_DRIVER_H_ + +#include +#include +#include + +#include "SRect.h" +#include "SPoint.h" +#include "RGBColor.h" + +class ServerBitmap; +class ServerCursor; +class LayerData; + +#ifndef ROUND + #define ROUND(a) ( (a-long(a))>=.5)?(long(a)+1):(long(a)) +#endif + +typedef struct +{ + uchar *xormask, *andmask; + int32 width, height; + int32 hotx, hoty; + +} cursor_data; + +#ifndef HOOK_DEFINE_CURSOR + +#define HOOK_DEFINE_CURSOR 0 +#define HOOK_MOVE_CURSOR 1 +#define HOOK_SHOW_CURSOR 2 +#define HOOK_DRAW_LINE_8BIT 3 +#define HOOK_DRAW_LINE_16BIT 12 +#define HOOK_DRAW_LINE_32BIT 4 +#define HOOK_DRAW_RECT_8BIT 5 +#define HOOK_DRAW_RECT_16BIT 13 +#define HOOK_DRAW_RECT_32BIT 6 +#define HOOK_BLIT 7 +#define HOOK_DRAW_ARRAY_8BIT 8 +#define HOOK_DRAW_ARRAY_16BIT 14 // Not implemented in current R5 drivers +#define HOOK_DRAW_ARRAY_32BIT 9 +#define HOOK_SYNC 10 +#define HOOK_INVERT_RECT 11 + +#endif + +#define DRAW_COPY 0 +#define DRAW_OVER 1 +#define DRAW_ERASE 2 +#define DRAW_INVERT 3 +#define DRAW_ADD 4 +#define DRAW_SUBTRACT 5 +#define DRAW_BLEND 6 +#define DRAW_MIN 7 +#define DRAW_MAX 8 +#define DRAW_SELECT 9 +#define DRAW_ALPHA 10 + +class DisplayDriver +{ +public: + DisplayDriver(void); + virtual ~DisplayDriver(void); + virtual bool Initialize(void); + virtual void Shutdown(void)=0; + virtual void CopyBits(SRect src, SRect dest)=0; + virtual void DrawBitmap(ServerBitmap *bmp, SRect src, SRect dest)=0; + virtual void DrawChar(char c, SPoint pt)=0; +// virtual void DrawPicture(SPicture *pic, SPoint pt)=0; +// virtual void DrawString(const char *string, int32 length, SPoint pt, escapement_delta *delta=NULL)=0; + virtual void InvertRect(SRect r)=0; + virtual void StrokeBezier(SPoint *pts, LayerData *d, int8 *pat)=0; + virtual void FillBezier(SPoint *pts, LayerData *d, int8 *pat)=0; + virtual void StrokeEllipse(SRect r, LayerData *d, int8 *pat)=0; + virtual void FillEllipse(SRect r, LayerData *d, int8 *pat)=0; + virtual void StrokeArc(SRect r, float angle, float span, LayerData *d, int8 *pat)=0; + virtual void FillArc(SRect r, float angle, float span, LayerData *d, int8 *pat)=0; + virtual void StrokeLine(SPoint start, SPoint end, LayerData *d, int8 *pat)=0; + virtual void StrokePolygon(SPoint *ptlist, int32 numpts, SRect rect, LayerData *d, int8 *pat, bool is_closed=true)=0; + virtual void FillPolygon(SPoint *ptlist, int32 numpts, SRect rect, LayerData *d, int8 *pat)=0; + virtual void StrokeRect(SRect r, LayerData *d, int8 *pat)=0; + virtual void FillRect(SRect r, LayerData *d, int8 *pat)=0; + virtual void StrokeRoundRect(SRect r, float xrad, float yrad, LayerData *d, int8 *pat)=0; + virtual void FillRoundRect(SRect r, float xrad, float yrad, LayerData *d, int8 *pat)=0; +// virtual void StrokeShape(SShape *sh, LayerData *d, int8 *pat)=0; +// virtual void FillShape(SShape *sh, LayerData *d, int8 *pat)=0; + virtual void StrokeTriangle(SPoint *pts, SRect r, LayerData *d, int8 *pat)=0; + virtual void FillTriangle(SPoint *pts, SRect r, LayerData *d, int8 *pat)=0; + virtual void StrokeLineArray(SPoint *pts, int32 numlines, RGBColor *colors, LayerData *d)=0; + virtual void SetMode(int32 mode)=0; + virtual bool DumpToFile(const char *path)=0; + + uint8 GetDepth(void); + uint16 GetHeight(void); + uint16 GetWidth(void); + int32 GetMode(void); + +protected: + void Lock(void); + void Unlock(void); + void SetDepthInternal(uint8 d); + void SetHeightInternal(uint16 h); + void SetWidthInternal(uint16 w); + void SetModeInternal(int32 m); + +private: + sem_id lock_sem; + uint8 buffer_depth; + uint16 buffer_width; + uint16 buffer_height; + int32 buffer_mode; +}; + +#endif \ No newline at end of file diff --git a/src/prefs/appearance/LayerData.h b/src/prefs/appearance/LayerData.h new file mode 100644 index 0000000000..7d25459c89 --- /dev/null +++ b/src/prefs/appearance/LayerData.h @@ -0,0 +1,35 @@ +#ifndef LAYERDATA_H_ +#define LAYERDATA_H_ + +class ServerBitmap; + +class LayerData +{ +public: +LayerData(void) + { + pensize=1.0; + penlocation.Set(0,0); + drawing_mode=0; + bitmap_background=NULL; + bitmap_overlay=NULL; + highcolor.SetColor(0,0,0,255); + lowcolor.SetColor(255,255,255,255); + //SFont font; + //bool antialias_text; + scale=1.0; + }; + +float pensize; +SPoint penlocation; +int32 drawing_mode; +ServerBitmap *bitmap_background; +ServerBitmap *bitmap_overlay; +RGBColor highcolor, lowcolor; +//SFont font; +//bool antialias_text; +float scale; +}; + + +#endif \ No newline at end of file diff --git a/src/prefs/appearance/PreviewDriver.cpp b/src/prefs/appearance/PreviewDriver.cpp new file mode 100644 index 0000000000..1287532053 --- /dev/null +++ b/src/prefs/appearance/PreviewDriver.cpp @@ -0,0 +1,338 @@ +/* + PreviewDriver: + Module based on proto6's ViewDriver for the purpose of Decorator previews. + + The concept is to have a view draw a bitmap, which is a "frame buffer" + of sorts, utilize a second view to write to it. This cuts out + the most problems with having a crapload of code to get just right without + having to write a bunch of unit tests + + Components: 3 classes, VDView, VDWindow, and ViewDriver + + PreviewDriver - a wrapper class which mostly posts messages to the VDWindow + PDView - doesn't do all that much except display the rendered bitmap +*/ + +//#define DEBUG_DRIVER_MODULE +//#define DEBUG_SERVER_EMU + +//#define DISABLE_SERVER_EMU + +#include +#include +#include +#include +#include +#include +#include +#include "PortLink.h" +#include "PreviewDriver.h" +#include "LayerData.h" + +SRect preview_bounds(0,0,200,200);; + +PVView::PVView(BRect bounds) + : BView(bounds,"previewdriver_view",B_FOLLOW_NONE, B_WILL_DRAW) +{ + viewbmp=new BBitmap(bounds,B_RGB32,true); +} + +PVView::~PVView(void) +{ + delete viewbmp; +} + +void PVView::AttachedToWindow(void) +{ + win=Window(); +} + +void PVView::DetachedFromWindow(void) +{ + win=NULL; +} + +void PVView::Draw(BRect rect) +{ + if(viewbmp) + { + DrawBitmapAsync(viewbmp,rect,rect); + Sync(); + } +} + +PreviewDriver::PreviewDriver(void) +{ + view=new PVView(preview_bounds.Rect()); + drawview=new BView(preview_bounds.Rect(),"drawview",B_FOLLOW_ALL, 0); +} + +PreviewDriver::~PreviewDriver(void) +{ + delete view; + delete drawview; +} + +bool PreviewDriver::Initialize(void) +{ + view->viewbmp->Lock(); + view->viewbmp->AddChild(drawview); + view->viewbmp->Unlock(); + return true; +} + +void PreviewDriver::Shutdown(void) +{ + view->viewbmp->Lock(); + view->viewbmp->RemoveChild(drawview); + view->viewbmp->Unlock(); +} + +void PreviewDriver::CopyBits(SRect src, SRect dest) +{ + view->viewbmp->Lock(); + drawview->CopyBits(src.Rect(),dest.Rect()); + drawview->Sync(); + view->Invalidate(dest.Rect()); + view->viewbmp->Unlock(); +} + +void PreviewDriver::DrawBitmap(ServerBitmap *bmp, SRect src, SRect dest) +{ +} + +void PreviewDriver::DrawChar(char c, SPoint pt) +{ + view->viewbmp->Lock(); + drawview->DrawChar(c,pt.Point()); + drawview->Sync(); + view->Invalidate(); + view->viewbmp->Unlock(); +} + +/* +void DrawPicture(SPicture *pic, SPoint pt) +{ +} + +void DrawString(const char *string, int32 length, SPoint pt, escapement_delta *delta=NULL) +{ +} +*/ + +void PreviewDriver::InvertRect(SRect r) +{ + view->viewbmp->Lock(); + drawview->InvertRect(r.Rect()); + drawview->Sync(); + view->Invalidate(r.Rect()); + view->viewbmp->Unlock(); +} + +void PreviewDriver::StrokeBezier(SPoint *pts, LayerData *d, int8 *pat) +{ + BPoint points[4]; + for(uint8 i=0;i<4;i++) + points[i]=pts[i].Point(); + + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->StrokeBezier(points,*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(); + view->viewbmp->Unlock(); +} + +void PreviewDriver::FillBezier(SPoint *pts, LayerData *d, int8 *pat) +{ + BPoint points[4]; + for(uint8 i=0;i<4;i++) + points[i]=pts[i].Point(); + + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->StrokeBezier(points,*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(); + view->viewbmp->Unlock(); +} + +void PreviewDriver::StrokeEllipse(SRect r, LayerData *d, int8 *pat) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->StrokeEllipse(r.Rect(),*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(r.Rect()); + view->viewbmp->Unlock(); +} + +void PreviewDriver::FillEllipse(SRect r, LayerData *d, int8 *pat) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->FillEllipse(r.Rect(),*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(r.Rect()); + view->viewbmp->Unlock(); +} + +void PreviewDriver::StrokeArc(SRect r, float angle, float span, LayerData *d, int8 *pat) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->StrokeArc(r.Rect(),angle,span,*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(r.Rect()); + view->viewbmp->Unlock(); +} + +void PreviewDriver::FillArc(SRect r, float angle, float span, LayerData *d, int8 *pat) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->FillArc(r.Rect(),angle,span,*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(r.Rect()); + view->viewbmp->Unlock(); +} + +void PreviewDriver::StrokeLine(SPoint start, SPoint end, LayerData *d, int8 *pat) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->StrokeLine(start.Point(),end.Point(),*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(); + view->viewbmp->Unlock(); +} + +void PreviewDriver::StrokePolygon(SPoint *ptlist, int32 numpts, SRect rect, LayerData *d, int8 *pat, bool is_closed=true) +{ +} + +void PreviewDriver::FillPolygon(SPoint *ptlist, int32 numpts, SRect rect, LayerData *d, int8 *pat) +{ +} + +void PreviewDriver::StrokeRect(SRect r, LayerData *d, int8 *pat) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->StrokeRect(r.Rect(),*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(r.Rect()); + view->viewbmp->Unlock(); +} + +void PreviewDriver::FillRect(SRect r, LayerData *d, int8 *pat) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->FillRect(r.Rect(),*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(r.Rect()); + view->viewbmp->Unlock(); +} + +void PreviewDriver::StrokeRoundRect(SRect r, float xrad, float yrad, LayerData *d, int8 *pat) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->StrokeRoundRect(r.Rect(),xrad,yrad,*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(r.Rect()); + view->viewbmp->Unlock(); +} + +void PreviewDriver::FillRoundRect(SRect r, float xrad, float yrad, LayerData *d, int8 *pat) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->FillRoundRect(r.Rect(),xrad,yrad,*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(r.Rect()); + view->viewbmp->Unlock(); +} + +/* +void StrokeShape(SShape *sh, LayerData *d, int8 *pat) +{ +} + +void FillShape(SShape *sh, LayerData *d, int8 *pat) +{ +} +*/ + +void PreviewDriver::StrokeTriangle(SPoint *pts, SRect r, LayerData *d, int8 *pat) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->StrokeTriangle(pts[0].Point(),pts[1].Point(), + pts[2].Point(),r.Rect(),*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(r.Rect()); + view->viewbmp->Unlock(); +} + +void PreviewDriver::FillTriangle(SPoint *pts, SRect r, LayerData *d, int8 *pat) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->FillTriangle(pts[0].Point(),pts[1].Point(), + pts[2].Point(),r.Rect(),*((pattern *)pat)); + drawview->Sync(); + view->Invalidate(r.Rect()); + view->viewbmp->Unlock(); +} + +void PreviewDriver::StrokeLineArray(SPoint *pts, int32 numlines, RGBColor *colors, LayerData *d) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->SetPenSize(d->pensize); + drawview->BeginLineArray(numlines); + for(int32 i=0; iAddLine(pts[2*i].Point(),pts[(2*i)+1].Point(),colors[i].GetColor32()); + drawview->EndLineArray(); + drawview->Sync(); + view->Invalidate(); + view->viewbmp->Unlock(); +} + +void PreviewDriver::SetMode(int32 mode) +{ +} + +bool PreviewDriver::DumpToFile(const char *path) +{ + return false; +} diff --git a/src/prefs/appearance/PreviewDriver.h b/src/prefs/appearance/PreviewDriver.h new file mode 100644 index 0000000000..731eb29cf5 --- /dev/null +++ b/src/prefs/appearance/PreviewDriver.h @@ -0,0 +1,79 @@ +#ifndef _PREVIEWDRIVER_H_ +#define _PREVIEWDRIVER_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "DisplayDriver.h" + + +class BBitmap; +class PortLink; +class ServerCursor; + +class PVView : public BView +{ +public: + PVView(BRect bounds); + ~PVView(void); + void AttachedToWindow(void); + void DetachedFromWindow(void); + void Draw(BRect rect); + + BBitmap *viewbmp; + BWindow *win; +}; + +class PreviewDriver : public DisplayDriver +{ +public: + PreviewDriver(void); + ~PreviewDriver(void); + + virtual bool Initialize(void); + virtual void Shutdown(void); + virtual void CopyBits(SRect src, SRect dest); + virtual void DrawBitmap(ServerBitmap *bmp, SRect src, SRect dest); + virtual void DrawChar(char c, SPoint pt); +// virtual void DrawPicture(SPicture *pic, SPoint pt); +// virtual void DrawString(const char *string, int32 length, SPoint pt, escapement_delta *delta=NULL); + virtual void InvertRect(SRect r); + virtual void StrokeBezier(SPoint *pts, LayerData *d, int8 *pat); + virtual void FillBezier(SPoint *pts, LayerData *d, int8 *pat); + virtual void StrokeEllipse(SRect r, LayerData *d, int8 *pat); + virtual void FillEllipse(SRect r, LayerData *d, int8 *pat); + virtual void StrokeArc(SRect r, float angle, float span, LayerData *d, int8 *pat); + virtual void FillArc(SRect r, float angle, float span, LayerData *d, int8 *pat); + virtual void StrokeLine(SPoint start, SPoint end, LayerData *d, int8 *pat); + virtual void StrokePolygon(SPoint *ptlist, int32 numpts, SRect rect, LayerData *d, int8 *pat, bool is_closed=true); + virtual void FillPolygon(SPoint *ptlist, int32 numpts, SRect rect, LayerData *d, int8 *pat); + virtual void StrokeRect(SRect r, LayerData *d, int8 *pat); + virtual void FillRect(SRect r, LayerData *d, int8 *pat); + virtual void StrokeRoundRect(SRect r, float xrad, float yrad, LayerData *d, int8 *pat); + virtual void FillRoundRect(SRect r, float xrad, float yrad, LayerData *d, int8 *pat); +// virtual void StrokeShape(SShape *sh, LayerData *d, int8 *pat); +// virtual void FillShape(SShape *sh, LayerData *d, int8 *pat); + virtual void StrokeTriangle(SPoint *pts, SRect r, LayerData *d, int8 *pat); + virtual void FillTriangle(SPoint *pts, SRect r, LayerData *d, int8 *pat); + virtual void StrokeLineArray(SPoint *pts, int32 numlines, RGBColor *colors, LayerData *d); + virtual void SetMode(int32 mode); + virtual bool DumpToFile(const char *path); + + BView *View(void) { return (BView*)view; }; +protected: + BBitmap *framebuffer; + BView *drawview; + + // Region used to track of invalid areas for the Begin/EndLineArray functions + BRegion laregion; + PVView *view; +}; + +extern SRect preview_bounds; + +#endif \ No newline at end of file diff --git a/src/prefs/appearance/RGBColor.cpp b/src/prefs/appearance/RGBColor.cpp new file mode 100644 index 0000000000..603cb835d4 --- /dev/null +++ b/src/prefs/appearance/RGBColor.cpp @@ -0,0 +1,157 @@ +/* + RGBColor.cpp + Color encapsulation class for app_server. +*/ + +#include "RGBColor.h" + +RGBColor::RGBColor(uint8 r, uint8 g, uint8 b, uint8 a=255) +{ + SetColor(r,g,b,a); +} + +RGBColor::RGBColor(rgb_color col) +{ + SetColor(col); +} + +RGBColor::RGBColor(uint16 col) +{ + SetColor(col); +} + +RGBColor::RGBColor(uint8 col) +{ + SetColor(col); +} + +RGBColor::RGBColor(const RGBColor &col) +{ + color32=col.color32; + color16=col.color16; + color8=col.color8; +} + +RGBColor::RGBColor(void) +{ + SetColor(0,0,0,0); +} + +uint8 RGBColor::GetColor8(void) +{ + return color8; +} + +uint16 RGBColor::GetColor16(void) +{ + return color16; +} + +rgb_color RGBColor::GetColor32(void) +{ + return color32; +} + +void RGBColor::SetColor(uint8 r, uint8 g, uint8 b, uint8 a=255) +{ + color32.red=r; + color32.green=g; + color32.blue=b; + color32.alpha=a; +} + +void RGBColor::SetColor(uint16 col16) +{ + // Pared-down version from what is used in the app_server to + // eliminate some dependencies + color16=col16; +} + +void RGBColor::SetColor(uint8 col8) +{ + // Pared-down version from what is used in the app_server to + // eliminate some dependencies + color8=col8; +} + +void RGBColor::SetColor(rgb_color color) +{ + // Pared-down version from what is used in the app_server to + // eliminate some dependencies + color32=color; +} + +void RGBColor::SetColor(const RGBColor &col) +{ + color32=col.color32; + color16=col.color16; + color8=col.color8; +} + + +RGBColor & RGBColor::operator=(const RGBColor &col) +{ + color32=col.color32; + color16=col.color16; + color8=col.color8; + return *this; +} + +RGBColor & RGBColor::operator=(rgb_color col) +{ + color32=col; + return *this; +} + +RGBColor RGBColor::MakeBlendColor(RGBColor color, float position) +{ + rgb_color col=color32; + rgb_color col2=color.color32; + + rgb_color newcol={0,0,0,0}; + float mod=0; + int16 delta; + if(position<0 || position>1) + return newcol; + + delta=int16(col2.red)-int16(col.red); + mod=col.red + (position * delta); + newcol.red=uint8(mod); + if(mod>255 ) + newcol.red=255; + if(mod<0 ) + newcol.red=0; + + delta=int16(col2.green)-int16(col.green); + mod=col.green + (position * delta); + newcol.green=uint8(mod); + if(mod>255 ) + newcol.green=255; + if(mod<0 ) + newcol.green=0; + + delta=int16(col2.blue)-int16(col.blue); + mod=col.blue + (position * delta); + newcol.blue=uint8(mod); + if(mod>255 ) + newcol.blue=255; + if(mod<0 ) + newcol.blue=0; + + delta=int8(col2.alpha)-int8(col.alpha); + mod=col.alpha + (position * delta); + newcol.alpha=uint8(mod); + if(mod>255 ) + newcol.alpha=255; + if(mod<0 ) + newcol.alpha=0; +#ifdef DEBUG_COLOR_UTILS +printf("MakeBlendColor( {%u,%u,%u,%u}, {%u,%u,%u,%u}, %f) : {%u,%u,%u,%u}\n", + col.red,col.green,col.blue,col.alpha, + col2.red,col2.green,col2.blue,col2.alpha, + position, + newcol.red,newcol.green,newcol.blue,newcol.alpha); +#endif + + return RGBColor(newcol); +} diff --git a/src/prefs/appearance/RGBColor.h b/src/prefs/appearance/RGBColor.h new file mode 100644 index 0000000000..e7e1dad03e --- /dev/null +++ b/src/prefs/appearance/RGBColor.h @@ -0,0 +1,32 @@ +#ifndef RGBCOLOR_H_ +#define RGBCOLOR_H_ + +#include + +class RGBColor +{ +public: + RGBColor(uint8 r, uint8 g, uint8 b, uint8 a=255); + RGBColor(rgb_color col); + RGBColor(uint16 col); + RGBColor(uint8 col); + RGBColor(const RGBColor &col); + RGBColor(void); + uint8 GetColor8(void); + uint16 GetColor16(void); + rgb_color GetColor32(void); + void SetColor(uint8 r, uint8 g, uint8 b, uint8 a=255); + void SetColor(uint16 color16); + void SetColor(uint8 color8); + void SetColor(rgb_color color); + void SetColor(const RGBColor &col); + RGBColor MakeBlendColor(RGBColor color, float position); + RGBColor & operator=(const RGBColor &col); + RGBColor & operator=(rgb_color col); +protected: + rgb_color color32; + uint16 color16; + uint8 color8; +}; + +#endif \ No newline at end of file diff --git a/src/prefs/appearance/SPoint.cpp b/src/prefs/appearance/SPoint.cpp new file mode 100644 index 0000000000..48b9135256 --- /dev/null +++ b/src/prefs/appearance/SPoint.cpp @@ -0,0 +1,92 @@ +/* + SPoint.cpp: + Point class which utilizes Frans van Nispen's original SPoint sources + and extends them slightly for app_server use. +*/ + +#include +#include + +#include +#include +#include "SPoint.h" +#include "SRect.h" + + + +void SPoint::ConstrainTo(SRect r) +{ + x = max_c(min_c(x, r.right), r.left); + y = max_c(min_c(y, r.bottom), r.top); +} + +void SPoint::PrintToStream() const +{ + printf("SPoint(x:%.0f, y:%.0f)\n", x, y); +} + +SPoint SPoint::operator+(const SPoint& p) const +{ + return SPoint(x + p.x, y + p.y); +} + +SPoint SPoint::operator-(const SPoint& p) const +{ + return SPoint(x - p.x, y - p.y); +} + +SPoint SPoint::operator*(const SPoint& p) const +{ + return SPoint(x * p.x, y * p.y); +} + +SPoint SPoint::operator/(const SPoint& p) const +{ + return SPoint((p.x!=0)?(x / p.x):0,(p.y!=0)?(y / p.y):0); +} + +SPoint& SPoint::operator+=(const SPoint& p) +{ + x += p.x; + y += p.y; + + return *this; +} + +SPoint& SPoint::operator-=(const SPoint& p) +{ + x -= p.x; + y -= p.y; + + return *this; +} + +bool SPoint::operator!=(const SPoint& p) const +{ + return x != p.x || y != p.y; +} + +bool SPoint::operator==(const SPoint& p) const +{ + return x == p.x && y == p.y; +} + +bool SPoint::operator<=(const SPoint& p) const +{ + return x <= p.x && y <= p.y; +} + +bool SPoint::operator>=(const SPoint& p) const +{ + return x >= p.x && y >= p.y; +} + +bool SPoint::operator<(const SPoint& p) const +{ + return x < p.x || y < p.y; +} + +bool SPoint::operator>(const SPoint& p) const +{ + return x > p.x && y > p.y; +} diff --git a/src/prefs/appearance/SPoint.h b/src/prefs/appearance/SPoint.h new file mode 100644 index 0000000000..f147303440 --- /dev/null +++ b/src/prefs/appearance/SPoint.h @@ -0,0 +1,80 @@ +#ifndef _SPOINT_H +#define _SPOINT_H + +#include +#include + +class SRect; + +#ifndef BE_SUPPORT +#define BE_SUPPORT +#endif + +#ifdef BE_SUPPORT +#include +#include +#endif + +class SPoint +{ +public: + float x; + float y; + + SPoint(); + SPoint(float X, float Y); + SPoint(const SPoint &p); + + SPoint &operator=(const SPoint &p); + void Set(float X, float Y); + + void ConstrainTo(SRect r); + void PrintToStream() const; + + SPoint operator+(const SPoint &p) const; + SPoint operator-(const SPoint &p) const; + SPoint operator*(const SPoint &p) const; + SPoint operator/(const SPoint &p) const; + SPoint& operator+=(const SPoint &p); + SPoint& operator-=(const SPoint &p); + + bool operator!=(const SPoint &p) const; + bool operator==(const SPoint &p) const; + bool operator>=(const SPoint &p) const; + bool operator<=(const SPoint &p) const; + bool operator>(const SPoint &p) const; + bool operator<(const SPoint &p) const; + +#ifdef BE_SUPPORT + BPoint Point(void) { return BPoint(x,y); }; +#endif +}; + +inline SPoint::SPoint() +{ + x = y = 0; +} +inline SPoint::SPoint(float X, float Y) +{ + x = X; + y = Y; +} +inline SPoint::SPoint(const SPoint& pt) +{ + x = pt.x; + y = pt.y; +} +inline SPoint &SPoint::operator=(const SPoint& from) +{ + x = from.x; + y = from.y; + return *this; +} +inline void SPoint::Set(float X, float Y) +{ + x = X; + y = Y; +} + + +#endif diff --git a/src/prefs/appearance/SRect.cpp b/src/prefs/appearance/SRect.cpp new file mode 100644 index 0000000000..403cc4cbef --- /dev/null +++ b/src/prefs/appearance/SRect.cpp @@ -0,0 +1,205 @@ +/* + SPoint.cpp: + Point class which utilizes Frans van Nispen's original SPoint sources + and extends them slightly for app_server use. +*/ + +#include +#include "SRect.h" + +bool TestLineIntersect(const SRect& r, float x1, float y1, float x2, float y2, + bool vertical = true); + + +void SRect::InsetBy(SPoint p) +{ + left += p.x; + right -= p.x; + top += p.y; + bottom -= p.y; +} + +void SRect::InsetBy(float dx, float dy) +{ + left += dx; + right -= dx; + top += dy; + bottom -= dy; +} + +SRect& SRect::InsetBySelf(SPoint p) +{ + this->InsetBy(p); + return *this; +} + +SRect& SRect::InsetBySelf(float dx, float dy) +{ + this->InsetBy(dx, dy); + return *this; +} + +SRect SRect::InsetByCopy(SPoint p) +{ + SRect copy(*this); + copy.InsetBy(p); + return copy; +} + +SRect SRect::InsetByCopy(float dx, float dy) +{ + SRect copy(*this); + copy.InsetBy(dx, dy); + return copy; +} + +void SRect::OffsetBy(SPoint p) +{ + left += p.x; + right += p.x; + top += p.y; + bottom += p.y; +} + +void SRect::OffsetBy(float dx, float dy) +{ + left += dx; + right += dx; + top += dy; + bottom += dy; +} + +SRect& SRect::OffsetBySelf(SPoint p) +{ + this->OffsetBy(p); + return *this; +} + +SRect& SRect::OffsetBySelf(float dx, float dy) +{ + this->OffsetBy(dx, dy); + return *this; +} + +SRect SRect::OffsetByCopy(SPoint p) +{ + SRect copy(*this); + copy.OffsetBy(p); + return copy; +} + +SRect SRect::OffsetByCopy(float dx, float dy) +{ + SRect copy(*this); + copy.OffsetBy(dx, dy); + return copy; +} + +void SRect::OffsetTo(SPoint p) +{ + right = (right - left) + p.x; + left = p.x; + bottom = (bottom - top) + p.y; + top = p.y; +} + +void SRect::OffsetTo(float x, float y) +{ + right = (right - left) + x; + left = x; + bottom = (bottom - top) + y; + top=y; +} + +SRect& SRect::OffsetToSelf(SPoint p) +{ + this->OffsetTo(p); + return *this; +} + +SRect& SRect::OffsetToSelf(float dx, float dy) +{ + this->OffsetTo(dx, dy); + return *this; +} + +SRect SRect::OffsetToCopy(SPoint p) +{ + SRect copy(*this); + copy.OffsetTo(p); + return copy; +} + +SRect SRect::OffsetToCopy(float dx, float dy) +{ + SRect copy(*this); + copy.OffsetTo(dx, dy); + return copy; +} + +void SRect::PrintToStream() const +{ + printf("(l:%.1f t:%.1f r:%.1f b:%.1f)\n", left, top, right, bottom); +} + +bool SRect::operator==(SRect r) const +{ + return left == r.left && right == r.right && + top == r.top && bottom == r.bottom; +} + +bool SRect::operator!=(SRect r) const +{ + return !(*this == r); +} + +SRect SRect::operator&(SRect r) const +{ + return SRect(max_c(left, r.left), max_c(top, r.top), + min_c(right, r.right), min_c(bottom, r.bottom)); +} + +SRect SRect::operator|(SRect r) const +{ + return SRect(min_c(left, r.left), min_c(top, r.top), + max_c(right, r.right), max_c(bottom, r.bottom)); +} + +bool SRect::Intersects(SRect r) const +{ + return TestLineIntersect(*this, r.left, r.top, r.left, r.bottom) || + TestLineIntersect(*this, r.left, r.top, r.right, r.top, false) || + TestLineIntersect(*this, r.right, r.top, r.right, r.bottom) || + TestLineIntersect(*this, r.left, r.bottom, r.right, r.bottom, false); +} + +bool SRect::Contains(SPoint p) const +{ + return p.x >= left && p.x <= right && p.y >= top && p.y <= bottom; +} + +bool SRect::Contains(SRect r) const +{ + return r.left >= left && r.right <= right && + r.top >= top && r.bottom <= bottom; +} + + + + +bool TestLineIntersect(const SRect& r, float x1, float y1, float x2, float y2, + bool vertical) +{ + if (vertical) + { + return (x1 >= r.left && x1 <= r.right) && + ((y1 >= r.top && y1 <= r.bottom) || + (y2 >= r.top && y2 <= r.bottom)); + } + else + { + return (y1 >= r.top && y1 <= r.bottom) && + ((x1 >= r.left && x1 <= r.right) || + (x2 >= r.left && x2 <= r.right)); + } +} diff --git a/src/prefs/appearance/SRect.h b/src/prefs/appearance/SRect.h new file mode 100644 index 0000000000..3550fc68cd --- /dev/null +++ b/src/prefs/appearance/SRect.h @@ -0,0 +1,187 @@ +#ifndef _SRECT_H_ +#define _SRECT_H_ + +// define used when this class also needs to support BRects +#ifndef BE_SUPPORT +#define BE_SUPPORT +#endif + +#include +#include +#include "SPoint.h" + +#ifdef BE_SUPPORT +#include +#endif + +class SRect +{ +public: + float left; + float top; + float right; + float bottom; + + SRect(); + SRect(const SRect &r); + SRect(float l, float t, float r, float b); + SRect(SPoint lt, SPoint rb); + + SRect &operator=(const SRect &r); + void Set(float l, float t, float r, float b); + + void PrintToStream() const; + + SPoint LeftTop() const; + SPoint RightBottom() const; + SPoint LeftBottom() const; + SPoint RightTop() const; + + void SetLeftTop(const SPoint p); + void SetRightBottom(const SPoint p); + void SetLeftBottom(const SPoint p); + void SetRightTop(const SPoint p); + + // transformation + void InsetBy(SPoint p); + void InsetBy(float dx, float dy); + void OffsetBy(SPoint p); + void OffsetBy(float dx, float dy); + void OffsetTo(SPoint p); + void OffsetTo(float x, float y); + + // expression transformations + SRect & InsetBySelf(SPoint); + SRect & InsetBySelf(float dx, float dy); + SRect InsetByCopy(SPoint); + SRect InsetByCopy(float dx, float dy); + SRect & OffsetBySelf(SPoint); + SRect & OffsetBySelf(float dx, float dy); + SRect OffsetByCopy(SPoint); + SRect OffsetByCopy(float dx, float dy); + SRect & OffsetToSelf(SPoint); + SRect & OffsetToSelf(float dx, float dy); + SRect OffsetToCopy(SPoint); + SRect OffsetToCopy(float dx, float dy); + + // comparison + bool operator==(SRect r) const; + bool operator!=(SRect r) const; + + // intersection and union + SRect operator&(SRect r) const; + SRect operator|(SRect r) const; + + bool Intersects(SRect r) const; + bool IsValid() const; + float Width() const; + int32 IntegerWidth() const; + float Height() const; + int32 IntegerHeight() const; + bool Contains(SPoint p) const; + bool Contains(SRect r) const; + +#ifdef BE_SUPPORT + BRect Rect(void) { return BRect(left,top,right,bottom); }; +#endif +}; + + +// inline definitions ---------------------------------------------------------- + +inline SPoint SRect::LeftTop() const +{ + return(*((const SPoint*)&left)); +} + +inline SPoint SRect::RightBottom() const +{ + return(*((const SPoint*)&right)); +} + +inline SPoint SRect::LeftBottom() const +{ + return(SPoint(left, bottom)); +} + +inline SPoint SRect::RightTop() const +{ + return(SPoint(right, top)); +} + +inline SRect::SRect() +{ + top = left = 0; + bottom = right = -1; +} + +inline SRect::SRect(float l, float t, float r, float b) +{ + left = l; + top = t; + right = r; + bottom = b; +} + +inline SRect::SRect(const SRect &r) +{ + left = r.left; + top = r.top; + right = r.right; + bottom = r.bottom; +} + +inline SRect::SRect(SPoint leftTop, SPoint rightBottom) +{ + left = leftTop.x; + top = leftTop.y; + right = rightBottom.x; + bottom = rightBottom.y; +} + +inline SRect &SRect::operator=(const SRect& from) +{ + left = from.left; + top = from.top; + right = from.right; + bottom = from.bottom; + return *this; +} + +inline void SRect::Set(float l, float t, float r, float b) +{ + left = l; + top = t; + right = r; + bottom = b; +} + +inline bool SRect::IsValid() const +{ + if (left <= right && top <= bottom) + return true; + else + return false; +} + +inline int32 SRect::IntegerWidth() const +{ + return((int32)ceil(right - left)); +} + +inline float SRect::Width() const +{ + return(right - left); +} + +inline int32 SRect::IntegerHeight() const +{ + return((int32)ceil(bottom - top)); +} + +inline float SRect::Height() const +{ + return(bottom - top); +} + +#endif diff --git a/src/prefs/appearance/defs.h b/src/prefs/appearance/defs.h new file mode 100644 index 0000000000..b5d7204d90 --- /dev/null +++ b/src/prefs/appearance/defs.h @@ -0,0 +1,21 @@ +#ifndef DEFS_H_ +#define DEFS_H_ + +#define SETTINGS_DIR "/boot/home/config/settings/app_server/" +#define DECORATORS_DIR "/boot/home/config/add-ons/decorators/" + +#define APPLY_SETTINGS 'aply' +#define REVERT_SETTINGS 'rvrt' +#define DEFAULT_SETTINGS 'dflt' +#define TRY_SETTINGS 'trys' + +#define ATTRIBUTE_CHOSEN 'atch' +#define UPDATE_COLOR 'upcl' +#define DECORATOR_CHOSEN 'dcch' +#define UPDATE_DECORATOR 'updc' + +#define SET_DECORATOR 'sdec' +#define GET_DECORATOR 'gdec' + +#define SET_UI_COLORS 'suic' +#endif \ No newline at end of file