* Modified the ScrollInfo structure for more modularity,
which helps doxygen docs be clear. * Changed loop in recalc_scrollbars() to loop thru /all/ children and skip over scrollbars, instead of assuming fix_scrollbar_order() has been called. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10220 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
7382173223
commit
afcd967fd8
@ -99,17 +99,33 @@ protected: // NEW (STR#1895)
|
||||
#else
|
||||
private: // OLD
|
||||
#endif
|
||||
// Structure to manage scrollbar and widget interior sizes.
|
||||
/**
|
||||
Structure to manage scrollbar and widget interior sizes.
|
||||
This is filled out by recalc_scrollbars() for use in calculations
|
||||
that need to know the visible scroll area size, etc.
|
||||
\note Availability in FLTK_ABI_VERSION 10303 or higher.
|
||||
*/
|
||||
typedef struct {
|
||||
int scrollsize; // the scrollsize (global|local)
|
||||
int innerbox_x, innerbox_y, innerbox_w, innerbox_h; // widget's inner box (excludes scrollbars)
|
||||
int innerchild_x, innerchild_y, innerchild_w, innerchild_h; // widget's inner box including scrollbars
|
||||
int child_l, child_r, child_b, child_t; // child bounding box: left/right/bottom/top
|
||||
int hneeded, vneeded; // hor + ver scrollbar visibility
|
||||
int hscroll_x, hscroll_y, hscroll_w, hscroll_h; // hor scrollbar size/position
|
||||
int vscroll_x, vscroll_y, vscroll_w, vscroll_h; // ver scrollbar size/position
|
||||
int hpos, hsize, hfirst, htotal; // hor scrollbar values (pos/size/first/total)
|
||||
int vpos, vsize, vfirst, vtotal; // ver scrollbar values (pos/size/first/total)
|
||||
/// A local struct to manage a region defined by xywh
|
||||
typedef struct { int x,y,w,h; } Fl_Region_XYWH;
|
||||
/// A local struct to manage a region defined by left/right/bottom/top
|
||||
typedef struct { int l,r,b,t; } Fl_Region_LRBT;
|
||||
/// A local struct to manage a scrollbar's xywh region and tab values
|
||||
typedef struct {
|
||||
int x,y,w,h;
|
||||
int pos; ///< scrollbar tab's position value
|
||||
int size; ///< scrollbar tab's size
|
||||
int first; ///< scrollbar tab's first value
|
||||
int total; ///< scrollbar tab's total value
|
||||
} Fl_Scrollbar_Data;
|
||||
int scrollsize; ///< the effective scrollbar thickness (local or global)
|
||||
Fl_Region_XYWH innerbox; ///< widget's inner box, excluding scrollbars
|
||||
Fl_Region_XYWH innerchild; ///< widget's inner box, including scrollbars
|
||||
Fl_Region_LRBT child; ///< child bounding box: left/right/bottom/top
|
||||
int hneeded; ///< horizontal scrollbar visibility
|
||||
int vneeded; ///< vertical scrollbar visibility
|
||||
Fl_Scrollbar_Data hscroll; ///< horizontal scrollbar region + values
|
||||
Fl_Scrollbar_Data vscroll; ///< vertical scrollbar region + values
|
||||
} ScrollInfo;
|
||||
void recalc_scrollbars(ScrollInfo &si);
|
||||
|
||||
|
@ -100,60 +100,61 @@ void Fl_Scroll::draw_clip(void* v,int X, int Y, int W, int H) {
|
||||
void Fl_Scroll::recalc_scrollbars(ScrollInfo &si) {
|
||||
|
||||
// inner box of widget (excluding scrollbars)
|
||||
si.innerbox_x = x()+Fl::box_dx(box());
|
||||
si.innerbox_y = y()+Fl::box_dy(box());
|
||||
si.innerbox_w = w()-Fl::box_dw(box());
|
||||
si.innerbox_h = h()-Fl::box_dh(box());
|
||||
si.innerbox.x = x()+Fl::box_dx(box());
|
||||
si.innerbox.y = y()+Fl::box_dy(box());
|
||||
si.innerbox.w = w()-Fl::box_dw(box());
|
||||
si.innerbox.h = h()-Fl::box_dh(box());
|
||||
|
||||
// accumulate a bounding box for all the children
|
||||
si.child_l = si.innerbox_x;
|
||||
si.child_r = si.innerbox_x;
|
||||
si.child_b = si.innerbox_y;
|
||||
si.child_t = si.innerbox_y;
|
||||
si.child.l = si.innerbox.x;
|
||||
si.child.r = si.innerbox.x;
|
||||
si.child.b = si.innerbox.y;
|
||||
si.child.t = si.innerbox.y;
|
||||
int first = 1;
|
||||
Fl_Widget*const* a = array();
|
||||
for (int i=children()-2; i--;) {
|
||||
for (int i=children(); i--;) {
|
||||
Fl_Widget* o = *a++;
|
||||
if ( o==&scrollbar || o==&hscrollbar ) continue;
|
||||
if ( first ) {
|
||||
first = 0;
|
||||
si.child_l = o->x();
|
||||
si.child_r = o->x()+o->w();
|
||||
si.child_b = o->y()+o->h();
|
||||
si.child_t = o->y();
|
||||
si.child.l = o->x();
|
||||
si.child.r = o->x()+o->w();
|
||||
si.child.b = o->y()+o->h();
|
||||
si.child.t = o->y();
|
||||
} else {
|
||||
if (o->x() < si.child_l) si.child_l = o->x();
|
||||
if (o->y() < si.child_t) si.child_t = o->y();
|
||||
if (o->x()+o->w() > si.child_r) si.child_r = o->x()+o->w();
|
||||
if (o->y()+o->h() > si.child_b) si.child_b = o->y()+o->h();
|
||||
if (o->x() < si.child.l) si.child.l = o->x();
|
||||
if (o->y() < si.child.t) si.child.t = o->y();
|
||||
if (o->x()+o->w() > si.child.r) si.child.r = o->x()+o->w();
|
||||
if (o->y()+o->h() > si.child.b) si.child.b = o->y()+o->h();
|
||||
}
|
||||
}
|
||||
|
||||
// Turn the scrollbars on and off as necessary.
|
||||
// See if children would fit if we had no scrollbars...
|
||||
{
|
||||
int X = si.innerbox_x;
|
||||
int Y = si.innerbox_y;
|
||||
int W = si.innerbox_w;
|
||||
int H = si.innerbox_h;
|
||||
int X = si.innerbox.x;
|
||||
int Y = si.innerbox.y;
|
||||
int W = si.innerbox.w;
|
||||
int H = si.innerbox.h;
|
||||
|
||||
si.scrollsize = scrollbar_size_ ? scrollbar_size_ : Fl::scrollbar_size();
|
||||
si.vneeded = 0;
|
||||
si.hneeded = 0;
|
||||
if (type() & VERTICAL) {
|
||||
if ((type() & ALWAYS_ON) || si.child_t < Y || si.child_b > Y+H) {
|
||||
if ((type() & ALWAYS_ON) || si.child.t < Y || si.child.b > Y+H) {
|
||||
si.vneeded = 1;
|
||||
W -= si.scrollsize;
|
||||
if (scrollbar.align() & FL_ALIGN_LEFT) X += si.scrollsize;
|
||||
}
|
||||
}
|
||||
if (type() & HORIZONTAL) {
|
||||
if ((type() & ALWAYS_ON) || si.child_l < X || si.child_r > X+W) {
|
||||
if ((type() & ALWAYS_ON) || si.child.l < X || si.child.r > X+W) {
|
||||
si.hneeded = 1;
|
||||
H -= si.scrollsize;
|
||||
if (scrollbar.align() & FL_ALIGN_TOP) Y += si.scrollsize;
|
||||
// recheck vertical since we added a horizontal scrollbar
|
||||
if (!si.vneeded && (type() & VERTICAL)) {
|
||||
if ((type() & ALWAYS_ON) || si.child_t < Y || si.child_b > Y+H) {
|
||||
if ((type() & ALWAYS_ON) || si.child.t < Y || si.child.b > Y+H) {
|
||||
si.vneeded = 1;
|
||||
W -= si.scrollsize;
|
||||
if (scrollbar.align() & FL_ALIGN_LEFT) X += si.scrollsize;
|
||||
@ -161,51 +162,51 @@ void Fl_Scroll::recalc_scrollbars(ScrollInfo &si) {
|
||||
}
|
||||
}
|
||||
}
|
||||
si.innerchild_x = X;
|
||||
si.innerchild_y = Y;
|
||||
si.innerchild_w = W;
|
||||
si.innerchild_h = H;
|
||||
si.innerchild.x = X;
|
||||
si.innerchild.y = Y;
|
||||
si.innerchild.w = W;
|
||||
si.innerchild.h = H;
|
||||
}
|
||||
|
||||
// calculate hor scrollbar position
|
||||
si.hscroll_x = si.innerchild_x;
|
||||
si.hscroll_y = (scrollbar.align() & FL_ALIGN_TOP)
|
||||
? si.innerbox_y
|
||||
: si.innerbox_y + si.innerbox_h - si.scrollsize;
|
||||
si.hscroll_w = si.innerchild_w;
|
||||
si.hscroll_h = si.scrollsize;
|
||||
si.hscroll.x = si.innerchild.x;
|
||||
si.hscroll.y = (scrollbar.align() & FL_ALIGN_TOP)
|
||||
? si.innerbox.y
|
||||
: si.innerbox.y + si.innerbox.h - si.scrollsize;
|
||||
si.hscroll.w = si.innerchild.w;
|
||||
si.hscroll.h = si.scrollsize;
|
||||
|
||||
// calculate ver scrollbar position
|
||||
si.vscroll_x = (scrollbar.align() & FL_ALIGN_LEFT)
|
||||
? si.innerbox_x
|
||||
: si.innerbox_x + si.innerbox_w - si.scrollsize;
|
||||
si.vscroll_y = si.innerchild_y;
|
||||
si.vscroll_w = si.scrollsize;
|
||||
si.vscroll_h = si.innerchild_h;
|
||||
si.vscroll.x = (scrollbar.align() & FL_ALIGN_LEFT)
|
||||
? si.innerbox.x
|
||||
: si.innerbox.x + si.innerbox.w - si.scrollsize;
|
||||
si.vscroll.y = si.innerchild.y;
|
||||
si.vscroll.w = si.scrollsize;
|
||||
si.vscroll.h = si.innerchild.h;
|
||||
|
||||
// calculate h/v scrollbar values (pos/size/first/total)
|
||||
si.hpos = si.innerchild_x - si.child_l;
|
||||
si.hsize = si.innerchild_w;
|
||||
si.hfirst = 0;
|
||||
si.htotal = si.child_r - si.child_l;
|
||||
if ( si.hpos < 0 ) { si.htotal += (-si.hpos); si.hfirst = si.hpos; }
|
||||
si.hscroll.pos = si.innerchild.x - si.child.l;
|
||||
si.hscroll.size = si.innerchild.w;
|
||||
si.hscroll.first = 0;
|
||||
si.hscroll.total = si.child.r - si.child.l;
|
||||
if ( si.hscroll.pos < 0 ) { si.hscroll.total += (-si.hscroll.pos); si.hscroll.first = si.hscroll.pos; }
|
||||
|
||||
si.vpos = si.innerchild_y - si.child_t;
|
||||
si.vsize = si.innerchild_h;
|
||||
si.vfirst = 0;
|
||||
si.vtotal = si.child_b - si.child_t;
|
||||
if ( si.vpos < 0 ) { si.vtotal += (-si.vpos); si.vfirst = si.vpos; }
|
||||
si.vscroll.pos = si.innerchild.y - si.child.t;
|
||||
si.vscroll.size = si.innerchild.h;
|
||||
si.vscroll.first = 0;
|
||||
si.vscroll.total = si.child.b - si.child.t;
|
||||
if ( si.vscroll.pos < 0 ) { si.vscroll.total += (-si.vscroll.pos); si.vscroll.first = si.vscroll.pos; }
|
||||
|
||||
// printf("DEBUG --- ScrollInfo ---\n");
|
||||
// printf("DEBUG scrollsize: %d\n", si.scrollsize);
|
||||
// printf("DEBUG hneeded, vneeded: %d %d\n", si.hneeded, si.vneeded);
|
||||
// printf("DEBUG innerbox xywh: %d %d %d %d\n", si.innerbox_x, si.innerbox_y, si.innerbox_w, si.innerbox_h);
|
||||
// printf("DEBUG innerchild xywh: %d %d %d %d\n", si.innerchild_x, si.innerchild_y, si.innerchild_w, si.innerchild_h);
|
||||
// printf("DEBUG child lrbt: %d %d %d %d\n", si.child_l, si.child_r, si.child_b, si.child_t);
|
||||
// printf("DEBUG hscroll xywh: %d %d %d %d\n", si.hscroll_x, si.hscroll_y, si.hscroll_w, si.hscroll_h);
|
||||
// printf("DEBUG vscroll xywh: %d %d %d %d\n", si.vscroll_x, si.vscroll_y, si.vscroll_w, si.vscroll_h);
|
||||
// printf("DEBUG horz scroll vals: %d %d %d %d\n", si.hpos, si.hsize, si.hfirst, si.htotal);
|
||||
// printf("DEBUG vert scroll vals: %d %d %d %d\n", si.vpos, si.vsize, si.vfirst, si.vtotal);
|
||||
// printf("DEBUG innerbox.x, si.innerbox.y, si.innerbox.w,si.innerbox.h);
|
||||
// printf("DEBUG innerchild.xywh: %d %d %d %d\n", si.innerchild.x, si.innerchild.y, si.innerchild.w, si.innerchild.h);
|
||||
// printf("DEBUG child lrbt: %d %d %d %d\n", si.child.l, si.child.r, si.child.b, si.child.t);
|
||||
// printf("DEBUG hscroll xywh: %d %d %d %d\n", si.hscroll.x, si.hscroll.y, si.hscroll.w, si.hscroll.h);
|
||||
// printf("DEBUG vscroll xywh: %d %d %d %d\n", si.vscroll.x, si.vscroll.y, si.vscroll.w, si.vscroll.h);
|
||||
// printf("DEBUG horz scroll vals: %d %d %d %d\n", si.hscroll.pos, si.hscroll.size, si.hscroll.first, si.hscroll.total);
|
||||
// printf("DEBUG vert scroll vals: %d %d %d %d\n", si.vscroll.pos, si.vscroll.size, si.vscroll.first, si.vscroll.total);
|
||||
// printf("DEBUG \n");
|
||||
}
|
||||
|
||||
@ -286,7 +287,7 @@ void Fl_Scroll::draw() {
|
||||
}
|
||||
else if (!si.vneeded && scrollbar.visible()) {
|
||||
scrollbar.clear_visible();
|
||||
draw_clip(this, si.vscroll_x, si.vscroll_y, si.vscroll_w, si.vscroll_h);
|
||||
draw_clip(this, si.vscroll.x, si.vscroll.y, si.vscroll.w, si.vscroll.h);
|
||||
d = FL_DAMAGE_ALL;
|
||||
}
|
||||
if (si.hneeded && !hscrollbar.visible()) {
|
||||
@ -295,7 +296,7 @@ void Fl_Scroll::draw() {
|
||||
}
|
||||
else if (!si.hneeded && hscrollbar.visible()) {
|
||||
hscrollbar.clear_visible();
|
||||
draw_clip(this, si.hscroll_x, si.hscroll_y, si.hscroll_w, si.hscroll_h);
|
||||
draw_clip(this, si.hscroll.x, si.hscroll.y, si.hscroll.w, si.hscroll.h);
|
||||
d = FL_DAMAGE_ALL;
|
||||
}
|
||||
else if ( hscrollbar.h() != si.scrollsize || scrollbar.w() != si.scrollsize ) {
|
||||
@ -303,13 +304,13 @@ void Fl_Scroll::draw() {
|
||||
d = FL_DAMAGE_ALL;
|
||||
}
|
||||
|
||||
scrollbar.resize(si.vscroll_x, si.vscroll_y, si.vscroll_w, si.vscroll_h);
|
||||
oldy = yposition_ = si.vpos; // si.innerchild_y - si.child_t;
|
||||
scrollbar.value(si.vpos, si.vsize, si.vfirst, si.vtotal);
|
||||
scrollbar.resize(si.vscroll.x, si.vscroll.y, si.vscroll.w, si.vscroll.h);
|
||||
oldy = yposition_ = si.vscroll.pos; // si.innerchild.y - si.child.t;
|
||||
scrollbar.value(si.vscroll.pos, si.vscroll.size, si.vscroll.first, si.vscroll.total);
|
||||
|
||||
hscrollbar.resize(si.hscroll_x, si.hscroll_y, si.hscroll_w, si.hscroll_h);
|
||||
oldx = xposition_ = si.hpos; // si.innerchild_x - si.child_l;
|
||||
hscrollbar.value(si.hpos, si.hsize, si.hfirst, si.htotal);
|
||||
hscrollbar.resize(si.hscroll.x, si.hscroll.y, si.hscroll.w, si.hscroll.h);
|
||||
oldx = xposition_ = si.hscroll.pos; // si.innerchild.x - si.child.l;
|
||||
hscrollbar.value(si.hscroll.pos, si.hscroll.size, si.hscroll.first, si.hscroll.total);
|
||||
}
|
||||
|
||||
// draw the scrollbars:
|
||||
|
Loading…
Reference in New Issue
Block a user