[Y-devel] 'simpleconf' Theme
Chris Amshey ychris at amshey.net
Wed Feb 25 04:44:26 GMT 2004
Okay, this patch adds a theme called simpleconf to the build tree. You
will need to re-run autogen.sh & configure; you should be able to
go to modules/themes/simpleconf and do a make && make install to build
just the module.
To actually -use- the theme, you need to change your configuration file to
something like,
...
LoadModule "theme/basic"
LoadModule "theme/simpleconf"
LoadModule "wm/default"
...
And to actually configure it, you need a file called simple.conf (in the
same directory as default.conf), which can set some colors and fonts. I'll
attach an example simple.conf along with the patch.
Enjoy. :)
--Chris
-------------- next part --------------
diff -x '\{arch\}' -urN clean/configure.ac simpleconf/configure.ac
--- clean/configure.ac 2004-02-24 23:28:08.000000000 -0500
+++ simpleconf/configure.ac 2004-02-24 23:17:40.000000000 -0500
@@ -178,6 +178,7 @@
modules/drivers/ipc/tcp/Makefile
modules/themes/Makefile
modules/themes/basic/Makefile
+modules/themes/simpleconf/Makefile
modules/wm/Makefile
modules/wm/default/Makefile
clients/Makefile
diff -x '\{arch\}' -urN clean/modules/themes/Makefile.am simpleconf/modules/themes/Makefile.am
--- clean/modules/themes/Makefile.am 2004-02-24 23:28:09.000000000 -0500
+++ simpleconf/modules/themes/Makefile.am 2004-02-24 23:17:56.000000000 -0500
@@ -1 +1 @@
-SUBDIRS = basic
+SUBDIRS = basic simpleconf
diff -x '\{arch\}' -urN clean/modules/themes/simpleconf/Makefile.am simpleconf/modules/themes/simpleconf/Makefile.am
--- clean/modules/themes/simpleconf/Makefile.am 1969-12-31 19:00:00.000000000 -0500
+++ simpleconf/modules/themes/simpleconf/Makefile.am 2004-02-24 23:15:05.000000000 -0500
@@ -0,0 +1,10 @@
+include $(top_srcdir)/build-misc/common.mk
+include $(top_srcdir)/modules/module.mk
+
+themelibdir = ${pkglibdir}/theme
+themelib_LTLIBRARIES = simpleconf.la
+
+noinst_HEADERS = window.h draw.h
+
+simpleconf_la_SOURCES = simpleconf.c window.c draw.c
+simpleconf_la_LDFLAGS = -module
diff -x '\{arch\}' -urN clean/modules/themes/simpleconf/draw.c simpleconf/modules/themes/simpleconf/draw.c
--- clean/modules/themes/simpleconf/draw.c 1969-12-31 19:00:00.000000000 -0500
+++ simpleconf/modules/themes/simpleconf/draw.c 2004-02-24 23:15:57.000000000 -0500
@@ -0,0 +1,211 @@
+
+#include <Y/modules/module_interface.h>
+#include <Y/modules/theme_interface.h>
+
+#include <Y/util/yutil.h>
+
+#include <Y/buffer/painter.h>
+#include <Y/util/rectangle.h>
+#include <Y/object/class.h>
+#include <Y/object/object.h>
+#include <Y/text/font.h>
+#include <Y/util/log.h>
+
+#include "simpleconf.h"
+#include "window.h"
+#include "draw.h"
+static unsigned int bgcolour = 0x40000000;
+static unsigned int textcolour = 0xFF000000;
+static unsigned int highlightcolour = 0x80FFFFFF;
+static unsigned int shadowcolour = 0x80000000;
+
+static int simpleconfDrawWidget_Button(struct Painter *painter, struct Widget *widget);
+
+void simpleconfSetBackgroundColour(unsigned int newcolour)
+{
+ bgcolour = newcolour;
+}
+
+void simpleconfSetHighlightColour(unsigned int newcolour)
+{
+ highlightcolour = newcolour;
+}
+
+void simpleconfSetShadowColour(unsigned int newcolour)
+{
+ shadowcolour = newcolour;
+}
+
+void simpleconfSetTextColour(unsigned int newcolour)
+{
+ textcolour = newcolour;
+}
+
+static int
+simpleconfDrawWidget_Label(struct Painter *painter, struct Widget *widget)
+{
+ int offset, width, ascender, descender;
+ struct Font *font;
+ const char *text =
+ objectGetPropertyAsString (widgetToObject (widget), "text");
+ const char *alignment =
+ objectGetPropertyAsString (widgetToObject (widget), "alignment");
+ struct Rectangle *rect = widgetGetRectangle(widget);
+ enum WidgetState state = widgetGetState(widget);
+
+ int xp, yp;
+
+ painterSaveState (painter);
+
+ painterSetPenColour (painter, textcolour);
+
+ font = simpleconfGetDefaultFont ();
+
+ fontGetMetrics (font, &ascender, &descender, NULL);
+ fontMeasureString (font, text, &offset, &width, NULL);
+
+ yp = (rect->h - ascender - descender ) / 2 + ascender;
+ if (alignment && strcasecmp (alignment, "right") == 0)
+ xp = (rect->w - width);
+ else if (alignment && strcasecmp (alignment, "center") == 0)
+ xp = (rect->w - width + offset) / 2 - offset;
+ else
+ xp = - offset;
+
+ fontRenderString (font, painter, text, xp, yp);
+
+ painterRestoreState (painter);
+
+ rectangleDestroy(rect);
+
+ return 1;
+}
+
+
+static int
+simpleconfDrawWidget_CheckBox(struct Painter *painter, struct Widget *widget)
+{
+ struct Font *font;
+ int offset, ascender, descender;
+ const char *text =
+ objectGetPropertyAsString (widgetToObject (widget), "text");
+ struct Rectangle *rect = widgetGetRectangle(widget);
+ enum WidgetState state = widgetGetState(widget);
+
+ painterSaveState (painter);
+
+ painterSetPenColour (painter, textcolour);
+ font = simpleconfGetDefaultFont ();
+ fontGetMetrics (font, &ascender, &descender, NULL);
+ fontMeasureString (font, text, &offset, NULL, NULL);
+ fontRenderString (font, painter, text, 20 - offset,
+ (rect -> h - ascender - descender) / 2 + ascender);
+
+ simpleconfDrawButtonPane (painter, 0, (rect->h - 16) / 2,
+ 16, 16, state);
+ if (objectGetPropertyAsInteger (widgetToObject (widget), "checked"))
+ {
+ int yp = (rect->h - 16) / 2;
+ painterDrawLine (painter, 3, yp + 7, 3, 6);
+ painterDrawLine (painter, 6, yp + 13, 6, -12);
+ }
+
+ painterRestoreState (painter);
+
+ rectangleDestroy(rect);
+
+ return 1;
+}
+
+
+int
+simpleconfDrawWidget (struct Painter *painter, struct Widget *widget)
+{
+ /* get the widget name */
+ const char *widget_name = classGetName(objectClass(widgetToObject(widget)));
+
+ /* if we recognize it, draw it, else return 0 */
+ if(!strcmp(widget_name, "Button")) {
+ return simpleconfDrawWidget_Button(painter, widget);
+ } else if(!strcmp(widget_name, "CheckBox")) {
+ return simpleconfDrawWidget_CheckBox(painter, widget);
+ } else if(!strcmp(widget_name, "Label")) {
+ return simpleconfDrawWidget_Label(painter, widget);
+ } else {
+ return 0;
+ }
+}
+
+static int
+simpleconfDrawWidget_Button(struct Painter *painter, struct Widget *widget)
+{
+ struct Font *font;
+ int offset, width, ascender, descender;
+ const char *text =
+ objectGetPropertyAsString (widgetToObject (widget), "text");
+ struct Rectangle *rect = widgetGetRectangle(widget);
+ enum WidgetState state = widgetGetState(widget);
+
+ painterSaveState (painter);
+
+ simpleconfDrawButtonPane (painter, 0, 0, rect->w, rect->h, state);
+
+ painterSetPenColour (painter, textcolour);
+ font = simpleconfGetDefaultFont ();
+ fontGetMetrics (font, &ascender, &descender, NULL);
+ fontMeasureString (font, text, &offset, &width, NULL);
+ fontRenderString (font, painter, text,
+ (rect -> w - width + offset) / 2 - offset,
+ (rect -> h - ascender - descender) / 2 + ascender);
+
+ painterRestoreState (painter);
+
+ rectangleDestroy(rect);
+
+ return 1;
+
+}
+
+void
+simpleconfDrawButtonPane (struct Painter *painter, int x, int y, int w, int h,
+ enum WidgetState state)
+{
+ painterSaveState (painter);
+ painterSetBlendMode (painter, COLOUR_BLEND_SOURCE_OVER);
+ painterSetPenColour (painter, bgcolour);
+
+ if (state == WIDGET_STATE_HOVER
+ || state == WIDGET_STATE_PRESSED
+ || state == WIDGET_STATE_CANCELLING)
+ painterSetFillColour (painter, bgcolour);
+ else
+ painterSetFillColour (painter, bgcolour);
+
+ painterDrawRectangle (painter, x, y, w, h);
+
+ if (state == WIDGET_STATE_PRESSED)
+ painterSetPenColour (painter, shadowcolour);
+ else
+ painterSetPenColour (painter, highlightcolour);
+
+ painterDrawHLine (painter, x+1, y+1, w-2);
+
+ painterDrawVLine (painter, x+1, y+2, h-2);
+
+ if (state == WIDGET_STATE_PRESSED)
+ painterSetPenColour (painter, highlightcolour);
+ else
+ painterSetPenColour (painter, shadowcolour);
+
+ painterDrawHLine (painter, x+2, y+h-2, w-3);
+ painterDrawVLine (painter, x+w-2, y+1, h-3);
+ painterRestoreState (painter);
+ if (state == WIDGET_STATE_PRESSED)
+ painterTranslate (painter, 1, 1);
+}
+
+void
+simpleconfDrawBackgroundPane (struct Painter *painter, int x, int y, int w, int h)
+{
+}
+
diff -x '\{arch\}' -urN clean/modules/themes/simpleconf/draw.h simpleconf/modules/themes/simpleconf/draw.h
--- clean/modules/themes/simpleconf/draw.h 1969-12-31 19:00:00.000000000 -0500
+++ simpleconf/modules/themes/simpleconf/draw.h 2004-02-24 23:16:11.000000000 -0500
@@ -0,0 +1,13 @@
+#ifndef Y_THEMES_CHRIS_DRAW_H
+#define Y_THEMES_CHRIS_DRAW_H
+
+#include <Y/buffer/painter.h>
+#include <Y/widget/widget.h>
+
+void simpleconfDrawBackgroundPane (struct Painter *, int, int, int, int);
+void simpleconfDrawButtonPane (struct Painter *, int, int, int, int,
+ enum WidgetState);
+int simpleconfDrawWidget (struct Painter *, struct Widget *);
+
+#endif
+
diff -x '\{arch\}' -urN clean/modules/themes/simpleconf/simpleconf.c simpleconf/modules/themes/simpleconf/simpleconf.c
--- clean/modules/themes/simpleconf/simpleconf.c 1969-12-31 19:00:00.000000000 -0500
+++ simpleconf/modules/themes/simpleconf/simpleconf.c 2004-02-24 23:16:21.000000000 -0500
@@ -0,0 +1,220 @@
+#include <Y/modules/module_interface.h>
+#include <Y/modules/theme_interface.h>
+
+#include <Y/util/yutil.h>
+#include <Y/text/font.h>
+
+#include "window.h"
+#include "draw.h"
+#include "simpleconf.h"
+
+static struct Font *simpleconfDefaultFont = NULL;
+static char *simpleconfDefaultFontName = NULL;
+static char *simpleconfDefaultFontStyle = NULL;
+static const char simpleconfFilename[] = "/simple.conf";
+static char simpleconfModuleName[] = "Simple Configurable Theme";
+
+static void simpleconfParseLine(char *line);
+
+/* simpleconfGetDefaultFont:
+ Return the configured font if we have one, or the default font if
+ if we don't.
+ */
+struct Font *
+simpleconfGetDefaultFont ()
+{
+ if (simpleconfDefaultFont == NULL)
+ {
+ if(simpleconfDefaultFontName != NULL && simpleconfDefaultFontStyle != NULL)
+ simpleconfDefaultFont = fontCreate (simpleconfDefaultFontName,
+ simpleconfDefaultFontStyle,
+ 12);
+ if (simpleconfDefaultFont == NULL)
+ simpleconfDefaultFont = fontCreate ("Bitstream Vera Serif", "Roman", 12);
+ }
+ return simpleconfDefaultFont;
+}
+
+static struct Theme simpleconfTheme =
+{
+ name: "Simple Configurable Theme",
+
+ drawBackgroundPane: simpleconfDrawBackgroundPane,
+ drawButtonPane: simpleconfDrawButtonPane,
+ drawWidget: simpleconfDrawWidget,
+ getDefaultFont: simpleconfGetDefaultFont,
+
+ windowInit: simpleconfWindowInit,
+ windowPaint: simpleconfWindowPaint,
+ windowGetRegion: simpleconfWindowGetRegion,
+ windowPointerMotion: simpleconfWindowPointerMotion,
+ windowPointerButton: simpleconfWindowPointerButton,
+ windowReconfigure: simpleconfWindowReconfigure,
+ windowResize: simpleconfWindowResize
+
+};
+
+/*
+ simpleconfParseLine:
+
+ A rather simple, blunt and extension-unfriendly way to parse
+ config file lines of the form 'option = value' where
+ '#' is the comment character,
+ whitespace is a token separator, but otherwise discarded,
+ and value you may be quoted if it should include whitespace.
+ie,
+ foo = bar
+ foo = "bar"
+ foo=bar # set foo to bar
+ are all equivalent.
+
+ We then selfishly act on recognized options instead of returning our
+ parsed values like a nice modular function ought.
+*/
+
+void simpleconfParseLine(char *line)
+{
+ char optionstr[512];
+ char valuestr[512];
+ unsigned int value;
+ unsigned char endchar;
+ int pos = 0;
+
+ while(isspace(*line))
+ line++;
+
+ while(pos < 511 && *line != '=' && !isspace(*line))
+ {
+ optionstr[pos++] = *line++;
+ }
+
+ if(isspace(*line))
+ while(isspace(*line))
+ line++;
+
+ if(*line == '=')
+ line++;
+ else
+ return;
+
+ while(isspace(*line))
+ line++;
+
+ if(*line == '"')
+ {
+ endchar = '"';
+ *line++;
+ }
+ else
+ endchar = ' ';
+
+ optionstr[pos] = '\0';
+ pos = 0;
+
+ while(pos < 511 && *line != '\0' && *line != '#' && *line != endchar)
+ {
+ valuestr[pos++] = *line++;
+ }
+
+ valuestr[pos] = 0;
+
+ if(!strncmp(optionstr,"background",512))
+ {
+ value = strtoul(valuestr, NULL, 16);
+ simpleconfWindowSetBaseColor(value);
+ simpleconfSetBackgroundColour(value);
+ }
+ if(!strncmp(optionstr,"colour",512))
+ {
+ value = strtoul(valuestr, NULL, 16);
+ simpleconfSetBackgroundColour(value);
+ }
+ if(!strncmp(optionstr,"text",512))
+ {
+ value = strtoul(valuestr, NULL, 16);
+ simpleconfSetTextColour(value);
+ }
+ if(!strncmp(optionstr,"highlight",512))
+ {
+ value = strtoul(valuestr, NULL, 16);
+ simpleconfSetHighlightColour(value);
+ }
+ if(!strncmp(optionstr,"shadow",512))
+ {
+ value = strtoul(valuestr, NULL, 16);
+ simpleconfSetShadowColour(value);
+ }
+ if(!strncmp(optionstr,"font",512))
+ {
+ simpleconfDefaultFontName = ymalloc(strlen(valuestr));
+ strcpy(simpleconfDefaultFontName,valuestr);
+ }
+ if(!strncmp(optionstr,"fontstyle",512))
+ {
+ simpleconfDefaultFontStyle = ymalloc(strlen(valuestr));
+ strcpy(simpleconfDefaultFontStyle,valuestr);
+ }
+ if(!strncmp(optionstr,"titlefont",512))
+ {
+ char *temp;
+
+ temp = ystrdup(valuestr);
+ simpleconfSetTitleFontFamily(temp);
+ }
+ if(!strncmp(optionstr,"titlestyle",512))
+ {
+ char *temp;
+
+ temp = ystrdup(valuestr);
+ simpleconfSetTitleFontStyle(temp);
+ }
+ if(!strncmp(optionstr,"titlecolour",512))
+ {
+ value = strtoul(valuestr, NULL, 16);
+ simpleconfSetTitleColour(value);
+ }
+}
+
+/*
+ initialise:
+ Try to open the configuration file, and if we succeed, parse it.
+ Currently, we look in the globally known 'yConfigDir' for a file
+ named 'simple.conf'
+*/
+int
+initialise (struct Module *module, int argc, const char **argv)
+{
+ FILE * fp;
+ int dirlen = strlen(yConfigDir);
+ int filelen = strlen(simpleconfFilename);
+ char conffile[dirlen + filelen + 1];
+ char linebuf[1024];
+ module -> name = simpleconfModuleName;
+ module -> data = &simpleconfTheme;
+
+ strcpy(conffile, yConfigDir);
+ strcat(conffile, simpleconfFilename);
+
+ if((fp = fopen(conffile, "r")) != NULL)
+ {
+ while(fgets(linebuf, 1023, fp) != NULL)
+ {
+ if(linebuf[0] != '#')
+ simpleconfParseLine(linebuf);
+ }
+ }
+
+ simpleconfDefaultFont = NULL;
+
+ themeAdd (&simpleconfTheme);
+ return 0;
+}
+
+int
+finalise (struct Module *module)
+{
+ fontDestroy (simpleconfDefaultFont);
+ themeRemove (&simpleconfTheme);
+ return 0;
+}
+
diff -x '\{arch\}' -urN clean/modules/themes/simpleconf/simpleconf.h simpleconf/modules/themes/simpleconf/simpleconf.h
--- clean/modules/themes/simpleconf/simpleconf.h 1969-12-31 19:00:00.000000000 -0500
+++ simpleconf/modules/themes/simpleconf/simpleconf.h 2004-02-24 23:14:50.000000000 -0500
@@ -0,0 +1,17 @@
+#ifndef THEME_SIMPLECONF_H
+#define THEME_SIMPLECONF_H
+#include <string.h>
+#include <ctype.h>
+void simpleconfSetBackgroundColour(unsigned int newcolour);
+void simpleconfSetTextColour(unsigned int newcolour);
+void simpleconfSetShadowColour(unsigned int newcolour);
+void simpleconfSetHighlightColour(unsigned int newcolour);
+
+void simpleconfWindowSetBaseColor(unsigned int newcolour);
+void simpleconfSetTitleColour(unsigned int newcolour);
+void simpleconfSetTitleFontFamily(char *family);
+void simpleconfSetTitleFontStyle(char *style);
+
+
+struct Font *simpleconfGetDefaultFont(void);
+#endif
diff -x '\{arch\}' -urN clean/modules/themes/simpleconf/window.c simpleconf/modules/themes/simpleconf/window.c
--- clean/modules/themes/simpleconf/window.c 1969-12-31 19:00:00.000000000 -0500
+++ simpleconf/modules/themes/simpleconf/window.c 2004-02-24 23:16:37.000000000 -0500
@@ -0,0 +1,415 @@
+
+#include <Y/widget/window.h>
+#include <Y/widget/widget.h>
+#include <Y/object/object.h>
+#include <Y/screen/screen.h>
+#include <Y/text/font.h>
+#include <Y/modules/windowmanager.h>
+#include <Y/modules/theme.h>
+
+#include "simpleconf.h"
+#include "window.h"
+#include "draw.h"
+
+static unsigned int basecolour = 0x0000A000;
+static struct Font *titlefont = NULL;
+static char *titlefontfamily = NULL;
+static char *titlefontstyle = NULL;
+static unsigned int titlecolour = 0xFF4040F0;
+
+static uint32_t windowICON[] =
+{
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x6080FF80, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8080FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0x8080FF80, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x2080FF80, 0x8080FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0x8080FF80, 0x2080FF80, 0x00000000,
+ 0x00000000, 0x5080FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0x5080FF80, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x8080FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0xFF80FF80, 0x8080FF80, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0xFFFF8080, 0x80FF8080, 0x00000000, 0x00000000, 0xC080FF80, 0xFF80FF80, 0xC080FF80, 0x00000000, 0x00000000, 0x808080FF, 0xFF8080FF, 0x00000000,
+ 0x00000000, 0xFFFF8080, 0xFFFF8080, 0xFFFF8080, 0x80FF8080, 0x00000000, 0x00000000, 0x00000000, 0x808080FF, 0xFF8080FF, 0xFF8080FF, 0xFF8080FF, 0x00000000,
+ 0x00000000, 0xFFFF8080, 0xFFFF8080, 0xFFFF8080, 0xFFFF8080, 0xC0FF8080, 0x00000000, 0xC08080FF, 0xFF8080FF, 0xFF8080FF, 0xFF8080FF, 0xFF8080FF, 0x00000000,
+ 0x00000000, 0xFFFF8080, 0xFFFF8080, 0xFFFF8080, 0xFFFF8080, 0xFFFF8080, 0x00000000, 0xFF8080FF, 0xFF8080FF, 0xFF8080FF, 0xFF8080FF, 0xFF8080FF, 0x00000000,
+ 0x00000000, 0xFFFF8080, 0xFFFF8080, 0xFFFF8080, 0xFFFF8080, 0xFFFF8080, 0x00000000, 0xFF8080FF, 0xFF8080FF, 0xFF8080FF, 0xFF8080FF, 0xFF8080FF, 0x00000000,
+ 0x00000000, 0x20FF8080, 0xC0FF8080, 0xFFFF8080, 0xFFFF8080, 0xFFFF8080, 0x00000000, 0xFF8080FF, 0xFF8080FF, 0xFF8080FF, 0xC08080FF, 0x208080FF, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x40FF8080, 0xC0FF8080, 0xFFFF8080, 0x00000000, 0xFF8080FF, 0xC08080FF, 0x408080FF, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x20FF8080, 0x00000000, 0x208080FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
+};
+
+enum WindowRegion
+{
+WINDOW_REGION_NOTHING,
+WINDOW_REGION_MOVE,
+WINDOW_REGION_MAXIMISE, WINDOW_REGION_RESTORE, WINDOW_REGION_CLOSE,
+WINDOW_REGION_RESIZE_NW, WINDOW_REGION_RESIZE_N, WINDOW_REGION_RESIZE_NE,
+WINDOW_REGION_RESIZE_W, WINDOW_REGION_RESIZE_E,
+WINDOW_REGION_RESIZE_SW, WINDOW_REGION_RESIZE_S, WINDOW_REGION_RESIZE_SE,
+WINDOW_REGION_CHILD
+};
+
+void
+simpleconfWindowInit (struct Window *window)
+{
+}
+void simpleconfSetTitleColour(unsigned int newcolour)
+{
+ titlecolour = newcolour;
+}
+void simpleconfSetTitleFontFamily(char *family)
+{
+ titlefontfamily = family;
+}
+void simpleconfSetTitleFontStyle(char *style)
+{
+ titlefontstyle = style;
+}
+
+static struct Font *simpleconfGetTitleFont(void)
+{
+ if(titlefont == NULL)
+ {
+ if(titlefontfamily != NULL && titlefontstyle != NULL)
+ titlefont = fontCreate(titlefontfamily, titlefontstyle, 12);
+ if(titlefont == NULL)
+ {
+ titlefont = fontCreate ("Impact", "Regular", 12);
+ }
+ }
+ return titlefont;
+}
+
+static void
+paintTitleBar (struct Window *window, struct Painter *painter,
+ int x, int y, int w)
+{
+ /* title bar */
+ const char *title = objectGetPropertyAsString (windowToObject (window), "title");
+ struct Font *font = simpleconfGetTitleFont();
+ int ascender;
+ int titlex = x + 22;
+ int titley = y + 3;
+ fontGetMetrics (font, &ascender, NULL, NULL);
+ titley += ascender;
+ painterSetFillColour (painter, titlecolour & 0x66666666);
+ if (wmSelectedWindow () == window)
+ painterSetFillColour (painter, titlecolour);
+ painterDrawRectangle (painter, x, x, w, 19);
+ painterSetBlendMode (painter, COLOUR_BLEND_SOURCE_OVER);
+ painterDrawRGBAData (painter, windowICON, x + 4, x + 3, 13, 13, 13);
+ painterSaveState (painter);
+ {
+ struct Rectangle clipRect = { x + 18, y, w - 47, 19 };
+ painterClipTo (painter, &clipRect);
+ }
+ painterSetPenColour (painter, 0x60000000);
+ fontRenderString (font, painter, title, titlex, titley);
+ painterSetPenColour (painter, 0x30000000);
+ fontRenderString (font, painter, title, titlex-1, titley);
+ fontRenderString (font, painter, title, titlex+1, titley);
+ fontRenderString (font, painter, title, titlex, titley-1);
+ fontRenderString (font, painter, title, titlex, titley+1);
+ painterSetPenColour (painter, 0xFFFFFFFF);
+ fontRenderString (font, painter, title, titlex-1, titley-1);
+ painterRestoreState (painter);
+
+ painterSetPenColour (painter, 0xFFFFFFFF);
+ painterDrawLine (painter, x + w - 12, y + 5, 7, 7);
+ painterDrawLine (painter, x + w - 6, y + 5, -7, 7);
+ if (windowGetSizeState (window) == WINDOW_SIZE_NORMAL)
+ {
+ painterDrawLine (painter, x + w - 22, y + 5, -4, 7);
+ painterDrawLine (painter, x + w - 22, y + 5, 4, 7);
+ }
+ else
+ {
+ painterDrawLine (painter, x + w - 22, y + 12, -4, -7);
+ painterDrawLine (painter, x + w - 22, y + 12, 4, -7);
+ }
+
+}
+void simpleconfWindowSetBaseColor(unsigned int newcolour)
+{
+ basecolour = newcolour;
+}
+void
+simpleconfWindowPaint (struct Window *window, struct Painter *painter)
+{
+ struct Rectangle *rect = widgetGetRectangle (windowToWidget (window));
+ struct Widget *child = windowGetChild (window);
+ int selected = (wmSelectedWindow () == window);
+ int bgcolour = (selected ? 0xFF000000 : 0xC0000000 ) | (basecolour & 0x00FFFFFF);
+ int setbgcolour = objectIsPropertySet (windowToObject (window), "background")
+ ? objectGetPropertyAsInteger (windowToObject (window), "background")
+ : bgcolour;
+
+ if (windowGetSizeState (window) == WINDOW_SIZE_NORMAL)
+ {
+ /* resizing border */
+ painterSetBlendMode (painter, COLOUR_BLEND_SOURCE);
+ painterSetFillColour (painter, bgcolour);
+ painterClearRectangle (painter, 0, 0, rect -> w, 5);
+ painterClearRectangle (painter, rect -> w - 5, 0, 5, rect -> h);
+ painterClearRectangle (painter, 0, rect -> h - 5, rect -> w, 5);
+ painterClearRectangle (painter, 0, 0, 5, rect -> h);
+ painterSetPenColour (painter, 0xFF000000);
+ painterDrawHLine (painter, 0, 0, rect -> w);
+ painterDrawHLine (painter, 0, rect -> h - 1, rect -> w);
+ painterDrawVLine (painter, 0, 0, rect -> h);
+ painterDrawVLine (painter, rect -> w - 1, 0, rect -> h);
+
+ /* content area */
+ painterSetFillColour (painter, setbgcolour);
+ painterClearRectangle (painter, 5, 23, rect -> w - 10, rect -> h - 28);
+
+ paintTitleBar (window, painter, 5, 5, rect -> w - 10);
+ }
+ else
+ {
+ painterSetFillColour (painter, setbgcolour);
+ painterClearRectangle (painter, 0, 20, rect -> w, rect -> h - 20);
+ paintTitleBar (window, painter, 0, 0, rect -> w);
+ }
+
+ rectangleDestroy (rect);
+
+ /* paint child */
+ if (child != NULL)
+ {
+ struct Rectangle *childRect = widgetGetRectangle (child);
+ painterSaveState (painter);
+ painterEnter (painter, childRect);
+ if (!painterFullyClipped (painter))
+ {
+ widgetPaint (child, painter);
+ }
+ painterRestoreState (painter);
+ rectangleDestroy (childRect);
+ }
+}
+
+int
+simpleconfWindowGetRegion (struct Window *window, int x, int y)
+{
+ struct Rectangle *rect = widgetGetRectangle (windowToWidget (window));
+ int region = WINDOW_REGION_NOTHING;
+ int wx = 0, wy = 0, ww = rect -> w, wh = rect -> h;
+ switch (windowGetSizeState (window))
+ {
+ case WINDOW_SIZE_NORMAL:
+ wx = 5;
+ wy = 5;
+ ww = rect -> w - 10;
+ wh = rect -> h - 10;
+ break;
+ case WINDOW_SIZE_MAXIMISE:
+ wx = 0;
+ wy = 0;
+ ww = rect -> w;
+ wh = rect -> h;
+ }
+
+ if (y > wy && y <= wy + 19)
+ {
+ if (x > wx + wx + 19 && x < wx + ww - 27)
+ region = WINDOW_REGION_MOVE;
+ if (x >= wx + ww - 27 && x < wx + ww - 14)
+ {
+ if (windowGetSizeState (window) == WINDOW_SIZE_NORMAL)
+ region = WINDOW_REGION_MAXIMISE;
+ else
+ region = WINDOW_REGION_RESTORE;
+ }
+ if (x >= wx + ww - 14 && x <= wx + ww)
+ region = WINDOW_REGION_CLOSE;
+ }
+ if (x > wx && x < wx + ww && y > wy + 19 && y < wy + wh)
+ region = WINDOW_REGION_CHILD;
+
+ if (windowGetSizeState (window) == WINDOW_SIZE_NORMAL)
+ {
+ if (y >= 0 && y <= 5)
+ {
+ if (x >= 0 && x <= 24)
+ region = WINDOW_REGION_RESIZE_NW;
+ if (x > 24 && x <= rect -> w - 24)
+ region = WINDOW_REGION_RESIZE_N;
+ if (x > rect -> w - 24 && x <= rect -> w)
+ region = WINDOW_REGION_RESIZE_NE;
+ }
+ if (x >= 0 && x <= 5)
+ {
+ if (y >= 0 && y <= 24)
+ region = WINDOW_REGION_RESIZE_NW;
+ if (y > 24 && y <= rect -> h - 24)
+ region = WINDOW_REGION_RESIZE_W;
+ if (y > rect -> h - 24 && y <= rect -> h)
+ region = WINDOW_REGION_RESIZE_SW;
+ }
+ if (y >= rect -> h - 5 && y <= rect -> h)
+ {
+ if (x >= 0 && x <= 24)
+ region = WINDOW_REGION_RESIZE_SW;
+ if (x > 24 && x <= rect -> w - 24)
+ region = WINDOW_REGION_RESIZE_S;
+ if (x > rect -> w - 24 && x <= rect -> w)
+ region = WINDOW_REGION_RESIZE_SE;
+ }
+ if (x >= rect -> w - 5 && x <= rect -> w)
+ {
+ if (y >= 0 && y <= 24)
+ region = WINDOW_REGION_RESIZE_NE;
+ if (y > 24 && y <= rect -> h - 24)
+ region = WINDOW_REGION_RESIZE_E;
+ if (y > rect -> h - 24 && y <= rect -> h)
+ region = WINDOW_REGION_RESIZE_SE;
+ }
+ }
+ rectangleDestroy (rect);
+ return region;
+}
+
+int
+simpleconfWindowPointerMotion (struct Window *w, int x, int y, int dx, int dy)
+{
+ int r = simpleconfWindowGetRegion (w, x, y);
+ switch (r)
+ {
+ case WINDOW_REGION_CHILD:
+ return widgetPointerMotion (windowGetChild (w), x - 5, y - 24, dx, dy);
+ }
+ return 0;
+}
+
+int
+simpleconfWindowPointerButton (struct Window *w, int x, int y, int b, int pressed)
+{
+ int r = simpleconfWindowGetRegion (w, x, y);
+ if (b == 0 && pressed == 1)
+ {
+ switch (r)
+ {
+ case WINDOW_REGION_MOVE:
+ windowStartReshape (w, x, y, WINDOW_RESHAPE_MOVE); break;
+ case WINDOW_REGION_MAXIMISE:
+ wmMaximiseWindow (w); break;
+ case WINDOW_REGION_RESTORE:
+ wmRestoreWindow (w); break;
+ case WINDOW_REGION_CLOSE:
+ windowRequestClose (w); break;
+ case WINDOW_REGION_RESIZE_NW:
+ windowStartReshape (w, x, y, WINDOW_RESHAPE_RESIZE_NW); break;
+ case WINDOW_REGION_RESIZE_N:
+ windowStartReshape (w, x, y, WINDOW_RESHAPE_RESIZE_N); break;
+ case WINDOW_REGION_RESIZE_NE:
+ windowStartReshape (w, x, y, WINDOW_RESHAPE_RESIZE_NE); break;
+ case WINDOW_REGION_RESIZE_W:
+ windowStartReshape (w, x, y, WINDOW_RESHAPE_RESIZE_W); break;
+ case WINDOW_REGION_RESIZE_E:
+ windowStartReshape (w, x, y, WINDOW_RESHAPE_RESIZE_E); break;
+ case WINDOW_REGION_RESIZE_SW:
+ windowStartReshape (w, x, y, WINDOW_RESHAPE_RESIZE_SW); break;
+ case WINDOW_REGION_RESIZE_S:
+ windowStartReshape (w, x, y, WINDOW_RESHAPE_RESIZE_S); break;
+ case WINDOW_REGION_RESIZE_SE:
+ windowStartReshape (w, x, y, WINDOW_RESHAPE_RESIZE_SE); break;
+ }
+ }
+ if (b == 0 && pressed == 0)
+ {
+ windowStopReshape (w);
+ return 1;
+ }
+ if (r == WINDOW_REGION_CHILD)
+ return widgetPointerButton (windowGetChild (w), x - 5, y - 24, b, pressed);
+ return 1;
+}
+
+struct Rectangle *
+simpleconfWindowChildRectangle (struct Window *w)
+{
+ struct Rectangle *wr = widgetGetRectangle (windowToWidget (w));
+ struct Rectangle *cr = rectangleCreate (5, 24, wr -> w - 10, wr -> h - 29);
+ rectangleDestroy (wr);
+ return cr;
+}
+
+void
+simpleconfWindowPointerMove (struct Window *window, int x, int y, int dx, int dy)
+{
+
+}
+
+void
+simpleconfWindowReconfigure (struct Window *window,
+ int *minWidth_p, int *minHeight_p,
+ int *reqWidth_p, int *reqHeight_p,
+ int *maxWidth_p, int *maxHeight_p)
+{
+ struct Widget *child = windowGetChild (window);
+ *minWidth_p = 64;
+ *minHeight_p = 48;
+ *maxWidth_p = -1;
+ *maxHeight_p = -1;
+
+ if (child != NULL)
+ {
+ int childMinWidth, childMinHeight;
+ int childReqWidth, childReqHeight;
+ int childMaxWidth, childMaxHeight;
+ widgetGetConstraints (child, &childMinWidth, &childMinHeight,
+ &childReqWidth, &childReqHeight,
+ &childMaxWidth, &childMaxHeight);
+ if (childMinWidth > 54)
+ *minWidth_p = childMinWidth + 10;
+ if (childMinHeight > 19)
+ *minHeight_p = childMinHeight + 29;
+ if (childMaxWidth > 0)
+ *maxWidth_p = childMaxWidth + 10;
+ if (childMaxHeight > 0)
+ *maxHeight_p = childMaxHeight + 29;
+
+ if (*reqWidth_p < 0 && childReqWidth > 54)
+ *reqWidth_p = childReqWidth + 10;
+ if (*reqHeight_p < 0 && childReqHeight > 19)
+ *reqHeight_p = childReqHeight + 29;
+ }
+
+ if (*maxWidth_p > 0)
+ {
+ if (*maxWidth_p < *minWidth_p)
+ *maxWidth_p = *minWidth_p;
+ if (*reqWidth_p > *maxWidth_p)
+ *reqWidth_p = *maxWidth_p;
+ }
+ if (*maxHeight_p > 0)
+ {
+ if (*maxHeight_p < *minHeight_p)
+ *maxHeight_p = *minHeight_p;
+ if (*reqHeight_p > *maxHeight_p)
+ *reqHeight_p = *maxHeight_p;
+ }
+ if (*reqWidth_p < *minWidth_p)
+ *reqWidth_p = *minWidth_p;
+ if (*reqHeight_p < *minHeight_p)
+ *reqHeight_p = *minHeight_p;
+}
+
+void
+simpleconfWindowResize (struct Window *window)
+{
+ struct Widget *child = windowGetChild (window);
+ if (child != NULL)
+ {
+ int w, h;
+ widgetGetSize (windowToWidget (window), &w, &h);
+ switch (windowGetSizeState (window))
+ {
+ case WINDOW_SIZE_NORMAL:
+ widgetMove (child, 5, 24);
+ widgetResize (child, w - 10, h - 29);
+ break;
+ case WINDOW_SIZE_MAXIMISE:
+ widgetMove (child, 0, 19);
+ widgetResize (child, w, h - 19);
+ }
+ }
+}
+
diff -x '\{arch\}' -urN clean/modules/themes/simpleconf/window.h simpleconf/modules/themes/simpleconf/window.h
--- clean/modules/themes/simpleconf/window.h 1969-12-31 19:00:00.000000000 -0500
+++ simpleconf/modules/themes/simpleconf/window.h 2004-02-24 23:16:47.000000000 -0500
@@ -0,0 +1,20 @@
+#ifndef Y_THEMES_CHRIS_WINDOW_H
+#define Y_THEMES_CHRIS_WINDOW_H
+
+#include <Y/widget/window.h>
+#include <Y/buffer/painter.h>
+
+void simpleconfWindowInit (struct Window *);
+void simpleconfWindowPaint (struct Window *, struct Painter *);
+int simpleconfWindowGetRegion (struct Window *, int, int);
+int simpleconfWindowPointerMotion (struct Window *, int, int, int, int);
+int simpleconfWindowPointerButton (struct Window *, int, int, int, int);
+void simpleconfWindowReconfigure (struct Window *, int *, int *, int *, int *,
+ int *, int *);
+void simpleconfWindowResize (struct Window *);
+struct Rectangle *simpleconfWindowChildRectangle (struct Window *w);
+void simpleconfWindowPointerMove (struct Window *window, int x, int y, int dx, int dy);
+
+#endif
+
+
-------------- next part --------------
# This is a simpleconf theme file.
font = "Verdana"
fontstyle = "Regular"
titlefont = "Comic Sans MS"
titlestyle = "Regular"
titlecolour = 0xFF3838A0
background=0x00B0A0C0
colour=0x30F00000
text=0xFF400000
shadow=0x80000020
highlight=0x80E0E0FF
More information about the Y-devel mailing list
2026 © www.Y-Windows.Org - All Rights Reserved