Author: matt
Date: 2012-04-29 12:10:11 -0700 (Sun, 29 Apr 2012)
New Revision: 9408
Log:
Added a local origin to most (all?) graphics calls. This is needed to implement
group-relative coordinate systems. FLTK 2 solves this slightly different, but I
think I prefer this way. test/subwindow is used to verify success.
Group-relative coordinates will be the FLTK 3 default, Window-relative
coordinates are optional for backwards compatibility. This commit does not
solve event_x() and event_y() handling yet!
Modified:
branches/branch-3.0/include/fltk3/Device.h
branches/branch-3.0/include/fltk3/Widget.h
branches/branch-3.0/include/fltk3/draw.h
branches/branch-3.0/src/fltk3/Group.cxx
branches/branch-3.0/src/fltk3/Widget.cxx
branches/branch-3.0/src/fltk3/arci.cxx
branches/branch-3.0/src/fltk3/boxtype.cxx
branches/branch-3.0/src/fltk3/cocoa_draw_image.cxx
branches/branch-3.0/src/fltk3/cocoa_font.cxx
branches/branch-3.0/src/fltk3/rect.cxx
branches/branch-3.0/src/fltk3/run.cxx
branches/branch-3.0/src/fltk3/vertex.cxx
branches/branch-3.0/test/subwindow.cxx
Modified: branches/branch-3.0/include/fltk3/Device.h
===================================================================
--- branches/branch-3.0/include/fltk3/Device.h 2012-04-28 00:46:24 UTC (rev
9407)
+++ branches/branch-3.0/include/fltk3/Device.h 2012-04-29 19:10:11 UTC (rev
9408)
@@ -95,6 +95,7 @@
/** A 2D coordinate transformation matrix
*/
struct matrix {double a, b, c, d, x, y;};
+ struct origin {int x, y;};
private:
static const matrix m0;
fltk3::Font font_; // current font
@@ -104,6 +105,10 @@
enum { matrix_stack_size = MATRIX_STACK_SIZE };
matrix stack[MATRIX_STACK_SIZE];
matrix m;
+ int optr;
+ enum { origin_stack_size = MATRIX_STACK_SIZE };
+ origin ostack[MATRIX_STACK_SIZE];
+ origin o;
int rstackptr;
enum { region_stack_max = REGION_STACK_SIZE - 1 };
fltk3::Region rstack[REGION_STACK_SIZE];
@@ -227,6 +232,13 @@
/** \brief see fltk3::pop_clip(). */
virtual void pop_clip();
+ void push_origin();
+ void pop_origin();
+ void translate_origin(int dx, int dy);
+ void origin(int x, int y);
+ int origin_x() { return o.x; }
+ int origin_y() { return o.y; }
+
/** \brief see fltk3::push_matrix(). */
void push_matrix();
/** \brief see fltk3::pop_matrix(). */
Modified: branches/branch-3.0/include/fltk3/Widget.h
===================================================================
--- branches/branch-3.0/include/fltk3/Widget.h 2012-04-28 00:46:24 UTC (rev
9407)
+++ branches/branch-3.0/include/fltk3/Widget.h 2012-04-29 19:10:11 UTC (rev
9408)
@@ -783,6 +783,18 @@
*/
void clear_output() {flags_ &= ~OUTPUT;}
+ /** Makes the coordinate system of this group relative to the enclosing
window.
+ \see group_relative()
+ */
+ void set_window_relative() { flags_ &= ~GROUP_RELATIVE; }
+ int is_window_relative() const { return ((flags_|GROUP_RELATIVE)==0); }
+
+ /** Use a local coordinte system for this group.
+ \see window_relative()
+ */
+ void set_group_relative() { flags_ |= GROUP_RELATIVE; }
+ int is_group_relative() const { return
((flags_|GROUP_RELATIVE)==GROUP_RELATIVE); }
+
/** Returns if the widget is able to take events.
This is the same as (active() && !output() && visible())
but is faster.
@@ -1025,6 +1037,13 @@
\deprecated Use selection_color(unsigned) instead.
*/
void color2(unsigned a) {color2_ = a;}
+
+ /** Choose a coding style for this widget.
+ FLTK 1 coding style uses a Window-relative coordinte system.
+ FLTK 2 and 3 use a Group-relative coordinte system.
+ More details will be implemented later.
+ */
+ void coding_style(int s);
};
Modified: branches/branch-3.0/include/fltk3/draw.h
===================================================================
--- branches/branch-3.0/include/fltk3/draw.h 2012-04-28 00:46:24 UTC (rev
9407)
+++ branches/branch-3.0/include/fltk3/draw.h 2012-04-29 19:10:11 UTC (rev
9408)
@@ -328,6 +328,13 @@
/** fltk3::chord declaration is a place holder - the function does not yet
exist */
FLTK3_EXPORT void chord(int x, int y, int w, int h, double a1, double a2);
// nyi
+ inline void push_origin() { fltk3::graphics_driver->push_origin(); }
+ inline void pop_origin() { fltk3::graphics_driver->pop_origin(); }
+ inline void translate_origin(int dx, int dy) {
fltk3::graphics_driver->translate_origin(dx, dy); }
+ inline void origin(int x, int y) { fltk3::graphics_driver->origin(x, y); }
+ inline int origin_x() { return fltk3::graphics_driver->origin_x(); }
+ inline int origin_y() { return fltk3::graphics_driver->origin_y(); }
+
// scalable drawing code (code in fltk3::vertex.C and fltk3::arc.C):
/**
Saves the current transformation matrix on the stack.
Modified: branches/branch-3.0/src/fltk3/Group.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Group.cxx 2012-04-28 00:46:24 UTC (rev
9407)
+++ branches/branch-3.0/src/fltk3/Group.cxx 2012-04-29 19:10:11 UTC (rev
9408)
@@ -100,7 +100,9 @@
// windows so they are relative to that window.
static int send(fltk3::Widget* o, int event) {
- if (o->type() < fltk3::WINDOW) return o->handle(event);
+ if ( o->type()<fltk3::WINDOW) {
+ return o->handle(event);
+ }
switch ( event )
{
case fltk3::DND_ENTER: /* FALLTHROUGH */
@@ -745,14 +747,7 @@
draw_box();
draw_label();
}
- if (flags()&GROUP_RELATIVE) {
- push_matrix();
- translate(x(), y());
- draw_children();
- pop_matrix();
- } else {
- draw_children();
- }
+ draw_children();
}
/**
@@ -781,7 +776,14 @@
if (widget.visible() && widget.type() < fltk3::WINDOW &&
fltk3::not_clipped(widget.x(), widget.y(), widget.w(), widget.h())) {
widget.clear_damage(fltk3::DAMAGE_ALL);
- widget.draw();
+ if (widget.flags()&fltk3::Widget::GROUP_RELATIVE) {
+ push_origin();
+ translate_origin(widget.x(), widget.y());
+ widget.draw();
+ pop_origin();
+ } else {
+ widget.draw();
+ }
widget.clear_damage();
}
}
Modified: branches/branch-3.0/src/fltk3/Widget.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Widget.cxx 2012-04-28 00:46:24 UTC (rev
9407)
+++ branches/branch-3.0/src/fltk3/Widget.cxx 2012-04-29 19:10:11 UTC (rev
9408)
@@ -385,6 +385,19 @@
draw_label();
}
+void fltk3::Widget::coding_style(int s) {
+ switch (s) {
+ case 1:
+ set_window_relative();
+ break;
+ case 2:
+ set_group_relative();
+ break;
+ case 3:
+ set_group_relative();
+ break;
+ }
+}
// ========================= Wrapper Support
===================================
Modified: branches/branch-3.0/src/fltk3/arci.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/arci.cxx 2012-04-28 00:46:24 UTC (rev
9407)
+++ branches/branch-3.0/src/fltk3/arci.cxx 2012-04-29 19:10:11 UTC (rev
9408)
@@ -50,6 +50,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::arc(int x,int y,int w,int h,double a1,double
a2) {
if (w <= 0 || h <= 0) return;
+ x += origin_x(); y += origin_y();
a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
CGContextSetShouldAntialias(fl_gc, true);
@@ -69,6 +70,7 @@
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::arc(int x,int y,int w,int h,double a1,double
a2) {
if (w <= 0 || h <= 0) return;
+ x += origin_x(); y += origin_y();
int xa = x+w/2+int(w*cos(a1/180.0*M_PI));
int ya = y+h/2-int(h*sin(a1/180.0*M_PI));
int xb = x+w/2+int(w*cos(a2/180.0*M_PI));
@@ -81,6 +83,7 @@
#else
void fltk3::XlibGraphicsDriver::arc(int x,int y,int w,int h,double a1,double
a2) {
if (w <= 0 || h <= 0) return;
+ x += origin_x(); y += origin_y();
XDrawArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1,
int(a1*64),int((a2-a1)*64));
}
#endif
@@ -89,6 +92,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::pie(int x,int y,int w,int h,double a1,double
a2) {
if (w <= 0 || h <= 0) return;
+ x += origin_x(); y += origin_y();
a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
CGContextSetShouldAntialias(fl_gc, true);
@@ -112,6 +116,7 @@
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::pie(int x,int y,int w,int h,double a1,double
a2) {
if (w <= 0 || h <= 0) return;
+ x += origin_x(); y += origin_y();
if (a1 == a2) return;
int xa = x+w/2+int(w*cos(a1/180.0*M_PI));
int ya = y+h/2-int(h*sin(a1/180.0*M_PI));
@@ -129,6 +134,7 @@
#else
void fltk3::XlibGraphicsDriver::pie(int x,int y,int w,int h,double a1,double
a2) {
if (w <= 0 || h <= 0) return;
+ x += origin_x(); y += origin_y();
XDrawArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1,
int(a1*64),int((a2-a1)*64));
XFillArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1,
int(a1*64),int((a2-a1)*64));
}
Modified: branches/branch-3.0/src/fltk3/boxtype.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/boxtype.cxx 2012-04-28 00:46:24 UTC (rev
9407)
+++ branches/branch-3.0/src/fltk3/boxtype.cxx 2012-04-29 19:10:11 UTC (rev
9408)
@@ -446,7 +446,13 @@
//extern fltk3::Widget *fl_boxcheat; // hack set by fltk3::Window.cxx
/** Draws the widget box according its box style */
void fltk3::Widget::draw_box() const {
- if (box_) draw_box((fltk3::Boxtype)box_, x_, y_, w_, h_, color_);
+ if (box_) {
+ if (flags()&GROUP_RELATIVE) {
+ draw_box((fltk3::Boxtype)box_, 0, 0, w_, h_, color_);
+ } else {
+ draw_box((fltk3::Boxtype)box_, x_, y_, w_, h_, color_);
+ }
+ }
draw_backdrop();
}
/** If fltk3::ALIGN_IMAGE_BACKDROP is set, the image or deimage will be drawn
*/
Modified: branches/branch-3.0/src/fltk3/cocoa_draw_image.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/cocoa_draw_image.cxx 2012-04-28 00:46:24 UTC
(rev 9407)
+++ branches/branch-3.0/src/fltk3/cocoa_draw_image.cxx 2012-04-29 19:10:11 UTC
(rev 9408)
@@ -152,18 +152,18 @@
}
void fltk3::QuartzGraphicsDriver::draw_image(const uchar* buf, int x, int y,
int w, int h, int d, int l){
- innards(buf,x,y,w,h,d,l,(d<3&&d>-3),0,0);
+ innards(buf,x+origin_x(),y+origin_y(),w,h,d,l,(d<3&&d>-3),0,0);
}
void fltk3::QuartzGraphicsDriver::draw_image(fltk3::DrawImageCb cb, void* data,
int x, int y, int w, int h,int d) {
- innards(0,x,y,w,h,d,0,(d<3&&d>-3),cb,data);
+ innards(0,x+origin_x(),y+origin_y(),w,h,d,0,(d<3&&d>-3),cb,data);
}
void fltk3::QuartzGraphicsDriver::draw_image_mono(const uchar* buf, int x, int
y, int w, int h, int d, int l){
- innards(buf,x,y,w,h,d,l,1,0,0);
+ innards(buf,x+origin_x(),y+origin_y(),w,h,d,l,1,0,0);
}
void fltk3::QuartzGraphicsDriver::draw_image_mono(fltk3::DrawImageCb cb, void*
data,
int x, int y, int w, int h,int d) {
- innards(0,x,y,w,h,d,0,1,cb,data);
+ innards(0,x+origin_x(),y+origin_y(),w,h,d,0,1,cb,data);
}
void fltk3::rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) {
Modified: branches/branch-3.0/src/fltk3/cocoa_font.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/cocoa_font.cxx 2012-04-28 00:46:24 UTC
(rev 9407)
+++ branches/branch-3.0/src/fltk3/cocoa_font.cxx 2012-04-29 19:10:11 UTC
(rev 9408)
@@ -478,6 +478,7 @@
#endif
static void fl_mac_draw(const char *str, int n, float x, float y,
fltk3::GraphicsDriver *driver) {
+ x += driver->origin_x(); y += driver->origin_y();
// convert to UTF-16 first
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
Modified: branches/branch-3.0/src/fltk3/rect.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/rect.cxx 2012-04-28 00:46:24 UTC (rev
9407)
+++ branches/branch-3.0/src/fltk3/rect.cxx 2012-04-29 19:10:11 UTC (rev
9408)
@@ -163,9 +163,35 @@
#endif // USE_X11
+void fltk3::GraphicsDriver::push_origin() {
+ if (optr==origin_stack_size)
+ fltk3::error("fltk3::push_origin(): origin stack overflow.");
+ else
+ ostack[optr++] = o;
+}
+
+void fltk3::GraphicsDriver::pop_origin() {
+ if (optr==0)
+ fltk3::error("fltk3::pop_origin(): origin stack underflow.");
+ else
+ o = ostack[--optr];
+}
+
+void fltk3::GraphicsDriver::translate_origin(int dx, int dy) {
+ o.x += dx;
+ o.y += dy;
+}
+
+void fltk3::GraphicsDriver::origin(int x, int y) {
+ o.x = x;
+ o.y = y;
+}
+
+
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::rect(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
+ x += origin_x(); y += origin_y();
if ( fltk3::SurfaceDevice::surface() ==
fltk3::DisplayDevice::display_device() && fl_quartz_line_width_ > 1.5f)
CGContextSetShouldAntialias(fl_gc, true);
CGRect rect = CGRectMake(x, y, w-1, h-1);
CGContextStrokeRect(fl_gc, rect);
@@ -174,6 +200,7 @@
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::rect(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
+ x += origin_x(); y += origin_y();
MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x+w-1, y);
LineTo(fl_gc, x+w-1, y+h-1);
@@ -183,6 +210,7 @@
#else
void fltk3::XlibGraphicsDriver::rect(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
+ x += origin_x(); y += origin_y();
if (!clip_to_short(x, y, w, h))
XDrawRectangle(fl_display, fl_window, fl_gc, x, y, w-1, h-1);
}
@@ -192,12 +220,14 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::rectf(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
+ x += origin_x(); y += origin_y();
CGRect rect = CGRectMake(x, y, w-0.9, h-0.9);
CGContextFillRect(fl_gc, rect);
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::rectf(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
+ x += origin_x(); y += origin_y();
RECT rect;
rect.left = x; rect.top = y;
rect.right = x + w; rect.bottom = y + h;
@@ -206,6 +236,7 @@
#else
void fltk3::XlibGraphicsDriver::rectf(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
+ x += origin_x(); y += origin_y();
if (!clip_to_short(x, y, w, h))
XFillRectangle(fl_display, fl_window, fl_gc, x, y, w, h);
}
@@ -215,6 +246,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::xyline(int x, int y, int x1) {
if (fltk3::SurfaceDevice::surface() !=
fltk3::DisplayDevice::display_device() || fl_quartz_line_width_ > 1.5f)
CGContextSetShouldAntialias(fl_gc, true);
+ x += origin_x(); y += origin_y(); x1 += origin_x();
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y);
CGContextStrokePath(fl_gc);
@@ -222,10 +254,12 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::xyline(int x, int y, int x1) {
+ x += origin_x(); y += origin_y(); x1 += origin_x();
MoveToEx(fl_gc, x, y, 0L); LineTo(fl_gc, x1+1, y);
}
#else
void fltk3::XlibGraphicsDriver::xyline(int x, int y, int x1) {
+ x += origin_x(); y += origin_y(); x1 += origin_x();
XDrawLine(fl_display, fl_window, fl_gc, clip_x(x), clip_x(y), clip_x(x1),
clip_x(y));
}
#endif
@@ -234,6 +268,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::xyline(int x, int y, int x1, int y2) {
if (fltk3::SurfaceDevice::surface() !=
fltk3::DisplayDevice::display_device() || fl_quartz_line_width_ > 1.5f)
CGContextSetShouldAntialias(fl_gc, true);
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y2 += origin_y();
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y);
CGContextAddLineToPoint(fl_gc, x1, y2);
@@ -242,6 +277,7 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::xyline(int x, int y, int x1, int y2) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y2 += origin_y();
if (y2 < y) y2--;
else y2++;
MoveToEx(fl_gc, x, y, 0L);
@@ -250,6 +286,7 @@
}
#else
void fltk3::XlibGraphicsDriver::xyline(int x, int y, int x1, int y2) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y2 += origin_y();
XPoint p[3];
p[0].x = clip_x(x); p[0].y = p[1].y = clip_x(y);
p[1].x = p[2].x = clip_x(x1); p[2].y = clip_x(y2);
@@ -261,6 +298,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::xyline(int x, int y, int x1, int y2, int x3)
{
if (fltk3::SurfaceDevice::surface() !=
fltk3::DisplayDevice::display_device() || fl_quartz_line_width_ > 1.5f)
CGContextSetShouldAntialias(fl_gc, true);
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y2 += origin_y(); x3 +=
origin_x();
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y);
CGContextAddLineToPoint(fl_gc, x1, y2);
@@ -270,6 +308,7 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::xyline(int x, int y, int x1, int y2, int x3) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y2 += origin_y(); x3 +=
origin_x();
if(x3 < x1) x3--;
else x3++;
MoveToEx(fl_gc, x, y, 0L);
@@ -279,6 +318,7 @@
}
#else
void fltk3::XlibGraphicsDriver::xyline(int x, int y, int x1, int y2, int x3) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y2 += origin_y(); x3 +=
origin_x();
XPoint p[4];
p[0].x = clip_x(x); p[0].y = p[1].y = clip_x(y);
p[1].x = p[2].x = clip_x(x1); p[2].y = p[3].y = clip_x(y2);
@@ -291,6 +331,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::yxline(int x, int y, int y1) {
if (fltk3::SurfaceDevice::surface() !=
fltk3::DisplayDevice::display_device() || fl_quartz_line_width_ > 1.5f)
CGContextSetShouldAntialias(fl_gc, true);
+ x += origin_x(); y += origin_y(); y1 += origin_y();
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x, y1);
CGContextStrokePath(fl_gc);
@@ -298,12 +339,14 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::yxline(int x, int y, int y1) {
+ x += origin_x(); y += origin_y(); y1 += origin_y();
if (y1 < y) y1--;
else y1++;
MoveToEx(fl_gc, x, y, 0L); LineTo(fl_gc, x, y1);
}
#else
void fltk3::XlibGraphicsDriver::yxline(int x, int y, int y1) {
+ x += origin_x(); y += origin_y(); y1 += origin_y();
XDrawLine(fl_display, fl_window, fl_gc, clip_x(x), clip_x(y), clip_x(x),
clip_x(y1));
}
#endif
@@ -312,6 +355,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::yxline(int x, int y, int y1, int x2) {
if (fltk3::SurfaceDevice::surface() !=
fltk3::DisplayDevice::display_device() || fl_quartz_line_width_ > 1.5f)
CGContextSetShouldAntialias(fl_gc, true);
+ x += origin_x(); y += origin_y(); y1 += origin_y(); x2 += origin_x();
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x, y1);
CGContextAddLineToPoint(fl_gc, x2, y1);
@@ -320,6 +364,7 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::yxline(int x, int y, int y1, int x2) {
+ x += origin_x(); y += origin_y(); y1 += origin_y(); x2 += origin_x();
if (x2 > x) x2++;
else x2--;
MoveToEx(fl_gc, x, y, 0L);
@@ -328,6 +373,7 @@
}
#else
void fltk3::XlibGraphicsDriver::yxline(int x, int y, int y1, int x2) {
+ x += origin_x(); y += origin_y(); y1 += origin_y(); x2 += origin_x();
XPoint p[3];
p[0].x = p[1].x = clip_x(x); p[0].y = clip_x(y);
p[1].y = p[2].y = clip_x(y1); p[2].x = clip_x(x2);
@@ -339,6 +385,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::yxline(int x, int y, int y1, int x2, int y3)
{
if (fltk3::SurfaceDevice::surface() !=
fltk3::DisplayDevice::display_device() || fl_quartz_line_width_ > 1.5f)
CGContextSetShouldAntialias(fl_gc, true);
+ x += origin_x(); y += origin_y(); y1 += origin_y(); x2 += origin_x(); y3 +=
origin_y();
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x, y1);
CGContextAddLineToPoint(fl_gc, x2, y1);
@@ -348,6 +395,7 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::yxline(int x, int y, int y1, int x2, int y3) {
+ x += origin_x(); y += origin_y(); y1 += origin_y(); x2 += origin_x(); y3 +=
origin_y();
if(y3<y1) y3--;
else y3++;
MoveToEx(fl_gc, x, y, 0L);
@@ -357,6 +405,7 @@
}
#else
void fltk3::XlibGraphicsDriver::yxline(int x, int y, int y1, int x2, int y3) {
+ x += origin_x(); y += origin_y(); y1 += origin_y(); x2 += origin_x(); y3 +=
origin_y();
XPoint p[4];
p[0].x = p[1].x = clip_x(x); p[0].y = clip_x(y);
p[1].y = p[2].y = clip_x(y1); p[2].x = p[3].x = clip_x(x2);
@@ -369,6 +418,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::line(int x, int y, int x1, int y1) {
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y();
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextStrokePath(fl_gc);
@@ -376,6 +426,7 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::line(int x, int y, int x1, int y1) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y();
MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x1, y1);
// Draw the last point *again* because the GDI line drawing
@@ -384,6 +435,7 @@
}
#else
void fltk3::XlibGraphicsDriver::line(int x, int y, int x1, int y1) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y();
XDrawLine(fl_display, fl_window, fl_gc, x, y, x1, y1);
}
#endif
@@ -392,6 +444,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::line(int x, int y, int x1, int y1, int x2,
int y2) {
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y(); x2 +=
origin_x(); y2 += origin_y();
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextAddLineToPoint(fl_gc, x2, y2);
@@ -400,6 +453,7 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::line(int x, int y, int x1, int y1, int x2, int
y2) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y(); x2 +=
origin_x(); y2 += origin_y();
MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x1, y1);
LineTo(fl_gc, x2, y2);
@@ -409,6 +463,7 @@
}
#else
void fltk3::XlibGraphicsDriver::line(int x, int y, int x1, int y1, int x2, int
y2) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y(); x2 +=
origin_x(); y2 += origin_y();
XPoint p[3];
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
@@ -420,6 +475,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::loop(int x, int y, int x1, int y1, int x2,
int y2) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y(); x2 +=
origin_x(); y2 += origin_y();
CGContextSetShouldAntialias(fl_gc, true);
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
@@ -430,6 +486,7 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::loop(int x, int y, int x1, int y1, int x2, int
y2) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y(); x2 +=
origin_x(); y2 += origin_y();
MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x1, y1);
LineTo(fl_gc, x2, y2);
@@ -437,6 +494,7 @@
}
#else
void fltk3::XlibGraphicsDriver::loop(int x, int y, int x1, int y1, int x2, int
y2) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y(); x2 +=
origin_x(); y2 += origin_y();
XPoint p[4];
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
@@ -449,6 +507,8 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::loop(int x, int y, int x1, int y1, int x2,
int y2, int x3, int y3) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y();
+ x2 += origin_x(); y2 += origin_y(); x3 += origin_x(); y3 += origin_y();
CGContextSetShouldAntialias(fl_gc, true);
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
@@ -460,6 +520,8 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::loop(int x, int y, int x1, int y1, int x2, int
y2, int x3, int y3) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y();
+ x2 += origin_x(); y2 += origin_y(); x3 += origin_x(); y3 += origin_y();
MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x1, y1);
LineTo(fl_gc, x2, y2);
@@ -468,6 +530,8 @@
}
#else
void fltk3::XlibGraphicsDriver::loop(int x, int y, int x1, int y1, int x2, int
y2, int x3, int y3) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y();
+ x2 += origin_x(); y2 += origin_y(); x3 += origin_x(); y3 += origin_y();
XPoint p[5];
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
@@ -481,6 +545,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::polygon(int x, int y, int x1, int y1, int
x2, int y2) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y(); x2 +=
origin_x(); y2 += origin_y();
CGContextSetShouldAntialias(fl_gc, true);
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
@@ -491,6 +556,7 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::polygon(int x, int y, int x1, int y1, int x2,
int y2) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y(); x2 +=
origin_x(); y2 += origin_y();
XPoint p[3];
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
@@ -500,6 +566,7 @@
}
#else
void fltk3::XlibGraphicsDriver::polygon(int x, int y, int x1, int y1, int x2,
int y2) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y(); x2 +=
origin_x(); y2 += origin_y();
XPoint p[4];
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
@@ -513,6 +580,8 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::polygon(int x, int y, int x1, int y1, int
x2, int y2, int x3, int y3) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y();
+ x2 += origin_x(); y2 += origin_y(); x3 += origin_x(); y3 += origin_y();
CGContextSetShouldAntialias(fl_gc, true);
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
@@ -524,6 +593,8 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::polygon(int x, int y, int x1, int y1, int x2,
int y2, int x3, int y3) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y();
+ x2 += origin_x(); y2 += origin_y(); x3 += origin_x(); y3 += origin_y();
XPoint p[4];
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
@@ -534,6 +605,8 @@
}
#else
void fltk3::XlibGraphicsDriver::polygon(int x, int y, int x1, int y1, int x2,
int y2, int x3, int y3) {
+ x += origin_x(); y += origin_y(); x1 += origin_x(); y1 += origin_y();
+ x2 += origin_x(); y2 += origin_y(); x3 += origin_x(); y3 += origin_y();
XPoint p[5];
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
@@ -548,14 +621,17 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::point(int x, int y) {
+ x += origin_x(); y += origin_y();
CGContextFillRect(fl_gc, CGRectMake(x - 0.5, y - 0.5, 1, 1) );
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::point(int x, int y) {
+ x += origin_x(); y += origin_y();
SetPixel(fl_gc, x, y, fl_RGB());
}
#else
void fltk3::XlibGraphicsDriver::point(int x, int y) {
+ x += origin_x(); y += origin_y();
XDrawPoint(fl_display, fl_window, fl_gc, clip_x(x), clip_x(y));
}
#endif
@@ -566,6 +642,7 @@
// Missing X call: (is this the fastest way to init a 1-rectangle region?)
// MSWindows equivalent exists, implemented inline in win32.h
fltk3::Region XRectangleRegion(int x, int y, int w, int h) {
+ x += origin_x(); y += origin_y();
XRectangle R;
clip_to_short(x, y, w, h);
R.x = x; R.y = y; R.width = w; R.height = h;
@@ -625,6 +702,7 @@
#if defined(__APPLE_QUARTZ__)
void fltk3::QuartzGraphicsDriver::push_clip(int x, int y, int w, int h) {
+ x += origin_x(); y += origin_y();
fltk3::Region r;
if (w > 0 && h > 0) {
r = XRectangleRegion(x,y,w,h);
@@ -641,6 +719,7 @@
}
#elif defined(WIN32)
void fltk3::GDIGraphicsDriver::push_clip(int x, int y, int w, int h) {
+ x += origin_x(); y += origin_y();
fltk3::Region r;
if (w > 0 && h > 0) {
r = XRectangleRegion(x,y,w,h);
@@ -656,6 +735,7 @@
}
#else
void fltk3::XlibGraphicsDriver::push_clip(int x, int y, int w, int h) {
+ x += origin_x(); y += origin_y();
fltk3::Region r;
if (w > 0 && h > 0) {
r = XRectangleRegion(x,y,w,h);
@@ -694,6 +774,7 @@
#if defined(__APPLE_QUARTZ__)
int fltk3::QuartzGraphicsDriver::not_clipped(int x, int y, int w, int h) {
+ x += origin_x(); y += origin_y();
if (x+w <= 0 || y+h <= 0) return 0;
fltk3::Region r = clip_region();
if (!r) return 1;
@@ -706,6 +787,7 @@
}
#elif defined(WIN32)
int fltk3::GDIGraphicsDriver::not_clipped(int x, int y, int w, int h) {
+ x += origin_x(); y += origin_y();
if (x+w <= 0 || y+h <= 0) return 0;
fltk3::Region r = clip_region();
if (!r) return 1;
@@ -721,6 +803,7 @@
}
#else
int fltk3::XlibGraphicsDriver::not_clipped(int x, int y, int w, int h) {
+ x += origin_x(); y += origin_y();
if (x+w <= 0 || y+h <= 0) return 0;
fltk3::Region r = clip_region();
if (!r) return 1;
@@ -734,6 +817,7 @@
// return rectangle surrounding intersection of this rectangle and clip:
#if defined(__APPLE_QUARTZ__)
int fltk3::QuartzGraphicsDriver::clip_box(int x, int y, int w, int h, int& X,
int& Y, int& W, int& H){
+ x += origin_x(); y += origin_y();
X = x; Y = y; W = w; H = h;
fltk3::Region r = clip_region();
if (!r) return 0;
@@ -752,10 +836,12 @@
W = int(u.size.width + 1);
H = int(u.size.height + 1);
if(CGRectIsEmpty(u)) W = H = 0;
+ X -= origin_x(); Y -= origin_y();
return ! CGRectEqualToRect(arg, u);
}
#elif defined(WIN32)
int fltk3::GDIGraphicsDriver::clip_box(int x, int y, int w, int h, int& X,
int& Y, int& W, int& H){
+ x += origin_x(); y += origin_y();
X = x; Y = y; W = w; H = h;
fltk3::Region r = clip_region();
if (!r) return 0;
@@ -786,10 +872,12 @@
}
DeleteObject(temp);
DeleteObject(rr);
+ X -= origin_x(); Y -= origin_y();
return ret;
}
#else
int fltk3::XlibGraphicsDriver::clip_box(int x, int y, int w, int h, int& X,
int& Y, int& W, int& H){
+ x += origin_x(); y += origin_y();
X = x; Y = y; W = w; H = h;
fltk3::Region r = clip_region();
if (!r) return 0;
@@ -810,6 +898,7 @@
X = rect.x; Y = rect.y; W = rect.width; H = rect.height;
XDestroyRegion(temp);
XDestroyRegion(rr);
+ X -= origin_x(); Y -= origin_y();
return 1;
}
#endif
Modified: branches/branch-3.0/src/fltk3/run.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/run.cxx 2012-04-28 00:46:24 UTC (rev
9407)
+++ branches/branch-3.0/src/fltk3/run.cxx 2012-04-29 19:10:11 UTC (rev
9408)
@@ -1033,6 +1033,23 @@
// values to account for nested windows. 'window' is the outermost
// window the event was posted to by the system:
static int send(int event, fltk3::Widget* to, fltk3::Window* window) {
+ /*
+
+ int dx = x(); int dy = y();
+
+ for (Widget* p = parent(); p; p = p->parent()) {
+ // we may want to ignore hiearchy parents in a browser. Not figured
+ // out how to do this yet.
+ dx += p->x();
+ dy += p->y();
+ }
+ int save_x = e_x;
+ int save_y = e_y;
+ e_x = e_x_root-dx;
+ e_y = e_y_root-dy;
+
+ */
+
int dx, dy;
int old_event = fltk3::e_number;
if (window) {
@@ -1041,8 +1058,11 @@
} else {
dx = dy = 0;
}
- for (const fltk3::Widget* w = to; w; w = w->parent())
- if (w->type()>=fltk3::WINDOW) {dx -= w->x(); dy -= w->y();}
+ for (const fltk3::Widget* w = to; w; w = w->parent()) {
+ if (w->type()>=fltk3::WINDOW || w->is_group_relative()) {
+ dx -= w->x(); dy -= w->y();
+ }
+ }
int save_x = fltk3::e_x; fltk3::e_x += dx;
int save_y = fltk3::e_y; fltk3::e_y += dy;
int ret = to->handle(fltk3::e_number = event);
@@ -1706,6 +1726,7 @@
}
fltk3::damage(fltk3::DAMAGE_CHILD);
}
+
void fltk3::Window::flush() {
make_current();
//if (damage() == fltk3::DAMAGE_EXPOSE && can_boxcheat(box())) fl_boxcheat =
this;
Modified: branches/branch-3.0/src/fltk3/vertex.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/vertex.cxx 2012-04-28 00:46:24 UTC (rev
9407)
+++ branches/branch-3.0/src/fltk3/vertex.cxx 2012-04-29 19:10:11 UTC (rev
9408)
@@ -98,6 +98,7 @@
double fltk3::GraphicsDriver::transform_dy(double x, double y) {return x*m.b +
y*m.d;}
void fltk3::GraphicsDriver::transformed_vertex0(COORD_T x, COORD_T y) {
+ x += origin_x(); y += origin_y();
if (!n || x != p[n-1].x || y != p[n-1].y) {
if (n >= p_size) {
p_size = p ? 2*p_size : 16;
@@ -197,7 +198,7 @@
void fltk3::GraphicsDriver::end_loop() {
fixloop();
- if (n>2) transformed_vertex((COORD_T)p[0].x, (COORD_T)p[0].y);
+ if (n>2) transformed_vertex((COORD_T)p[0].x-origin_x(),
(COORD_T)p[0].y-origin_y());
end_line();
}
Modified: branches/branch-3.0/test/subwindow.cxx
===================================================================
--- branches/branch-3.0/test/subwindow.cxx 2012-04-28 00:46:24 UTC (rev
9407)
+++ branches/branch-3.0/test/subwindow.cxx 2012-04-29 19:10:11 UTC (rev
9408)
@@ -112,6 +112,51 @@
return 0;
}
+class testgroup : public fltk3::Group {
+ int handle(int);
+ void draw();
+ int cx, cy; char key;
+ fltk3::Cursor crsr;
+public:
+ testgroup(fltk3::Boxtype b,int x,int y,int w,int h,const char *l)
+ : fltk3::Group(x,y,w,h,l) {box(b); key = 0;}
+ void use_cursor(fltk3::Cursor c) { crsr = c; }
+};
+
+void testgroup::draw() {
+#ifdef DEBUG
+ printf("%s : draw\n",label());
+#endif
+ Group::draw();
+#ifdef DEBUG_POS
+ if (key) fltk3::draw(&key, 1, cx, cy);
+#endif
+}
+
+int testgroup::handle(int e) {
+#ifdef DEBUG
+ if (e != fltk3::MOVE) printf("%s : %s\n",label(),fltk3::eventnames[e]);
+#endif
+ printf("%s : %d at %d, %d\n",label(), e, fltk3::event_x(), fltk3::event_y());
+ if (crsr!=fltk3::CURSOR_DEFAULT) {
+ if (e == fltk3::ENTER)
+ window()->cursor(crsr);
+ if (e == fltk3::LEAVE)
+ window()->cursor(fltk3::CURSOR_DEFAULT);
+ }
+ if (Group::handle(e)) return 1;
+ if (e == fltk3::FOCUS) return 1;
+ if (e == fltk3::PUSH) {fltk3::focus(this); return 1;}
+ if (e == fltk3::KEYBOARD && fltk3::event_text()[0]) {
+ key = fltk3::event_text()[0];
+ cx = fltk3::event_x();
+ cy = fltk3::event_y();
+ redraw();
+ return 1;
+ }
+ return 0;
+}
+
fltk3::MenuButton* popup;
const char* bigmess =
@@ -154,16 +199,26 @@
int main(int argc, char **argv) {
testwindow *window =
- new testwindow(fltk3::UP_BOX,400,400,"outer");
+ new testwindow(fltk3::UP_BOX,820,400,"outer");
new fltk3::ToggleButton(310,310,80,80,"&outer");
new EnterExit(10,310,80,80,"enterexit");
new fltk3::Input(160,310,140,25,"input1:");
new fltk3::Input(160,340,140,25,"input2:");
(new fltk3::MenuButton(5,150,80,25,"menu&1"))->add(bigmess);
+
+ (new fltk3::Box(fltk3::NO_BOX,150,0,520,100,
+ "A child fltk3::Window with children of its own may "
+ "be useful for imbedding controls into a GL or display "
+ "that needs a different visual."
+ )) -> align(fltk3::ALIGN_WRAP);
+
+ popup = new fltk3::MenuButton(0,0,400,400);
+ popup->type(fltk3::MenuButton::POPUP3);
+ popup->add("This|is|a popup|menu");
+ popup->add(bigmess);
+
testwindow *subwindow =
- new testwindow(fltk3::DOWN_BOX,100,100,200,200,"inner");
- //fltk3::Group *subwindow =
- // new fltk3::Group(100,100,200,200,"inner");
+ new testwindow(fltk3::DOWN_BOX,100,100,200,200,"fltk3::Window");
subwindow->box(fltk3::DOWN_BOX);
new fltk3::ToggleButton(110,110,80,80,"&inner");
new EnterExit(10,110,80,80,"enterexit");
@@ -171,20 +226,34 @@
new fltk3::Input(55,50,140,25,"input1:");
new fltk3::Input(55,80,140,25,"input2:");
subwindow->resizable(subwindow);
- window->resizable(subwindow);
subwindow->end();
subwindow->use_cursor(fltk3::CURSOR_HAND);
- (new fltk3::Box(fltk3::NO_BOX,0,0,400,100,
- "A child fltk3::Window with children of its own may "
- "be useful for imbedding controls into a GL or display "
- "that needs a different visual. There are bugs with the "
- "origins being different between drawing and events, "
- "which I hope I have solved."
- )) -> align(fltk3::ALIGN_WRAP);
- popup = new fltk3::MenuButton(0,0,400,400);
- popup->type(fltk3::MenuButton::POPUP3);
- popup->add("This|is|a popup|menu");
- popup->add(bigmess);
+
+ testgroup *subgroup2 =
+ new testgroup(fltk3::DOWN_BOX,310,100,200,200,"fltk3::Group,
GROUP_RELATIVE");
+ subgroup2->set_group_relative();
+ new fltk3::ToggleButton(110,110,80,80,"&inner");
+ new EnterExit(10,110,80,80,"enterexit");
+ (new fltk3::MenuButton(50,20,80,25,"menu&2"))->add(bigmess);
+ new fltk3::Input(55,50,140,25,"input1:");
+ new fltk3::Input(55,80,140,25,"input2:");
+ //subgroup2->resizable(subgroup2);
+ window->resizable(subgroup2);
+ subgroup2->end();
+ subgroup2->use_cursor(fltk3::CURSOR_HAND);
+
+ testgroup *subgroup3 =
+ new testgroup(fltk3::DOWN_BOX,520,100,200,200,"fltk3::Group,
Window-relative");
+ subgroup3->set_window_relative();
+ new fltk3::ToggleButton(630,210,80,80,"&inner");
+ new EnterExit(530,210,80,80,"enterexit");
+ (new fltk3::MenuButton(570,120,80,25,"menu&2"))->add(bigmess);
+ new fltk3::Input(575,150,140,25,"input1:");
+ new fltk3::Input(575,180,140,25,"input2:");
+ subgroup3->resizable(subgroup3);
+ subgroup3->end();
+ subgroup3->use_cursor(fltk3::CURSOR_HAND);
+
window->show(argc, argv);
return fltk3::run();
}
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit