[Commit] twin ChangeLog, 1.22, 1.23 Makefile.am, 1.11, 1.12 twin.h, 1.17, 1.18 twin_button.c, NONE, 1.1 twin_hello.c, 1.1, 1.2 twin_hello.h, NONE, 1.1 twin_label.c, 1.1, 1.2 twin_widget.c, 1.1, 1.2 twin_window.c, 1.4, 1.5 twinint.h, 1.14, 1.15 xtwin.c, 1.21, 1.22

Keith Packard commit at keithp.com
Tue Oct 26 12:56:22 PDT 2004


Committed by: keithp

Update of /local/src/CVS/twin
In directory home.keithp.com:/tmp/cvs-serv9281

Modified Files:
	ChangeLog Makefile.am twin.h twin_hello.c twin_label.c 
	twin_widget.c twin_window.c twinint.h xtwin.c 
Added Files:
	twin_button.c twin_hello.h 
Log Message:
2004-10-26  Keith Packard  <keithp at keithp.com>

	* Makefile.am:
	* twin_button.c: (_twin_button_paint),
	(_twin_button_set_label_offset), (_twin_button_dispatch),
	(_twin_button_init), (twin_button_create):
	Add button widget
	
	* twin.h:
	* twinint.h:
	Grab button down inside client area.
	Add button widget
	
	* twin_hello.c: (twin_hello_start):
	* twin_hello.h:
	Test button widget
	
	* twin_label.c: (_twin_label_paint), (_twin_label_init),
	(twin_label_create):
	Permit subclassing; add offset to make text shift in button
	
	* twin_widget.c: (_twin_widget_contains):
	Add _twin_widget_contains to test inclusion
	
	* twin_window.c: (twin_window_create), (twin_window_dispatch):
	Grab button down inside client area 
	
	* xtwin.c: (main):
	Make hello window larger


Index: ChangeLog
===================================================================
RCS file: /local/src/CVS/twin/ChangeLog,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- ChangeLog	26 Oct 2004 06:15:42 -0000	1.22
+++ ChangeLog	26 Oct 2004 19:56:18 -0000	1.23
@@ -1,3 +1,33 @@
+2004-10-26  Keith Packard  <keithp at keithp.com>
+
+	* Makefile.am:
+	* twin_button.c: (_twin_button_paint),
+	(_twin_button_set_label_offset), (_twin_button_dispatch),
+	(_twin_button_init), (twin_button_create):
+	Add button widget
+	
+	* twin.h:
+	* twinint.h:
+	Grab button down inside client area.
+	Add button widget
+	
+	* twin_hello.c: (twin_hello_start):
+	* twin_hello.h:
+	Test button widget
+	
+	* twin_label.c: (_twin_label_paint), (_twin_label_init),
+	(twin_label_create):
+	Permit subclassing; add offset to make text shift in button
+	
+	* twin_widget.c: (_twin_widget_contains):
+	Add _twin_widget_contains to test inclusion
+	
+	* twin_window.c: (twin_window_create), (twin_window_dispatch):
+	Grab button down inside client area 
+	
+	* xtwin.c: (main):
+	Make hello window larger
+
 2004-10-25  Keith Packard  <keithp at keithp.com>
 
 	* Makefile.am:

Index: Makefile.am
===================================================================
RCS file: /local/src/CVS/twin/Makefile.am,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- Makefile.am	26 Oct 2004 06:15:42 -0000	1.11
+++ Makefile.am	26 Oct 2004 19:56:18 -0000	1.12
@@ -16,6 +16,7 @@
 xtwin_SOURCES = \
 	twin.h \
 	twin_box.c \
+	twin_button.c \
 	twin_convolve.c \
 	twin_dispatch.c \
 	twin_draw.c \

Index: twin.h
===================================================================
RCS file: /local/src/CVS/twin/twin.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- twin.h	26 Oct 2004 06:15:42 -0000	1.17
+++ twin.h	26 Oct 2004 19:56:18 -0000	1.18
@@ -312,6 +312,8 @@
     twin_window_style_t	style;
     twin_rect_t		client;
     twin_rect_t		damage;
