Ian MacArthur schrieb:
> That still does not address the more general issue of being able to
> "zoom" the entire app on the fly
You also asked how to realise it for FLTK 1.3 and I thougt about it.
It is not a real problem to add this functionality, but it is a problem
to keep it light:
There is a basic problem - when resizing back and forth, the sizes start
to drift, when they are replaced by new resized values. It is necessary
to keep the original values and calculate the current value out of
current ratio of widget sizes:
Sn= (S0 * hn)/ h0
Because of integer division it is important to use brackets!
So at first glance it seems to be necessary to add new data. But there
is a way to avoid this, when pushing calculation of current size to
query of current size:
Fl_Fontsize Fl_Widget::textsize() const
{ return h0 ? (l0 * h())/h0 : l0; }
Now it is only necessary to remember initial height. h0 can be used to
switch off zoom or to change current factor.
But another problem remained - Fl_Label is an own object, that doesn't
use method Fl_Widget::labelsize(), so it still remains necessary to
remember l0 and update the Fl_Label::labelsize_ when resizing.
Also the derived classes don't use textsize of Fl_Widget and if adding
textsize_ to Fl_Widget, it is necessary to patch all classes using
textsize_.
So it is necessary, to use the existing methods the way they are and to
update the existing values when resizing.
The appended patch realises this for Fl_Widget and after rebuilding FLTK
all widgets will zoom their fonts, until h0 is cleared
(pWidget->H0(0);). This is very basic (e.g. doesn't take care of ratio),
but it is also very easy to realise.
But this is to start discussion and was not my final goal. I wanted to
use format objects every widget is pointing to. This might make FLTK
lighter, because it would get rid of every widgets formats - normally
all widgets inside of a group use the same format, so they all could use
the same format object. The trick is, when you change the format, all
related widgets will change too at once and wherever they are.
I was going to realise this, using a template, but should I figure out,
how to change FLTK this way? This might be more useful, than creating my
own single solution.
--- ./fltk-1.3_Original/FL/Fl_Widget.H 2011-04-24 19:09:41.000000000 +0200
+++ ./fltk-1.3/FL/Fl_Widget.H 2012-04-14 12:39:30.704400000 +0200
@@ -113,6 +113,7 @@
Fl_Callback* callback_;
void* user_data_;
int x_,y_,w_,h_;
+ int h0, l0, t0; // Initial heigth, initial labelsize, initial
textsize
Fl_Label label_;
unsigned int flags_;
Fl_Color color_;
@@ -130,7 +131,6 @@
Fl_Widget& operator=(const Fl_Widget &);
protected:
-
/** Creates a widget at the given position and size.
The Fl_Widget is a protected constructor, but all derived widgets have a
@@ -503,6 +503,17 @@
*/
void labelsize(Fl_Fontsize pix) {label_.size=pix;}
+ /** virtual text methods to access methods of derived widgets
+ *
+ */
+ virtual Fl_Font textfont() const {return label_.font;}
+ virtual void textfont(Fl_Font f) {label_.font=f;}
+ virtual Fl_Fontsize textsize() const { return label_.size; }
+ virtual void textsize(Fl_Fontsize pix) {label_.size=pix;}
+
+ void H0(int val) { h0= val; }
+ int H0() const { return h0; }
+
/** Gets the image that is used as part of the widget label.
This image is used when drawing the widget in the active state.
\return the current image
--- ./fltk-1.3_Original/src/Fl_Widget.cxx 2010-12-02 18:58:58.000000000
+0100
+++ ./fltk-1.3/src/Fl_Widget.cxx 2012-04-14 12:41:59.516501000 +0200
@@ -132,12 +132,16 @@
color_ = FL_GRAY;
color2_ = FL_GRAY;
when_ = FL_WHEN_RELEASE;
-
+ h0 = H;
+ l0 = FL_NORMAL_SIZE;
+ t0 = FL_NORMAL_SIZE;
parent_ = 0;
if (Fl_Group::current()) Fl_Group::current()->add(this);
}
void Fl_Widget::resize(int X, int Y, int W, int H) {
+ labelsize(h0 ? (l0 * h())/h0 : l0);
+ textsize(h0 ? (t0 * h())/ h0 : t0);
x_ = X; y_ = Y; w_ = W; h_ = H;
}
_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk