Permalink
Browse files

improve color handling and add constants for line style

  • Loading branch information...
1 parent 56f27f0 commit 1cef5d4a5af804ae490d2a7cff569faf7341e7e2 @NotFound committed Nov 29, 2011
Showing with 99 additions and 25 deletions.
  1. +26 −18 GuitorConstants.winxhead
  2. +20 −0 examples/boxes.winxed
  3. +52 −7 src/Guitor.winxed
  4. +1 −0 src/GuitorNci.winxed
View
@@ -6,29 +6,37 @@
namespace Guitor
{
+// Line styles
+const int
+ LineSolid = 0,
+ LineOnOffDash = 1,
+ LineDoubleDash = 2;
+
namespace Events
{
// Event selection masks
-const int KeyPressMask = 0x00000001;
-const int KeyReleaseMask = 0x00000002;
-const int ButtonPressMask = 0x00000004;
-const int ButtonReleaseMask = 0x00000008;
-const int EnterWindowMask = 0x00000010;
-const int LeaveWindowMask = 0x00000020;
-const int PointerMotionMask = 0x00000040;
-const int ExposureMask = 0x00008000;
-const int StructureNotifyMask = 0x00020000;
+const int
+ KeyPressMask = 0x00000001,
+ KeyReleaseMask = 0x00000002,
+ ButtonPressMask = 0x00000004,
+ ButtonReleaseMask = 0x00000008,
+ EnterWindowMask = 0x00000010,
+ LeaveWindowMask = 0x00000020,
+ PointerMotionMask = 0x00000040,
+ ExposureMask = 0x00008000,
+ StructureNotifyMask = 0x00020000;
// Event types
-const int KeyPress = 2;
-const int KeyRelease = 3;
-const int ButtonPress = 4;
-const int ButtonRelease = 5;
-const int MotionNotify = 6;
-const int Expose = 12;
-const int DestroyNotify = 17;
-const int ConfigureNotify = 22;
-const int ClientMessage = 33;
+const int
+ KeyPress = 2,
+ KeyRelease = 3,
+ ButtonPress = 4,
+ ButtonRelease = 5,
+ MotionNotify = 6,
+ Expose = 12,
+ DestroyNotify = 17,
+ ConfigureNotify = 22,
+ ClientMessage = 33;
}
View
@@ -24,6 +24,7 @@ class Boxes : TopLevelWindow
var x1;
var y1;
var pressed;
+ var colors;
var numcolor;
function Boxes(controller)
{
@@ -38,6 +39,19 @@ class Boxes : TopLevelWindow
self.width = 600;
self.height = 400;
self.TopLevelWindow(controller, "Boxes", 0, 0, 600, 400);
+ var display = self.display;
+ self.colors = [
+ display.ParseColor("yellow"),
+ display.ParseColor("red"),
+ display.ParseColor("blue"),
+ display.ParseColor("light steel blue"),
+ display.ParseColor("orange"),
+ display.ParseColor("green"),
+ display.ParseColor("maroon"),
+ display.ParseColor("aquamarine"),
+ display.ParseColor("coral"),
+ display.ParseColor("violet")
+ ];
self.OnConfigure += function (event) { self.onConfigure(event); };
self.OnExpose += function (event) { self.onExpose(event); };
@@ -189,6 +203,7 @@ class Boxes : TopLevelWindow
if (width == 0 || height == 0)
return;
var boxlist = self.boxlist;
+/*
string color;
switch (self.numcolor) {
case 0: color = "yellow"; break;
@@ -204,6 +219,11 @@ class Boxes : TopLevelWindow
}
var box = new Box(self, x, y, width, height,
{ "background_color" : self.display.ParseColor(color) } );
+*/
+ var color = self.colors[self.numcolor];
+ var box = new Box(self, x, y, width, height,
+ { "background_color" : color } );
+
box.Map();
int active = elements(boxlist);
push(boxlist, box);
View
@@ -214,10 +214,8 @@ class Display
int status = fn(xdisplay, colormap, str_to_cstring(spec), xcolor);
if (status) {
status = getfun("XAllocColor")(xdisplay, colormap, xcolor);
- if (status) {
- int pixel = xcolorview[xcolor, 0];
- return pixel;
- }
+ if (status)
+ return new Color(xcolor);
}
return null;
}
@@ -248,6 +246,20 @@ class Display
}
}
+class Color
+{
+ var xcolor;
+ function Color(xcolor)
+ {
+ self.xcolor = xcolor;
+ }
+ function pixel()
+ {
+ var xcolorview = getxcolorview();
+ return int(xcolorview[self.xcolor, 0]);
+ }
+}
+
//**********************************************************************
function DisplayName()
@@ -440,8 +452,29 @@ class GraphicContext
function SetForeground(string spec)
{
- int pixel = self.display.ParseColor(spec);
- getfun("XSetForeground")(self.display.xdisplay, self.xgc, pixel);
+ var color = self.display.ParseColor(spec);
+ getfun("XSetForeground")(self.display.xdisplay, self.xgc, color.pixel());
+ }
+ function SetForeground [multi("_", "String")] (spec)
+ {
+ self.SetForeground(string(spec));
+ }
+ function SetForeground(var color)
+ {
+ getfun("XSetForeground")(self.display.xdisplay, self.xgc, color.pixel());
+ }
+ function SetBackground(string spec)
+ {
+ var color = self.display.ParseColor(spec);
+ getfun("XSetBackground")(self.display.xdisplay, self.xgc, color.pixel());
+ }
+ function SetBackground [multi("_", "String")] (spec)
+ {
+ self.SetBackground(string(spec));
+ }
+ function SetBackground(var color)
+ {
+ getfun("XSetBackground")(self.display.xdisplay, self.xgc, color.pixel());
}
function SetFunction(display, int func)
{
@@ -528,6 +561,18 @@ class Drawable
{
self.owngc().SetForeground(spec);
}
+ function SetForeground(var color)
+ {
+ self.owngc().SetForeground(color);
+ }
+ function SetBackground(string spec)
+ {
+ self.owngc().SetBackground(spec);
+ }
+ function SetBackground(var color)
+ {
+ self.owngc().SetBackground(color);
+ }
function DrawPoint(int x, int y)
{
self.getgc().DrawPoint(self.display, self, x, y);
@@ -794,7 +839,7 @@ class ChildWindow : ListenerWindow
int background = display.WhitePixel(0);
if (style != null) {
if (exists style["background_color"])
- background = style["background_color"];
+ background = style["background_color"].pixel();
}
self.xdrawable = display.CreateSimpleChildWindow(parent,
x, y, width, height, border_width, border_color, background);
View
@@ -330,6 +330,7 @@ function create_function(string funcname)
sig = "ppipi";
break;
case "XSetForeground":
+ case "XSetBackground":
sig = "vppi";
break;
case "XMapWindow":

0 comments on commit 1cef5d4

Please sign in to comment.