+    twin_bool_t		client_grab;
+    twin_bool_t		want_focus;
     void		*client_data;
     char		*name;
     
@@ -364,12 +366,11 @@
 typedef struct _twin_widget twin_widget_t;
 typedef struct _twin_box    twin_box_t;
 
-typedef enum _twin_widget_kind_t {
-    TwinWidgetToplevel,
-    TwinWidgetBox,
-    TwinWidgetLabel,
-    TwinWidgetGlue,
-} twin_widget_kind_t;
+#define _twin_widget_width(w)	(((twin_widget_t *)(w))->extents.right - \
+				 ((twin_widget_t *)(w))->extents.left)
+
+#define _twin_widget_height(w)	(((twin_widget_t *)(w))->extents.bottom - \
+				 ((twin_widget_t *)(w))->extents.top)
 
 typedef enum _twin_dispatch_result {
     TwinDispatchNone,
@@ -417,11 +418,18 @@
     twin_argb32_t	foreground;
     twin_fixed_t	font_size;
     twin_style_t	font_style;
+    twin_point_t	offset;
 } twin_label_t;
 
-typedef struct _twin_glue {
-    twin_widget_t	widget;
-} twin_glue_t;
+typedef void	(*twin_callback_t) (twin_widget_t *widget, void *closure);
+
+typedef struct _twin_button {
+    twin_label_t	label;
+    twin_bool_t		pressed;
+    twin_bool_t		active;
+    twin_callback_t	callback;
+    void		*closure;
+} twin_button_t;
 
 /*
  * twin_box.c
@@ -432,6 +440,17 @@
 		 twin_layout_t	layout);
 
 /*
+ * twin_button.c
+ */
+
+twin_button_t *
+twin_button_create (twin_box_t	    *parent,
+		   const char	    *value,
+		   twin_argb32_t    foreground,
+		   twin_fixed_t	    font_size,
+		   twin_style_t	    font_style);
+
+/*
  * twin_convolve.c
  */
 void

--- NEW FILE: twin_button.c ---
(This appears to be a binary file; contents omitted.)

Index: twin_hello.c
===================================================================
RCS file: /local/src/CVS/twin/twin_hello.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- twin_hello.c	26 Oct 2004 06:15:42 -0000	1.1
+++ twin_hello.c	26 Oct 2004 19:56:19 -0000	1.2
@@ -22,7 +22,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <twin.h>
+#include "twin_hello.h"
 #include <time.h>
 
 static twin_time_t
@@ -58,8 +58,15 @@
 						 0xff008000,
 						 twin_int_to_fixed (12),
 						 TWIN_TEXT_OBLIQUE);
+    twin_button_t   *button = twin_button_create (&top->box,
+						  "Button",
+						  0xff800000,
+						  twin_int_to_fixed (18),
+						  TWIN_TEXT_BOLD);
     twin_widget_set (&labela->widget, 0xc0c0c0c0);
+    (void) widget;
     twin_widget_set (&labelb->widget, 0xc0c0c0c0);
+    twin_widget_set (&button->label.widget, 0xc0808080);
     twin_toplevel_show (top);
     twin_set_timeout (_twin_hello_timeout, 1000, labelb);
 }

--- NEW FILE: twin_hello.h ---
(This appears to be a binary file; contents omitted.)

