Author: spouliot
Date: 2007-10-11 16:45:31 -0400 (Thu, 11 Oct 2007)
New Revision: 87357
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/panel.cpp
trunk/moon/src/panel.h
trunk/moon/src/stylus.cpp
trunk/moon/src/stylus.h
Log:
2007-10-11 Sebastien Pouliot <[EMAIL PROTECTED]>
* panel.cpp|h: Split Render into Render and RenderChildren, so
the later can be overriden in InkPresenter.
* stylus.cpp|h: A quick (see FIXME) implementation to render
ink found in some xaml files.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-10-11 20:34:24 UTC (rev 87356)
+++ trunk/moon/src/ChangeLog 2007-10-11 20:45:31 UTC (rev 87357)
@@ -1,3 +1,10 @@
+2007-10-11 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * panel.cpp|h: Split Render into Render and RenderChildren, so
+ the later can be overriden in InkPresenter.
+ * stylus.cpp|h: A quick (see FIXME) implementation to render
+ ink found in some xaml files.
+
2007-10-11 Jeffrey Stedfast <[EMAIL PROTECTED]>
* mplayer.cpp: Updated to use the new Queue class.
Modified: trunk/moon/src/panel.cpp
===================================================================
--- trunk/moon/src/panel.cpp 2007-10-11 20:34:24 UTC (rev 87356)
+++ trunk/moon/src/panel.cpp 2007-10-11 20:45:31 UTC (rev 87357)
@@ -104,7 +104,7 @@
r = IntersectBoundsWithClipPath (r, true);
#if DEBUG_BOUNDS
space (levelb + 4);
- printf ("Item (%s, 5s) bounds %g %g %g %g\n",
+ printf ("Item (%s, %s) bounds %g %g %g %g\n",
dependency_object_get_name (item),
item->GetTypeName(),r.x, r.y, r.w, r.h);
#endif
if (first) {
@@ -182,7 +182,7 @@
// non-translucent.
Type::Kind type = item->GetObjectType();
- if (type == Type::PANEL || type == Type::CANVAS) {
+ if (type == Type::PANEL || type == Type::CANVAS || type
== Type::INKPRESENTER) {
bool panel_works = false;
#if notyet
Brush *bg = panel_get_background ((Panel*)item);
@@ -219,8 +219,6 @@
void
Panel::Render (cairo_t *cr, int x, int y, int width, int height)
{
- VisualCollection *children = GetChildren ();
-
cairo_save (cr); // for UIElement::ClipProperty
cairo_set_matrix (cr, &absolute_xform);
@@ -243,6 +241,16 @@
}
}
+ RenderChildren (cr, x, y, width, height);
+
+ cairo_restore (cr);
+}
+
+void
+Panel::RenderChildren (cairo_t *cr, int x, int y, int width, int height)
+{
+ VisualCollection *children = GetChildren ();
+
Rect render_rect (x, y, width, height);
gint start_element = FindStartingElement (render_rect);
@@ -318,8 +326,7 @@
//printf ("RENDER: LEAVE\n");
//draw_grid (cr);
- levelb -= 4;
- cairo_restore (cr);
+// levelb -= 4;
}
bool
Modified: trunk/moon/src/panel.h
===================================================================
--- trunk/moon/src/panel.h 2007-10-11 20:34:24 UTC (rev 87356)
+++ trunk/moon/src/panel.h 2007-10-11 20:45:31 UTC (rev 87357)
@@ -32,6 +32,7 @@
virtual void ComputeBounds ();
virtual void Render (cairo_t *cr, int x, int y, int width, int height);
+ virtual void RenderChildren (cairo_t *cr, int x, int y, int width, int
height);
bool CheckOver (cairo_t *cr, UIElement *item, double x, double y);
Modified: trunk/moon/src/stylus.cpp
===================================================================
--- trunk/moon/src/stylus.cpp 2007-10-11 20:34:24 UTC (rev 87356)
+++ trunk/moon/src/stylus.cpp 2007-10-11 20:45:31 UTC (rev 87357)
@@ -3,6 +3,7 @@
*
* Author:
* Rolf Bjarne Kvinge ([EMAIL PROTECTED])
+ * Sebastien Pouliot <[EMAIL PROTECTED]>
*
* Copyright 2007 Novell, Inc. (http://www.novell.com)
*
@@ -17,7 +18,10 @@
#include <glib.h>
#include <stdlib.h>
#include <math.h>
+
#include "stylus.h"
+#include "collection.h"
+#include "color.h"
StylusInfo*
@@ -26,12 +30,50 @@
return new StylusInfo ();
}
+
StylusPoint*
stylus_point_new ()
{
return new StylusPoint ();
}
+double
+stylus_point_get_x (StylusPoint *stylus_point)
+{
+ return stylus_point->GetValue (StylusPoint::XProperty)->AsDouble();
+}
+
+void
+stylus_point_set_x (StylusPoint *stylus_point, double x)
+{
+ stylus_point->SetValue (StylusPoint::XProperty, Value (x));
+}
+
+double
+stylus_point_get_y (StylusPoint *stylus_point)
+{
+ return stylus_point->GetValue (StylusPoint::YProperty)->AsDouble();
+}
+
+void
+stylus_point_set_y (StylusPoint *stylus_point, double y)
+{
+ stylus_point->SetValue (StylusPoint::YProperty, Value (y));
+}
+
+double
+stylus_point_get_pressure_factor (StylusPoint *stylus_point)
+{
+ return stylus_point->GetValue
(StylusPoint::PressureFactorProperty)->AsDouble();
+}
+
+void
+stylus_point_set_pressure_factor (StylusPoint *stylus_point, double pressure)
+{
+ stylus_point->SetValue (StylusPoint::PressureFactorProperty, Value
(pressure));
+}
+
+
Stroke*
stroke_new ()
{
@@ -39,11 +81,143 @@
}
DrawingAttributes*
+stroke_get_drawing_attributes (Stroke *stroke)
+{
+ Value *value = stroke->GetValue (Stroke::DrawingAttributesProperty);
+ return value ? value->AsDrawingAttributes () : NULL;
+}
+
+void
+stroke_set_drawing_attributes (Stroke *stroke, DrawingAttributes *attributes)
+{
+ stroke->SetValue (Stroke::DrawingAttributesProperty, Value
(attributes));
+}
+
+
+DrawingAttributes*
drawing_attributes_new ()
{
return new DrawingAttributes ();
}
+Color*
+drawing_attributes_get_color (DrawingAttributes* da)
+{
+ return da->GetValue (DrawingAttributes::ColorProperty)->AsColor();
+}
+
+void
+drawing_attributes_set_color (DrawingAttributes* da, Color *color)
+{
+ da->SetValue (DrawingAttributes::ColorProperty, Value (*color));
+}
+
+Color*
+drawing_attributes_get_outline_color (DrawingAttributes* da)
+{
+ return da->GetValue
(DrawingAttributes::OutlineColorProperty)->AsColor();
+}
+
+void
+drawing_attributes_set_outline_color (DrawingAttributes* da, Color *color)
+{
+ da->SetValue (DrawingAttributes::OutlineColorProperty, Value (*color));
+}
+
+double
+drawing_attributes_get_height (DrawingAttributes* da)
+{
+ return da->GetValue (DrawingAttributes::HeightProperty)->AsDouble();
+}
+
+void
+drawing_attributes_set_height (DrawingAttributes* da, double height)
+{
+ da->SetValue (DrawingAttributes::HeightProperty, Value (height));
+}
+
+double
+drawing_attributes_get_width (DrawingAttributes* da)
+{
+ return da->GetValue (DrawingAttributes::WidthProperty)->AsDouble();
+}
+
+void
+drawing_attributes_set_width (DrawingAttributes* da, double width)
+{
+ da->SetValue (DrawingAttributes::WidthProperty, Value (width));
+}
+
+
+void
+InkPresenter::RenderChildren (cairo_t *cr, int x, int y, int width, int height)
+{
+ // Canvas elements are supported inside the InkPresenter
+ Panel::RenderChildren (cr, x, y, width, height);
+
+ Value* value = GetValue (InkPresenter::StrokesProperty);
+ if (!value)
+ return;
+
+ StrokeCollection *strokes = value->AsStrokeCollection ();
+ if (!strokes)
+ return;
+
+ cairo_set_matrix (cr, &absolute_xform);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+
+ // for each stroke in collection
+ Collection::Node *cn = (Collection::Node *) strokes->list->First ();
+ for ( ; cn != NULL; cn = (Collection::Node *) cn->next) {
+ double thickness = 1.0;
+ Stroke *stroke = (Stroke *) cn->obj;
+ // set drawing attributes
+ value = stroke->GetValue (Stroke::DrawingAttributesProperty);
+ if (value) {
+ DrawingAttributes *da = value->AsDrawingAttributes ();
+ if (da) {
+// FIXME: we need a brush that will respect width|height and both colors
+ thickness = drawing_attributes_get_height (da);
+ Color *color = drawing_attributes_get_color
(da);
+ cairo_set_source_rgba (cr, color->r, color->g,
color->b, color->a);
+ }
+ }
+ // for each stylus point in stroke
+ value = stroke->GetValue (Stroke::StylusPointsProperty);
+ if (value) {
+ StylusPointCollection *spc =
value->AsStylusPointCollection ();
+ if (spc) {
+ Collection::Node *cnp = (Collection::Node *)
spc->list->First ();
+ if (!cnp)
+ continue;
+
+ StylusPoint *stylus_point = (StylusPoint*)
cnp->obj;
+ cairo_move_to (cr, stylus_point_get_x
(stylus_point), stylus_point_get_y (stylus_point));
+ cnp = (Collection::Node *) cnp->next;
+
+ for ( ; cnp != NULL; cnp = (Collection::Node *)
cnp->next) {
+ StylusPoint *stylus_point =
(StylusPoint*) cnp->obj;
+
+ cairo_set_line_width (cr, thickness *
(1.0 + stylus_point_get_pressure_factor (stylus_point)));
+ cairo_line_to (cr, stylus_point_get_x
(stylus_point), stylus_point_get_y (stylus_point));
+ }
+
+ cairo_stroke (cr);
+ }
+ }
+ }
+}
+
+bool
+InkPresenter::OnChildPropertyChanged (DependencyProperty *prop,
DependencyObject *child)
+{
+ if (prop == StrokesProperty)
+ return true;
+
+ return Canvas::OnChildPropertyChanged (prop, child);
+}
+
InkPresenter*
ink_presenter_new ()
{
@@ -69,20 +243,20 @@
void stylus_init ()
{
- StylusInfo::DeviceTypeProperty = DependencyObject::Register
(Type::STYLUSINFO, "DeviceType", Type::INT32);
- StylusInfo::IsInvertedProperty = DependencyObject::Register
(Type::STYLUSINFO, "IsInverted", Type::BOOL);
+ StylusInfo::DeviceTypeProperty = DependencyObject::Register
(Type::STYLUSINFO, "DeviceType", new Value (TabletDeviceTypeMouse));
+ StylusInfo::IsInvertedProperty = DependencyObject::Register
(Type::STYLUSINFO, "IsInverted", new Value (false));
- StylusPoint::PressureFactorProperty = DependencyObject::Register
(Type::STYLUSPOINT, "PressureFactor", Type::DOUBLE);
- StylusPoint::XProperty = DependencyObject::Register (Type::STYLUSPOINT,
"X", Type::DOUBLE);
- StylusPoint::YProperty = DependencyObject::Register (Type::STYLUSPOINT,
"Y", Type::DOUBLE);
+ StylusPoint::PressureFactorProperty = DependencyObject::Register
(Type::STYLUSPOINT, "PressureFactor", new Value (0.5));
+ StylusPoint::XProperty = DependencyObject::Register (Type::STYLUSPOINT,
"X", new Value (0.0));
+ StylusPoint::YProperty = DependencyObject::Register (Type::STYLUSPOINT,
"Y", new Value (0.0));
Stroke::DrawingAttributesProperty = DependencyObject::Register
(Type::STROKE, "DrawingAttributes", Type::DRAWINGATTRIBUTES);
Stroke::StylusPointsProperty = DependencyObject::Register
(Type::STROKE, "StylusPoints", Type::STYLUSPOINT_COLLECTION);
- DrawingAttributes::ColorProperty = DependencyObject::Register
(Type::DRAWINGATTRIBUTES, "Color", Type::COLOR);
- DrawingAttributes::OutlineColorProperty = DependencyObject::Register
(Type::DRAWINGATTRIBUTES, "OutlineColor", Type::COLOR);
- DrawingAttributes::HeightProperty = DependencyObject::Register
(Type::DRAWINGATTRIBUTES, "Height", Type::DOUBLE);
- DrawingAttributes::WidthProperty = DependencyObject::Register
(Type::DRAWINGATTRIBUTES, "Width", Type::DOUBLE);
+ DrawingAttributes::ColorProperty = DependencyObject::Register
(Type::DRAWINGATTRIBUTES, "Color", new Value (Color (0xFF000000)));
+ DrawingAttributes::OutlineColorProperty = DependencyObject::Register
(Type::DRAWINGATTRIBUTES, "OutlineColor", new Value (Color (0x00000000)));
+ DrawingAttributes::HeightProperty = DependencyObject::Register
(Type::DRAWINGATTRIBUTES, "Height", new Value (3.0));
+ DrawingAttributes::WidthProperty = DependencyObject::Register
(Type::DRAWINGATTRIBUTES, "Width", new Value (3.0));
InkPresenter::StrokesProperty = DependencyObject::Register
(Type::INKPRESENTER, "Strokes", Type::STROKE_COLLECTION);
}
Modified: trunk/moon/src/stylus.h
===================================================================
--- trunk/moon/src/stylus.h 2007-10-11 20:34:24 UTC (rev 87356)
+++ trunk/moon/src/stylus.h 2007-10-11 20:45:31 UTC (rev 87357)
@@ -3,6 +3,7 @@
*
* Author:
* Rolf Bjarne Kvinge ([EMAIL PROTECTED])
+ * Sebastien Pouliot <[EMAIL PROTECTED]>
*
* Copyright 2007 Novell, Inc. (http://www.novell.com)
*
@@ -17,6 +18,13 @@
G_BEGIN_DECLS
+typedef enum {
+ TabletDeviceTypeMouse,
+ TabletDeviceTypeStylus,
+ TabletDeviceTypeTouch
+} TabletDeviceType;
+
+
class StylusInfo : public DependencyObject {
public:
StylusInfo () { }
@@ -43,20 +51,13 @@
};
StylusPoint* stylus_point_new ();
+double stylus_point_get_x (StylusPoint *stylus_point);
+void stylus_point_set_x (StylusPoint *stylus_point, double x);
+double stylus_point_get_y (StylusPoint *stylus_point);
+void stylus_point_set_y (StylusPoint *stylus_point, double y);
+double stylus_point_get_pressure_factor (StylusPoint *stylus_point);
+void stylus_point_set_pressure_factor (StylusPoint *stylus_point, double
pressure);
-class Stroke : public DependencyObject {
- public:
- Stroke () { }
- virtual ~Stroke () { };
-
- virtual Type::Kind GetObjectType () { return Type::STROKE; };
-
- static DependencyProperty* DrawingAttributesProperty;
- static DependencyProperty* StylusPointsProperty;
-};
-
-Stroke* stroke_new ();
-
class DrawingAttributes : public DependencyObject {
public:
DrawingAttributes () { }
@@ -71,7 +72,30 @@
};
DrawingAttributes* drawing_attributes_new ();
+Color* drawing_attributes_get_color (DrawingAttributes* da);
+void drawing_attributes_set_color (DrawingAttributes* da, Color *color);
+Color* drawing_attributes_get_outline_color (DrawingAttributes* da);
+void drawing_attributes_set_outline_color (DrawingAttributes* da, Color
*color);
+double drawing_attributes_get_height (DrawingAttributes* da);
+void drawing_attributes_set_height (DrawingAttributes* da, double height);
+double drawing_attributes_get_width (DrawingAttributes* da);
+void drawing_attributes_set_width (DrawingAttributes* da, double width);
+class Stroke : public DependencyObject {
+ public:
+ Stroke () { }
+ virtual ~Stroke () { };
+
+ virtual Type::Kind GetObjectType () { return Type::STROKE; };
+
+ static DependencyProperty* DrawingAttributesProperty;
+ static DependencyProperty* StylusPointsProperty;
+};
+
+Stroke* stroke_new ();
+DrawingAttributes* stroke_get_drawing_attributes (Stroke *stroke);
+void stroke_set_drawing_attributes (Stroke *stroke, DrawingAttributes
*attributes);
+
class InkPresenter : public Canvas {
public:
InkPresenter () { }
@@ -79,6 +103,9 @@
virtual Type::Kind GetObjectType () { return Type::INKPRESENTER; };
+ virtual void RenderChildren (cairo_t *cr, int x, int y, int width, int
height);
+ virtual bool OnChildPropertyChanged (DependencyProperty *prop,
DependencyObject *child);
+
static DependencyProperty* StrokesProperty;
};
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches