Skip to content

Commit

Permalink
simple TextButton and some minor addtions to base functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
NotFound committed Dec 1, 2011
1 parent fc276c1 commit 68fdb41
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions GuitorConstants.winxhead
Expand Up @@ -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
{

Expand Down
3 changes: 3 additions & 0 deletions examples/pizarra.winxed
Expand Up @@ -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)
{
Expand Down
51 changes: 51 additions & 0 deletions src/Guitor.winxed
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
3 changes: 3 additions & 0 deletions src/GuitorNci.winxed
Expand Up @@ -456,6 +456,9 @@ function create_function(string funcname)
case "XRaiseWindow":
sig = "vpi";
break;
case "XSetInputFocus":
sig = "vppil";
break;
case "XSetFunction":
sig = "vppi";
break;
Expand Down

0 comments on commit 68fdb41

Please sign in to comment.