Index: twin_label.c
===================================================================
RCS file: /local/src/CVS/twin/twin_label.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- twin_label.c	26 Oct 2004 06:15:42 -0000	1.1
+++ twin_label.c	26 Oct 2004 19:56:19 -0000	1.2
@@ -49,8 +49,8 @@
 {
     twin_path_t		*path = twin_path_create ();
     twin_text_metrics_t	m;
-    twin_coord_t	w = label->widget.extents.right - label->widget.extents.left;
-    twin_coord_t	h = label->widget.extents.bottom - label->widget.extents.top;
+    twin_coord_t	w = _twin_widget_width(label);
+    twin_coord_t	h = _twin_widget_height(label);
 
     if (path)
     {
@@ -60,8 +60,8 @@
 	twin_path_set_font_size (path, label->font_size);
 	twin_path_set_font_style (path, label->font_style);
 	twin_text_metrics_utf8 (path, label->label, &m);
-	twin_path_move (path, (wf - m.width) / 2,
-			(hf - (m.font_ascent + m.font_descent)) / 2 + m.font_ascent);
+	twin_path_move (path, (wf - m.width) / 2 + label->offset.x,
+			(hf - (m.ascent + m.descent)) / 2 + m.ascent + label->offset.y);
 
 	twin_path_utf8 (path, label->label);
 	twin_paint_path (label->widget.window->pixmap, label->foreground, path);
@@ -114,17 +114,20 @@
 }
 
 void
-_twin_label_init (twin_label_t	*label,
-		  twin_box_t	*parent,
-		  const char	*value,
-		  twin_argb32_t	foreground,
-		  twin_fixed_t	font_size,
-		  twin_style_t	font_style)
+_twin_label_init (twin_label_t		*label,
+		  twin_box_t		*parent,
+		  const char		*value,
+		  twin_argb32_t		foreground,
+		  twin_fixed_t		font_size,
+		  twin_style_t		font_style,
+		  twin_dispatch_proc_t	dispatch)
 {
     static const twin_rect_t	empty = { 0, 0, 0, 0 };
     _twin_widget_init (&label->widget, parent, 0, 
-		       empty, 1, 1, _twin_label_dispatch);
+		       empty, 1, 1, dispatch);
     label->label = NULL;
+    label->offset.x = 0;
+    label->offset.y = 0;
     twin_label_set (label, value, foreground, font_size, font_style);
 }
 
@@ -140,7 +143,8 @@
 
     if (!label)
 	return 0;
-    _twin_label_init (label, parent, value, foreground, font_size, font_style);
+    _twin_label_init (label, parent, value, foreground, 
+		      font_size, font_style, _twin_label_dispatch);
     return label;
 }
 

Index: twin_widget.c
===================================================================
RCS file: /local/src/CVS/twin/twin_widget.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- twin_widget.c	26 Oct 2004 06:15:42 -0000	1.1
+++ twin_widget.c	26 Oct 2004 19:56:19 -0000	1.2
@@ -113,6 +113,15 @@
     _twin_toplevel_queue_layout (widget);
 }
 
