Server now loads (and uses) the GUI system colors and can save 'em, too

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3862 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2003-07-05 17:40:42 +00:00
parent 16593e0a04
commit 491a7680eb
6 changed files with 182 additions and 16 deletions

View File

@ -98,10 +98,11 @@ AppServer::AppServer(void)
DEFAULT_FIXED_FONT_STYLE,DEFAULT_FIXED_FONT_SIZE);
fontserver->Unlock();
// Get the GUI colors here. For now, we'll just set the defaults
SetDefaultGUIColors(&gui_colorset);
// TODO: load the GUI colors here and set the global set to the values contained therein
// Load the GUI colors here and set the global set to the values contained therein. If this
// is not possible, set colors to the defaults
if(!LoadGUIColors(&gui_colorset))
SetDefaultGUIColors(&gui_colorset);
// Set up the Desktop
InitDesktop();

View File

@ -26,7 +26,13 @@
//
//------------------------------------------------------------------------------
#include <stdio.h>
#include <Message.h>
#include <File.h>
#include <Entry.h>
#include <Directory.h>
#include <String.h>
#include "ColorSet.h"
#include "ServerConfig.h"
//! Constructor which does nothing
ColorSet::ColorSet(void)
@ -126,7 +132,7 @@ void ColorSet::SetColors(const ColorSet &cs)
}
//! Prints all color set elements to stdout
void ColorSet::PrintToStream(void)
void ColorSet::PrintToStream(void) const
{
printf("panel_background "); panel_background.PrintToStream();
printf("panel_text "); panel_text.PrintToStream();
@ -165,7 +171,7 @@ void ColorSet::PrintToStream(void)
/*!
\brief Assigns the default system colors to the passed ColorSet object
\param The ColorSet object to set to defaults
\param set The ColorSet object to set to defaults
*/
void SetDefaultGUIColors(ColorSet *set)
{
@ -200,3 +206,160 @@ printf("Initializing color settings to defaults\n");
set->inactive_window_tab.SetColor(232,232,232);
set->inactive_window_tab_text.SetColor(80,80,80);
}
/*!
\brief Loads the saved system colors into a ColorSet
\param set the set to receive the system colors
\return true if successful, false if not
Note that this function automatically looks for the file named in
COLOR_SETTINGS_NAME in the folder SERVER_SETTINGS_DIR as defined in
ServerConfig.h
*/
bool LoadGUIColors(ColorSet *set)
{
BString path(SERVER_SETTINGS_DIR);
path+=COLOR_SETTINGS_NAME;
BFile file(path.String(),B_READ_ONLY);
if(file.InitCheck()!=B_OK)
return false;
BMessage msg;
if(msg.Unflatten(&file)!=B_OK)
return false;
rgb_color *col;
ssize_t size;
if(msg.FindData("Panel Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->panel_background=*col;
if(msg.FindData("Panel Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->panel_text=*col;
if(msg.FindData("Document Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->document_background=*col;
if(msg.FindData("Document Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->document_text=*col;
if(msg.FindData("Control Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->control_background=*col;
if(msg.FindData("Control Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->control_text=*col;
if(msg.FindData("Control Highlight",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->control_highlight=*col;
if(msg.FindData("Control Border",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->control_border=*col;
if(msg.FindData("Tooltip Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->tooltip_background=*col;
if(msg.FindData("Tooltip Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->tooltip_text=*col;
if(msg.FindData("Menu Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->menu_background=*col;
if(msg.FindData("Selected Menu Item Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->menu_selected_background=*col;
if(msg.FindData("Keyboard Navigation Base",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->keyboard_navigation_base=*col;
if(msg.FindData("Keyboard Navigation Pulse",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->keyboard_navigation_pulse=*col;
if(msg.FindData("Menu Item Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->menu_text=*col;
if(msg.FindData("Selected Menu Item Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->menu_selected_text=*col;
if(msg.FindData("Selected Menu Item Border",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->menu_selected_border=*col;
if(msg.FindData("Success",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->success=*col;
if(msg.FindData("Failure",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->failure=*col;
if(msg.FindData("Shine",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->shine=*col;
if(msg.FindData("Shadow",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->shadow=*col;
if(msg.FindData("Window Tab",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->window_tab=*col;
if(msg.FindData("Window Tab Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->window_tab_text=*col;
if(msg.FindData("Inactive Window Tab",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->inactive_window_tab=*col;
if(msg.FindData("Inactive Window Tab Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
set->inactive_window_tab_text=*col;
return true;
}
/*!
\brief Saves the saved system colors into a flattened BMessage
\param set ColorSet containing the colors to save
Note that this function automatically looks for the file named in
COLOR_SETTINGS_NAME in the folder SERVER_SETTINGS_DIR as defined in
ServerConfig.h. If SERVER_SETTINGS_DIR does not exist, it is created, and the same for
the color settings file.
*/
void SaveGUIColors(const ColorSet &set)
{
BEntry *entry=new BEntry(SERVER_SETTINGS_DIR);
if(!entry->Exists())
create_directory(SERVER_SETTINGS_DIR,0777);
delete entry;
BString path(SERVER_SETTINGS_DIR);
path+=COLOR_SETTINGS_NAME;
BFile file(path.String(), B_READ_WRITE | B_ERASE_FILE | B_CREATE_FILE);
BMessage msg;
rgb_color col;
col=set.panel_background.GetColor32();
msg.AddData("Panel Background",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.panel_text.GetColor32();
msg.AddData("Panel Text",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.document_background.GetColor32();
msg.AddData("Document Background",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.document_text.GetColor32();
msg.AddData("Document Text",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.control_background.GetColor32();
msg.AddData("Control Background",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.control_text.GetColor32();
msg.AddData("Control Text",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.control_highlight.GetColor32();
msg.AddData("Control Highlight",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.control_border.GetColor32();
msg.AddData("Control Border",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.tooltip_background.GetColor32();
msg.AddData("Tooltip Background",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.tooltip_text.GetColor32();
msg.AddData("Tooltip Text",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.menu_background.GetColor32();
msg.AddData("Menu Background",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.menu_selected_background.GetColor32();
msg.AddData("Selected Menu Item Background",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.keyboard_navigation_base.GetColor32();
msg.AddData("Keyboard Navigation Base",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.keyboard_navigation_pulse.GetColor32();
msg.AddData("Keyboard Navigation Pulse",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.menu_text.GetColor32();
msg.AddData("Menu Item Text",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.menu_selected_text.GetColor32();
msg.AddData("Selected Menu Item Text",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.menu_selected_border.GetColor32();
msg.AddData("Selected Menu Item Border",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.success.GetColor32();
msg.AddData("Success",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.failure.GetColor32();
msg.AddData("Failure",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.shine.GetColor32();
msg.AddData("Shine",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.shadow.GetColor32();
msg.AddData("Shadow",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.window_tab.GetColor32();
msg.AddData("Window Tab",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.window_tab_text.GetColor32();
msg.AddData("Window Tab Text",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.inactive_window_tab.GetColor32();
msg.AddData("Inactive Window Tab",(type_code)'RGBC',&col,sizeof(rgb_color));
col=set.inactive_window_tab_text.GetColor32();
msg.AddData("Inactive Window Tab Text",(type_code)'RGBC',&col,sizeof(rgb_color));
msg.Flatten(&file);
}

View File

@ -42,7 +42,7 @@ public:
ColorSet(const ColorSet &cs);
ColorSet & operator=(const ColorSet &cs);
void SetColors(const ColorSet &cs);
void PrintToStream(void);
void PrintToStream(void) const;
RGBColor panel_background,
panel_text,
@ -81,5 +81,7 @@ public:
};
void SetDefaultGUIColors(ColorSet *set);
bool LoadGUIColors(ColorSet *set);
void SaveGUIColors(const ColorSet &set);
#endif

View File

@ -107,7 +107,7 @@ RGBColor::RGBColor(void)
\brief Returns the color as the closest 8-bit color in the palette
\return The palette index for the current color
*/
uint8 RGBColor::GetColor8(void)
uint8 RGBColor::GetColor8(void) const
{
return color8;
}
@ -116,7 +116,7 @@ uint8 RGBColor::GetColor8(void)
\brief Returns the color as the closest 16-bit color
\return 16-bit value of the current color, including alpha
*/
uint16 RGBColor::GetColor16(void)
uint16 RGBColor::GetColor16(void) const
{
return color16;
}
@ -125,7 +125,7 @@ uint16 RGBColor::GetColor16(void)
\brief Returns the color as a 32-bit color
\return current color, including alpha
*/
rgb_color RGBColor::GetColor32(void)
rgb_color RGBColor::GetColor32(void) const
{
return color32;
}
@ -240,7 +240,7 @@ RGBColor & RGBColor::operator=(const rgb_color &col)
If the position passed to this function is invalid, the starting
color will be returned.
*/
RGBColor RGBColor::MakeBlendColor(RGBColor color, float position)
RGBColor RGBColor::MakeBlendColor(const RGBColor &color, const float &position)
{
rgb_color col=color32;
rgb_color col2=color.color32;

View File

@ -51,9 +51,9 @@ public:
void PrintToStream(void) const;
uint8 GetColor8(void);
uint16 GetColor16(void);
rgb_color GetColor32(void);
uint8 GetColor8(void) const;
uint16 GetColor16(void) const;
rgb_color GetColor32(void) const;
void SetColor(uint8 r, uint8 g, uint8 b, uint8 a=255);
void SetColor(int r, int g, int b, int a=255);
@ -62,7 +62,7 @@ public:
void SetColor(const rgb_color &color);
void SetColor(const RGBColor &col);
RGBColor MakeBlendColor(RGBColor color, float position);
RGBColor MakeBlendColor(const RGBColor &color, const float &position);
RGBColor & operator=(const RGBColor &col);
RGBColor & operator=(const rgb_color &col);

View File

@ -26,7 +26,7 @@
#define HWDRIVER 3
// Display driver to be used by the server.
#define DISPLAYDRIVER SCREENDRIVER
#define DISPLAYDRIVER VIEWDRIVER
// Uncomment this if the DisplayDriver should only rely on drawing functions implemented
// in software even though hardware-accelerated functions are available
@ -43,7 +43,7 @@
// regular application. When running as the app_server, this is not used.
#define SERVER_SIGNATURE "application/x-vnd.obe-OBAppServer"
// Directory for all app_server-related settings.
// Directory for all app_server-related settings. Must include ending slash.
#define SERVER_SETTINGS_DIR "/boot/home/config/settings/app_server/"
// Flattened list of usable fonts maintained by the server. The file is a