Permalink
Browse files

simple TextButton and some minor addtions to base functionality

  • Loading branch information...
NotFound committed Dec 1, 2011
1 parent fc276c1 commit 68fdb41d483b553edabf71801db7ee342989713e
Showing with 65 additions and 0 deletions.
  1. +8 −0 GuitorConstants.winxhead
  2. +3 −0 examples/pizarra.winxed
  3. +51 −0 src/Guitor.winxed
  4. +3 −0 src/GuitorNci.winxed
View
@@ -36,6 +36,14 @@ const int
ClipByChildren = 0,
IncludeInferiors = 1;
+const int CurrentTime = 0;
+
+// Focus revert type
+const int
+ RevertToNone = 0,
+ RevertToPointerRoot = 1,
+ RevertToParent = 2;
+
namespace Events
{
View
@@ -251,6 +251,9 @@ class Pizarra : TopLevelWindow
self.board.Map();
new ColorSelector(self, 1, 1);
new ToolSelector(self, 1, 86);
+ var b = new TextButton(self, 0, 160, 0, 0, "quit", null);
+ b.OnClick += function (event) { self.Destroy(); };
+ b.Map();
}
function onConfigure(event)
{
View
@@ -889,6 +889,11 @@ class Window : Drawable
getfun("XClearArea")(self.display.xdisplay, self.xdrawable,
x, y, width, height, exposures);
}
+ function SetInputFocus(int revert_to)
+ {
+ getfun("XSetInputFocus")(self.display.xdisplay. self.xdrawable,
+ revert_to, CurrentTime);
+ }
function MoveWindow(int x, int y)
{
getfun("XMoveWindow")(self.display.xdisplay, self.xdrawable, x, y);
@@ -1099,6 +1104,52 @@ class ChildWindow : ListenerWindow
}
}
+//**************************************************************
+
+// A barely functional text button to be used in examples and tests
+
+class TextButton : ChildWindow
+{
+ var text;
+ var font;
+ var width;
+ var height;
+ var OnClick;
+ function TextButton(parent, int x, int y, int width, int height, string text, font)
+ {
+ __DEBUG__ && cry(__FUNCTION__);
+ if (font == null)
+ font = parent.display.CreateFont("courier-10");
+ if (height == 0)
+ height = font.getHeight();
+ if (width == 0) {
+ width = font.getTextWidth(parent.display, text);
+ width += 8;
+ }
+ self.ChildWindow(parent, x, y, width, height);
+ self.width = width;
+ self.height = height;
+ self.text = text;
+ self.font = font;
+ self.OnClick = new EventHandler(self, ButtonPressMask | ButtonReleaseMask);
+ self.OnExpose += function (event)
+ {
+ int width = self.width;
+ int height = self.height;
+ self.DrawRectangle(0, 0, width - 1, height - 1);
+ var font = self.font;
+ string text = self.text;
+ int twidth = self.font.getTextWidth(self.display, text);
+ int tx = (width - twidth) / 2;
+ self.DrawImageString(tx, font.getAscent(), text);
+ };
+ self.OnButtonRelease += function (event)
+ {
+ self.OnClick.handle(event);
+ };
+ }
+}
+
} // namespace Guitor
// End.
View
@@ -456,6 +456,9 @@ function create_function(string funcname)
case "XRaiseWindow":
sig = "vpi";
break;
+ case "XSetInputFocus":
+ sig = "vppil";
+ break;
case "XSetFunction":
sig = "vppi";
break;

0 comments on commit 68fdb41

Please sign in to comment.