+twin_bool_t
+_twin_widget_contains (twin_widget_t	*widget,
+		       twin_coord_t	x,
+		       twin_coord_t	y)
+{
+    return (0 <= x && x < _twin_widget_width(widget) && 
+	    0 <= y && y < _twin_widget_height(widget)); 
+}
+
 twin_widget_t *
 twin_widget_create (twin_box_t	    *parent,
 		    twin_argb32_t   background,

Index: twin_window.c
===================================================================
RCS file: /local/src/CVS/twin/twin_window.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- twin_window.c	26 Oct 2004 06:15:42 -0000	1.4
+++ twin_window.c	26 Oct 2004 19:56:19 -0000	1.5
@@ -77,6 +77,8 @@
     twin_pixmap_move (window->pixmap, x, y);
     window->damage.left = window->damage.right = 0;
     window->damage.top = window->damage.bottom = 0;
+    window->client_grab = TWIN_FALSE;
+    window->want_focus = TWIN_FALSE;
     window->client_data = 0;
     window->name = 0;
     
@@ -337,19 +339,43 @@
     
     switch (ev.kind) {
     case TwinEventButtonDown:
-	if (ev.u.pointer.x < window->client.left ||
-	    window->client.right <= ev.u.pointer.x ||
-	    ev.u.pointer.y < window->client.top ||
-	    window->client.bottom <= ev.u.pointer.y)
+	if (window->client.left <= ev.u.pointer.x &&
+	    ev.u.pointer.x < window->client.right &&
+	    window->client.top  <= ev.u.pointer.y &&
+	    ev.u.pointer.y < window->client.bottom)
 	{
-	    delegate = TWIN_FALSE;
-	    break;
+	    delegate = TWIN_TRUE;
+	    window->client_grab = TWIN_TRUE;
+	    ev.u.pointer.x -= window->client.left;
+	    ev.u.pointer.y -= window->client.top;
 	}
-	/* fall through... */
+	else
+	    delegate = TWIN_FALSE;
+	break;
     case TwinEventButtonUp:
+	if (window->client_grab)
+	{
+	    delegate = TWIN_TRUE;
+	    window->client_grab = TWIN_FALSE;
+	    ev.u.pointer.x -= window->client.left;
+	    ev.u.pointer.y -= window->client.top;
+	}
+	else
+	    delegate = TWIN_FALSE;
+	break;
     case TwinEventMotion:
-	ev.u.pointer.x -= window->client.left;
-	ev.u.pointer.y -= window->client.top;
+	if (window->client_grab ||
+	    (window->client.left <= ev.u.pointer.x &&
+	     ev.u.pointer.x < window->client.right &&
+	     window->client.top  <= ev.u.pointer.y &&
+	     ev.u.pointer.y < window->client.bottom))
+	{
+	    delegate = TWIN_TRUE;
+	    ev.u.pointer.x -= window->client.left;
+	    ev.u.pointer.y -= window->client.top;
+	}
+	else
+	    delegate = TWIN_FALSE;
 	break;
     default:
 	break;

Index: twinint.h
===================================================================
RCS file: /local/src/CVS/twin/twinint.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- twinint.h	26 Oct 2004 06:15:42 -0000	1.14
+++ twinint.h	26 Oct 2004 19:56:19 -0000	1.15
@@ -479,13 +479,19 @@
 void
 _twin_widget_queue_layout (twin_widget_t    *widget);
 
+twin_bool_t
+_twin_widget_contains (twin_widget_t	*widget,
+		       twin_coord_t	x,
+		       twin_coord_t	y);
+
 void
-_twin_label_init (twin_label_t	*label,
-		  twin_box_t	*parent,
-		  const char	*value,
-		  twin_argb32_t	foreground,
-		  twin_fixed_t	font_size,
-		  twin_style_t	font_style);
+_twin_label_init (twin_label_t		*label,
+		  twin_box_t		*parent,
+		  const char		*value,
+		  twin_argb32_t		foreground,
+		  twin_fixed_t		font_size,
+		  twin_style_t		font_style,
+		  twin_dispatch_proc_t	dispatch);
 
 twin_dispatch_result_t
 _twin_label_dispatch (twin_widget_t *widget, twin_event_t *event);
@@ -505,4 +511,16 @@
 void
 _twin_toplevel_queue_layout (twin_widget_t *widget);
 
+twin_dispatch_result_t
+_twin_button_dispatch (twin_widget_t *widget, twin_event_t *event);
+
+void
+_twin_button_init (twin_button_t	*button,
+		   twin_box_t		*parent,
+		   const char		*value,
+		   twin_argb32_t	foreground,
+		   twin_fixed_t		font_size,
+		   twin_style_t		font_style,
+		   twin_dispatch_proc_t	dispatch);
+
 #endif /* _TWININT_H_ */

Index: xtwin.c
===================================================================
RCS file: /local/src/CVS/twin/xtwin.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- xtwin.c	26 Oct 2004 06:15:42 -0000	1.21
+++ xtwin.c	26 Oct 2004 19:56:19 -0000	1.22
@@ -32,6 +32,7 @@
 #include <twin_clock.h>
 #include <twin_text.h>
 #include <twin_demo.h>
+#include <twin_hello.h>
 
 #define WIDTH	512
 #define HEIGHT	512
@@ -50,7 +51,7 @@
 		     0, 0, 300, 300);
 #endif
     twin_hello_start (x11->screen, "Hello, World",
-		      0, 0, 100, 100);
+		      0, 0, 200, 200);
     twin_dispatch ();
     return 0;
 }




More information about the Commit mailing list