Author: spouliot
Date: 2007-10-20 12:23:42 -0400 (Sat, 20 Oct 2007)
New Revision: 87853
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/stylus.cpp
trunk/moon/src/stylus.h
Log:
2007-10-20 Sebastien Pouliot <[EMAIL PROTECTED]>
* runtime.h: Add gtk.h (since it depended on stylus.h to get it)
* stylus.cpp|h: Add some missing functions. Rendering changes
(not active, work in progress).
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-10-20 16:20:59 UTC (rev 87852)
+++ trunk/moon/src/ChangeLog 2007-10-20 16:23:42 UTC (rev 87853)
@@ -1,3 +1,9 @@
+2007-10-20 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * runtime.h: Add gtk.h (since it depended on stylus.h to get it)
+ * stylus.cpp|h: Add some missing functions. Rendering changes
+ (not active, work in progress).
+
2007-10-18 Chris Toshok <[EMAIL PROTECTED]>
* dependencyobject.h: fix comment.
Modified: trunk/moon/src/stylus.cpp
===================================================================
--- trunk/moon/src/stylus.cpp 2007-10-20 16:20:59 UTC (rev 87852)
+++ trunk/moon/src/stylus.cpp 2007-10-20 16:23:42 UTC (rev 87853)
@@ -12,25 +12,44 @@
*/
#include <config.h>
-#include <string.h>
-#include <gtk/gtk.h>
-#include <malloc.h>
-#include <glib.h>
#include <stdlib.h>
-#include <math.h>
#include "stylus.h"
#include "collection.h"
#include "color.h"
+#include "moon-path.h"
-
StylusInfo*
stylus_info_new ()
{
return new StylusInfo ();
}
+TabletDeviceType
+stylus_info_get_device_type (StylusInfo* stylus_info)
+{
+ return (TabletDeviceType) stylus_info->GetValue
(StylusInfo::DeviceTypeProperty)->AsInt32 ();
+}
+void
+stylus_info_set_device_type (StylusInfo* stylus_info, TabletDeviceType type)
+{
+ stylus_info->SetValue (StylusInfo::DeviceTypeProperty, Value (type));
+}
+
+bool
+stylus_info_get_inverted (StylusInfo* stylus_info)
+{
+ return stylus_info->GetValue (StylusInfo::IsInvertedProperty)->AsBool
();
+}
+
+void
+stylus_info_set_inverted (StylusInfo* stylus_info, bool inverted)
+{
+ stylus_info->SetValue (StylusInfo::IsInvertedProperty, Value
(inverted));
+}
+
+
StylusPoint*
stylus_point_new ()
{
@@ -148,8 +167,21 @@
da->SetValue (DrawingAttributes::WidthProperty, Value (width));
}
+StylusPointCollection*
+stroke_get_stylus_points (Stroke *stroke)
+{
+ Value *value = stroke->GetValue (Stroke::StylusPointsProperty);
+ return (value ? value->AsStylusPointCollection () : NULL);
+}
void
+stroke_set_stylus_points (Stroke *stroke, StylusPointCollection* collection)
+{
+ stroke->SetValue (Stroke::StylusPointsProperty, Value (collection));
+}
+
+#if TRUE
+void
InkPresenter::RenderChildren (cairo_t *cr, int x, int y, int width, int height)
{
// Canvas elements are supported inside the InkPresenter
@@ -208,7 +240,166 @@
}
}
}
+#else
+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);
+ cairo_set_line_width (cr, 2.0);
+
+ moon_path *path = moon_path_new (10);
+
+ // 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;
+ Color *color = NULL;
+ Color *outline_color = NULL;
+
+ float rx = 2.0;
+ float ry = 2.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
+ rx += drawing_attributes_get_width (da);
+ ry += drawing_attributes_get_height (da);
+ color = drawing_attributes_get_color (da);
+ outline_color =
drawing_attributes_get_outline_color (da);
+ }
+ }
+ // 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;
+
+ double c1x = stylus_point_get_x (stylus_point);
+ double c1y = stylus_point_get_y (stylus_point);
+
+ // ellipse are drawn by specifying the
upper-left corner, stylus points are at center
+ double hrx = (rx / 2.0);
+ double hry = (ry / 2.0);
+ double ex = c1x - hrx;
+ double ey = c1y - hry;
+
+ if (!cnp->next) {
+ // this is a single point stroke,
replace by ellipse
+ moon_ellipse (path, ex, ey, rx, ry);
+ } else {
+ moon_ellipse (path, ex, ey, rx, ry);
+
+ for (cnp = (Collection::Node *)
cnp->next ; cnp != NULL; cnp = (Collection::Node *) cnp->next) {
+ StylusPoint *stylus_point =
(StylusPoint*) cnp->obj;
+
+ double c2x = stylus_point_get_x
(stylus_point);
+ double c2y = stylus_point_get_y
(stylus_point);
+
+ double x1, y1, x2, y2;
+ if (c2x - c1x == 0) {
+ x1 = c1x + hrx;
+ y1 = c1y;
+ x2 = c2x + hrx;
+ y2 = c2y;
+ } else if (c2y - c1y == 0) {
+ x1 = c1x;
+ y1 = c1y + hry;
+ x2 = c2x;
+ y2 = c2y + hry;
+ } else {
+ double m = (c2y - c1y)
/ (c2x - c1x);
+ double angle = atan
(1.0 / m);
+ x1 = c1x + hrx * cos
(angle);
+ y1 = c1y - hry * sin
(angle);
+ x2 = c2x + hrx * cos
(angle);
+ y2 = c2y - hry * sin
(angle);
+ }
+ moon_move_to (path, x1, y1);
+ moon_line_to (path, x2, y2);
+
+// cairo_set_line_width (cr, ry *
(1.0 + stylus_point_get_pressure_factor (stylus_point)));
+ ex = c2x - hrx;
+ ey = c2y - hry;
+ moon_ellipse (path, ex, ey, rx,
ry);
+ }
+
+ cnp = (Collection::Node *)
spc->list->Last ();
+ for ( ; cnp != NULL; cnp =
(Collection::Node *) cnp->prev) {
+ StylusPoint *stylus_point =
(StylusPoint*) cnp->obj;
+
+ double c2x = stylus_point_get_x
(stylus_point);
+ double c2y = stylus_point_get_y
(stylus_point);
+
+ double x1, y1, x2, y2;
+ if (c2x - c1x == 0) {
+ x1 = c1x - hrx;
+ y1 = c1y;
+ x2 = c2x - hrx;
+ y2 = c2y;
+ } else if (c2y - c1y == 0) {
+ x1 = c1x;
+ y1 = c1y - hry;
+ x2 = c2x;
+ y2 = c2y - hry;
+ } else {
+ double m = (c2y - c1y)
/ (c2x - c1x);
+ double angle = atan
(1.0 / m);
+ x1 = c1x - hrx * cos
(angle);
+ y1 = c1y + hry * sin
(angle);
+ x2 = c2x - hrx * cos
(angle);
+ y2 = c2y + hry * sin
(angle);
+ }
+ moon_move_to (path, x1, y1);
+ moon_line_to (path, x2, y2);
+
+// cairo_set_line_width (cr, ry *
(1.0 + stylus_point_get_pressure_factor (stylus_point)));
+ ex = c2x - hrx;
+ ey = c2y - hry;
+ moon_ellipse (path, ex, ey, rx,
ry);
+ }
+ }
+ }
+
+ cairo_new_path (cr);
+ cairo_append_path (cr, &path->cairo);
+
+ if (color) {
+ cairo_set_source_rgba (cr, color->r, color->g,
color->b, color->a);
+ cairo_fill_preserve (cr);
+ }
+ if (outline_color) {
+ cairo_set_source_rgba (cr, outline_color->r,
outline_color->g, outline_color->b, outline_color->a);
+ cairo_stroke (cr);
+ }
+ moon_path_clear (path);
+ }
+ }
+ moon_path_destroy (path);
+}
+#endif
+
bool
InkPresenter::OnChildPropertyChanged (DependencyProperty *prop,
DependencyObject *child)
{
@@ -224,6 +415,20 @@
return new InkPresenter ();
}
+StrokeCollection*
+ink_presenter_get_strokes (InkPresenter *ink_presenter)
+{
+ Value *value = ink_presenter->GetValue (InkPresenter::StrokesProperty);
+ return (value ? value->AsStrokeCollection () : NULL);
+}
+
+void
+ink_presenter_set_strokes (InkPresenter *ink_presenter, StrokeCollection*
collection)
+{
+ ink_presenter->SetValue (InkPresenter::StrokesProperty, Value
(collection));
+}
+
+
DependencyProperty* StylusInfo::DeviceTypeProperty;
DependencyProperty* StylusInfo::IsInvertedProperty;
Modified: trunk/moon/src/stylus.h
===================================================================
--- trunk/moon/src/stylus.h 2007-10-20 16:20:59 UTC (rev 87852)
+++ trunk/moon/src/stylus.h 2007-10-20 16:23:42 UTC (rev 87853)
@@ -37,7 +37,12 @@
};
StylusInfo* stylus_info_new ();
+TabletDeviceType stylus_info_get_device_type (StylusInfo* stylus_info);
+void stylus_info_set_device_type (StylusInfo* stylus_info,
TabletDeviceType type);
+bool stylus_info_get_inverted (StylusInfo* stylus_info);
+void stylus_info_set_inverted (StylusInfo* stylus_info, bool
inverted);
+
class StylusPoint : public DependencyObject {
public:
StylusPoint () { }
@@ -95,7 +100,10 @@
Stroke* stroke_new ();
DrawingAttributes* stroke_get_drawing_attributes (Stroke *stroke);
void stroke_set_drawing_attributes (Stroke *stroke, DrawingAttributes
*attributes);
+StylusPointCollection* stroke_get_stylus_points (Stroke *stroke);
+void stroke_set_stylus_points (Stroke *stroke, StylusPointCollection*
collection);
+
class InkPresenter : public Canvas {
public:
InkPresenter () { }
@@ -110,7 +118,10 @@
};
InkPresenter* ink_presenter_new ();
+StrokeCollection* ink_presenter_get_strokes (InkPresenter *ink_presenter);
+void ink_presenter_set_strokes (InkPresenter *ink_presenter, StrokeCollection*
collection);
+
void stylus_init (void);
G_END_DECLS
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches