Author: matt
Date: 2012-05-01 14:13:18 -0700 (Tue, 01 May 2012)
New Revision: 9424
Log:
Fixed bitmap drawing.
Modified:
branches/branch-3.0/include/fltk3/Adjuster.h
branches/branch-3.0/include/fltk3/Widget.h
branches/branch-3.0/src/fltk3/Adjuster.cxx
branches/branch-3.0/src/fltk3/Bitmap.cxx
branches/branch-3.0/src/fltk3/Widget.cxx
branches/branch-3.0/src/fltk3/rect.cxx
Modified: branches/branch-3.0/include/fltk3/Adjuster.h
===================================================================
--- branches/branch-3.0/include/fltk3/Adjuster.h 2012-05-01 20:14:04 UTC
(rev 9423)
+++ branches/branch-3.0/include/fltk3/Adjuster.h 2012-05-01 21:13:18 UTC
(rev 9424)
@@ -53,21 +53,34 @@
click decrements by 10 times the amount.
*/
class FLTK3_EXPORT Adjuster : public Valuator {
+
+ private:
int drag;
int ix;
int soft_;
+
protected:
void draw();
int handle(int);
void value_damage();
+
public:
+
+ /**
+ Creates a new fltk3::Adjuster widget using the given position,
+ size, and label string. It looks best if one of the dimensions is 3
+ times the other.
+ <P> Inherited destructor destroys the Valuator.
+ */
Adjuster(int X,int Y,int W,int H,const char *l=0);
+
/**
If "soft" is turned on, the user is allowed to drag the value outside
the range. If they drag the value to one of the ends, let go, then
grab again and continue to drag, they can get to any value. Default is
one.
*/
+
void soft(int s) {soft_ = s;}
/**
If "soft" is turned on, the user is allowed to drag the value outside
Modified: branches/branch-3.0/include/fltk3/Widget.h
===================================================================
--- branches/branch-3.0/include/fltk3/Widget.h 2012-05-01 20:14:04 UTC (rev
9423)
+++ branches/branch-3.0/include/fltk3/Widget.h 2012-05-01 21:13:18 UTC (rev
9424)
@@ -376,8 +376,7 @@
void draw_box(Boxtype t, Color c) const;
void draw_box(Boxtype t, int x,int y,int w,int h, Color c) const;
void draw_backdrop() const;
- /** draws a focus rectangle around the widget */
- void draw_focus() {draw_focus(box(),x(),y(),w(),h());}
+ void draw_focus();
void draw_focus(Boxtype t, int x,int y,int w,int h) const;
void draw_label() const;
void draw_label(int, int, int, int) const;
Modified: branches/branch-3.0/src/fltk3/Adjuster.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Adjuster.cxx 2012-05-01 20:14:04 UTC (rev
9423)
+++ branches/branch-3.0/src/fltk3/Adjuster.cxx 2012-05-01 21:13:18 UTC (rev
9424)
@@ -31,6 +31,8 @@
#include <fltk3/draw.h>
#include <fltk3/Wrapper.h>
+
+// three bitmaps for the arrow images
#include "fastarrow.h"
static fltk3::Bitmap fastarrow(fastarrow_bits, fastarrow_width,
fastarrow_height);
#include "mediumarrow.h"
@@ -38,10 +40,15 @@
#include "slowarrow.h"
static fltk3::Bitmap slowarrow(slowarrow_bits, slowarrow_width,
slowarrow_height);
+
// changing the value does not change the appearance:
-void fltk3::Adjuster::value_damage() {}
+void fltk3::Adjuster::value_damage()
+{
+}
-void fltk3::Adjuster::draw() {
+
+void fltk3::Adjuster::draw()
+{
int dx, dy, W, H, hor = (w()>=h());
if (hor) {
dx = W = w()/3;
@@ -50,23 +57,23 @@
dx = 0; W = w();
dy = H = h()/3;
}
- draw_box(Boxtype((drag==1?DOWN_BOX:box())|(hor?TIE_RIGHT:TIE_TOP)), x(),
y()+2*dy, W, H, color());
-
draw_box(Boxtype((drag==2?fltk3::DOWN_BOX:box())|(hor?TIE_LEFT|TIE_RIGHT:TIE_TOP|TIE_BOTTOM)),
x()+dx, y()+dy, W, H, color());
- draw_box(Boxtype((drag==3?fltk3::DOWN_BOX:box())|(hor?TIE_LEFT:TIE_BOTTOM)),
x()+2*dx, y(), W, H, color());
+ fltk3::Boxtype up = box(), dn = fltk3::down(box());
+ draw_box(Boxtype((drag==1?dn:up)|(hor?TIE_RIGHT:TIE_TOP)), 0, 2*dy, W, H,
color());
+
draw_box(Boxtype((drag==2?dn:up)|(hor?TIE_LEFT|TIE_RIGHT:TIE_TOP|TIE_BOTTOM)),
dx, dy, W, H, color());
+ draw_box(Boxtype((drag==3?dn:up)|(hor?TIE_LEFT:TIE_BOTTOM)), 2*dx, 0, W, H,
color());
if (active_r())
fltk3::color(selection_color());
else
fltk3::color(fltk3::inactive(selection_color()));
- fastarrow.draw(x()+(W-fastarrow_width)/2,
- y()+2*dy+(H-fastarrow_height)/2, W, H);
- mediumarrow.draw(x()+dx+(W-mediumarrow_width)/2,
- y()+dy+(H-mediumarrow_height)/2, W, H);
- slowarrow.draw(x()+2*dx+(W-slowarrow_width)/2,
- y()+(H-slowarrow_width)/2, W, H);
+ fastarrow.draw((W-fastarrow_width)/2, 2*dy+(H-fastarrow_height)/2, W, H);
+ mediumarrow.draw(dx+(W-mediumarrow_width)/2, dy+(H-mediumarrow_height)/2, W,
H);
+ slowarrow.draw(2*dx+(W-slowarrow_width)/2, (H-slowarrow_width)/2, W, H);
if (fltk3::focus() == this) draw_focus();
}
-int fltk3::Adjuster::handle(int event) {
+
+int fltk3::Adjuster::handle(int event)
+{
double v;
int delta;
int mx = fltk3::event_x();
@@ -76,18 +83,18 @@
if (fltk3::visible_focus()) fltk3::focus(this);
ix = mx;
if (w()>=h())
- drag = 3*(mx-x())/w() + 1;
+ drag = (3*mx)/w() + 1;
else
- drag = 3-3*(fltk3::event_y()-y()-1)/h();
- { fltk3::WidgetTracker wp(this);
- handle_push();
- if (wp.deleted()) return 1;
- }
+ drag = 3-3*(fltk3::event_y()-1)/h();
+ { fltk3::WidgetTracker wp(this);
+ handle_push();
+ if (wp.deleted()) return 1;
+ }
redraw();
return 1;
case fltk3::DRAG:
if (w() >= h()) {
- delta = x()+(drag-1)*w()/3; // left edge of button
+ delta = (drag-1)*w()/3; // left edge of button
if (mx < delta)
delta = mx-delta;
else if (mx > (delta+w()/3)) // right edge of button
@@ -95,10 +102,10 @@
else
delta = 0;
} else {
- if (mx < x())
+ if (mx < 0)
delta = mx-x();
- else if (mx > (x()+w()))
- delta = mx-x()-w();
+ else if (mx > +w())
+ delta = mx-w();
else
delta = 0;
}
@@ -148,14 +155,14 @@
return 0;
}
// break not required because of switch...
-
+
case fltk3::FOCUS:
case fltk3::UNFOCUS:
if (fltk3::visible_focus()) {
redraw();
return 1;
} else return 0;
-
+
case fltk3::ENTER :
case fltk3::LEAVE :
return 1;
@@ -163,14 +170,10 @@
return 0;
}
-/**
- Creates a new fltk3::Adjuster widget using the given position,
- size, and label string. It looks best if one of the dimensions is 3
- times the other.
- <P> Inherited destructor destroys the Valuator.
-*/
fltk3::Adjuster::Adjuster(int X, int Y, int W, int H, const char* l)
- : fltk3::Valuator(X, Y, W, H, l) {
+: fltk3::Valuator(X, Y, W, H, l)
+{
+ set_group_relative(); // FIXME: remove later
box(fltk3::UP_BOX);
step(1, 10000);
selection_color(fltk3::SELECTION_COLOR);
Modified: branches/branch-3.0/src/fltk3/Bitmap.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Bitmap.cxx 2012-05-01 20:14:04 UTC (rev
9423)
+++ branches/branch-3.0/src/fltk3/Bitmap.cxx 2012-05-01 21:13:18 UTC (rev
9424)
@@ -280,7 +280,7 @@
}
if (!bm->id_) bm->id_ = fl_create_bitmask(bm->w(), bm->h(), bm->array);
if (bm->id_ && fl_gc) {
- CGRect rect = { { X, Y }, { W, H } };
+ CGRect rect = { { X+origin_x(), Y+origin_y()}, { W, H } };
Fl_X::q_begin_image(rect, cx, cy, bm->w(), bm->h());
CGContextDrawImage(fl_gc, rect, (CGImageRef)bm->id_);
Fl_X::q_end_image();
Modified: branches/branch-3.0/src/fltk3/Widget.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Widget.cxx 2012-05-01 20:14:04 UTC (rev
9423)
+++ branches/branch-3.0/src/fltk3/Widget.cxx 2012-05-01 21:13:18 UTC (rev
9424)
@@ -216,6 +216,16 @@
if (callback_ == default_callback) cleanup_readqueue(this);
}
+
+/** draws a focus rectangle around the widget */
+void fltk3::Widget::draw_focus() {
+ if (is_group_relative()) {
+ draw_focus(box(),0,0,w(),h());
+ } else {
+ draw_focus(box(),x(),y(),w(),h());
+ }
+}
+
/** Draws a focus box for the widget at the given position and size */
void
fltk3::Widget::draw_focus(fltk3::Boxtype B, int X, int Y, int W, int H) const {
Modified: branches/branch-3.0/src/fltk3/rect.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/rect.cxx 2012-05-01 20:14:04 UTC (rev
9423)
+++ branches/branch-3.0/src/fltk3/rect.cxx 2012-05-01 21:13:18 UTC (rev
9424)
@@ -817,27 +817,32 @@
// 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){
+ int ret;
x += origin_x(); y += origin_y();
X = x; Y = y; W = w; H = h;
fltk3::Region r = clip_region();
- if (!r) return 0;
- CGRect arg = fl_cgrectmake_cocoa(x, y, w, h);
- CGRect u = CGRectMake(0,0,0,0);
- CGRect test;
- for(int i = 0; i < r->count; i++) {
- test = CGRectIntersection(r->rects[i], arg);
- if( ! CGRectIsEmpty(test) ) {
- if(CGRectIsEmpty(u)) u = test;
- else u = CGRectUnion(u, test);
+ if (!r) {
+ ret = 0;
+ } else {
+ CGRect arg = fl_cgrectmake_cocoa(x, y, w, h);
+ CGRect u = CGRectMake(0,0,0,0);
+ CGRect test;
+ for(int i = 0; i < r->count; i++) {
+ test = CGRectIntersection(r->rects[i], arg);
+ if( ! CGRectIsEmpty(test) ) {
+ if(CGRectIsEmpty(u)) u = test;
+ else u = CGRectUnion(u, test);
+ }
}
+ X = int(u.origin.x);
+ Y = int(u.origin.y);
+ W = int(u.size.width + 1);
+ H = int(u.size.height + 1);
+ if(CGRectIsEmpty(u)) W = H = 0;
+ ret = ! CGRectEqualToRect(arg, u);
}
- X = int(u.origin.x);
- Y = int(u.origin.y);
- 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);
+ return ret;
}
#elif defined(WIN32)
int fltk3::GDIGraphicsDriver::clip_box(int x, int y, int w, int h, int& X,
int& Y, int& W, int& H){
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit