Author: miguel
Date: 2007-06-12 20:38:35 -0400 (Tue, 12 Jun 2007)
New Revision: 79358
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/runtime.cpp
trunk/moon/src/runtime.h
trunk/moon/src/shape.cpp
trunk/moon/src/shape.h
Log:
i2007-06-12 Miguel de Icaza <[EMAIL PROTECTED]>
* runtime.h (UIElement::inside_object): new routine that should
return true if the given absolute x, y is inside the given object
or not.
(UIElement::handle_motion): new routine that is called when a
motion event happens, it should determine if it can handle the
given event at x, y.
(Surface): new callbacks, these are callbacks that will pass the
notification of the event to managed code.
* runtime.cpp (FrameworkElement): provide a default implementation
for inside object that works for "squares" (things with widths and
heights)
Canvas: need to
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-13 00:34:58 UTC (rev 79357)
+++ trunk/moon/src/ChangeLog 2007-06-13 00:38:35 UTC (rev 79358)
@@ -1,3 +1,16 @@
+2007-06-12 Miguel de Icaza <[EMAIL PROTECTED]>
+
+ * runtime.h (UIElement::inside_object): new routine that should
+ return true if the given absolute x, y is inside the given object
+ or not.
+
+ (UIElement::handle_motion): new routine that is called when a
+ motion event happens, it should determine if it can handle the
+ given event at x, y.
+
+ (Surface): new callbacks, these are callbacks that will pass the
+ notification of the event to managed code.
+
2007-06-12 Jeffrey Stedfast <[EMAIL PROTECTED]>
* ffvideo.cpp: Instead of aborting when SDL_OpenAudio() fails,
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-06-13 00:34:58 UTC (rev 79357)
+++ trunk/moon/src/runtime.cpp 2007-06-13 00:38:35 UTC (rev 79358)
@@ -38,6 +38,10 @@
NameScope *global_NameScope;
+static callback_mouse_event cb_motion, cb_down, cb_up, cb_enter;
+static callback_plain_event cb_got_focus, cb_focus, cb_loaded, cb_mouse_leave;
+static callback_keyboard_event cb_keydown, cb_keyup;
+
void
base_ref (Base *base)
{
@@ -589,6 +593,19 @@
item->SetValue (UIElement::OpacityProperty, Value (opacity));
}
+bool
+UIElement::inside_object (Surface *s, double x, double y)
+{
+ printf ("UIElement derivatives should implement inside object\n");
+}
+
+void
+UIElement::handle_motion (Surface *s, int state, double x, double y)
+{
+ if (inside_object (s, x, y))
+ s->cb_motion (this, state, x, y);
+}
+
UIElement::~UIElement ()
{
printf ("FIXME: We should go through all of the attached properties and
unref them\n");
@@ -598,6 +615,26 @@
{
}
+bool
+FrameworkElement::inside_object (Surface *s, double x, double y)
+{
+ // Quick bounding box check.
+ if (x < x1 || x > x2 || y < y1 || y > y2)
+ return FALSE;
+
+ bool ret = FALSE;
+ double nx = x, ny = y;
+ cairo_save (s->cairo);
+ cairo_set_matrix (s->cairo, &absolute_xform);
+ cairo_rectangle (s->cairo, 0, 0, framework_element_get_width (this),
framework_element_get_height (this));
+ cairo_matrix_transform_point (&absolute_xform, &nx, &ny);
+ if (cairo_in_stroke (s->cairo, nx, ny) || cairo_in_fill (s->cairo, nx,
ny))
+ ret = TRUE;
+
+ cairo_restore (s->cairo);
+ return ret;
+}
+
double
framework_element_get_height (FrameworkElement *framework_element)
{
@@ -805,6 +842,28 @@
}
void
+Canvas::handle_motion (Surface *s, int state, double x, double y)
+{
+ //printf ("is %g %g inside the canvas? %d\n", x, y, inside_object (s,
x, y));
+ //
+ // We need to sync the canvas size with the surface size
+ //if (!inside_object (s, x, y))
+ //return;
+
+ GSList *il;
+ for (il = children->list; il != NULL; il = il->next){
+ UIElement *item = (UIElement *) il->data;
+
+ // Quick bound check:
+ if (x < item->x1 || x > item->x2 || y < item->y1 || y >
item->y2){
+ continue;
+ }
+
+ item->handle_motion (s, state, x, y);
+ }
+}
+
+void
surface_clear (Surface *s, int x, int y, int width, int height)
{
static unsigned char n;
@@ -946,7 +1005,11 @@
{
Surface *s = (Surface *) data;
- printf ("Motion\n");
+ if (!s->cb_motion)
+ return FALSE;
+
+ s->toplevel->handle_motion (s, event->state & (GDK_SHIFT_MASK |
GDK_CONTROL_MASK), event->x, event->y);
+ return TRUE;
}
static gboolean
@@ -1936,3 +1999,23 @@
xaml_init ();
clock_init ();
}
+
+void surface_register_events (Surface *s,
+ callback_mouse_event motion, callback_mouse_event
down, callback_mouse_event up,
+ callback_mouse_event enter,
+ callback_plain_event got_focus,
callback_plain_event lost_focus,
+ callback_plain_event loaded, callback_plain_event
mouse_leave,
+ callback_keyboard_event keydown,
callback_keyboard_event keyup)
+{
+ s->cb_motion = motion;
+ s->cb_down = down;
+ s->cb_up = up;
+ s->cb_enter = enter;
+ s->cb_got_focus = got_focus;
+ s->cb_lost_focus = lost_focus;
+ s->cb_loaded = loaded;
+ s->cb_mouse_leave = mouse_leave;
+ s->cb_keydown = keydown;
+ s->cb_keyup = keyup;
+}
+
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-06-13 00:34:58 UTC (rev 79357)
+++ trunk/moon/src/runtime.h 2007-06-13 00:38:35 UTC (rev 79358)
@@ -641,6 +641,19 @@
return Point (0, 0);
}
+ //
+ // inside_object:
+ // Returns whether the position x, y is inside the object
+ //
+ virtual bool inside_object (Surface *s, double x, double y);
+
+ //
+ // handle_motion:
+ // handles an mouse motion event, and dispatches it to anyone that
+ // might want it
+ //
+ virtual void handle_motion (Surface *s, int state, double x, double y);
+
~UIElement ();
virtual void OnPropertyChanged (DependencyProperty *prop);
@@ -687,6 +700,8 @@
FrameworkElement ();
Value::Kind GetObjectType () { return Value::FRAMEWORKELEMENT; }
+
+ virtual bool inside_object (Surface *s, double x, double y);
};
double framework_element_get_height (FrameworkElement *framework_element);
@@ -730,7 +745,8 @@
virtual void getbounds ();
virtual void update_xform ();
virtual void get_xform_for (UIElement *item, cairo_matrix_t *result);
-
+ virtual void handle_motion (Surface *s, int state, double x, double y);
+
virtual void OnSubPropertyChanged (DependencyProperty *prop,
DependencyProperty *subprop);
static DependencyProperty* TopProperty;
@@ -761,6 +777,9 @@
//
// Surface:
//
+typedef void (*callback_mouse_event) (UIElement *target, int state, double
x, double y);
+typedef void (*callback_plain_event) (UIElement *target);
+typedef void (*callback_keyboard_event) (UIElement *target, int state, int
platformcode, int key);
class Surface {
public:
Surface () : width (0), height (0), buffer (0),
@@ -801,6 +820,11 @@
UIElement *toplevel;
int frames;
+
+ callback_mouse_event cb_motion, cb_down, cb_up, cb_enter;
+ callback_plain_event cb_got_focus, cb_lost_focus, cb_loaded,
cb_mouse_leave;
+ callback_keyboard_event cb_keydown, cb_keyup;
+
};
Surface *surface_new (int width, int height);
@@ -813,6 +837,14 @@
void *surface_get_drawing_area (Surface *s);
+void surface_register_events (Surface *s,
+ callback_mouse_event motion,
callback_mouse_event down, callback_mouse_event up,
+ callback_mouse_event enter,
+ callback_plain_event got_focus,
callback_plain_event lost_focus,
+ callback_plain_event loaded,
callback_plain_event mouse_leave,
+ callback_keyboard_event keydown,
callback_keyboard_event keyup);
+
+
//
// XAML
//
Modified: trunk/moon/src/shape.cpp
===================================================================
--- trunk/moon/src/shape.cpp 2007-06-13 00:34:58 UTC (rev 79357)
+++ trunk/moon/src/shape.cpp 2007-06-13 00:38:35 UTC (rev 79358)
@@ -212,6 +212,25 @@
x_cairo_matrix_transform_bounding_box (&absolute_xform, &x1, &y1, &x2,
&y2);
}
+bool
+Shape::inside_object (Surface *s, double x, double y)
+{
+ bool ret = FALSE;
+
+ cairo_save (s->cairo);
+ DoDraw (s, FALSE);
+
+ double nx = x;
+ double ny = y;
+ cairo_matrix_transform_point (&absolute_xform, &nx, &ny);
+
+ if (cairo_in_stroke (s->cairo, nx, ny) || (CanFill () && cairo_in_fill
(s->cairo, nx, ny)))
+ ret = TRUE;
+
+ cairo_restore (s->cairo);
+ return ret;
+}
+
void
Shape::OnPropertyChanged (DependencyProperty *prop)
{
Modified: trunk/moon/src/shape.h
===================================================================
--- trunk/moon/src/shape.h 2007-06-13 00:34:58 UTC (rev 79357)
+++ trunk/moon/src/shape.h 2007-06-13 00:38:35 UTC (rev 79358)
@@ -48,7 +48,8 @@
//
virtual void render (Surface *s, int x, int y, int width, int height);
virtual void getbounds ();
-
+ virtual bool inside_object (Surface *s, double x, double y);
+
//
// new virtual methods for shapes
//
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches