>
> For download, all of the code is inside of
> http://www.tantec.de/komponenten/FLTK/font_size/
>
> Please take care of Readme.txt and I need to point out, that I didn't
> succeed in creating a makefile working for windows.
>
> There are lots of german words and comments, but I think, we can start
> diskussion without need to translate it first. Missing explanations
> will come when up to date - for the moment I'm trying to start the
> existing stuff... ;o)
>
> Also saving and restore of settings is not mentioned. For use in FLTK it
> might be more easy, but I think, this is a good point to start.
Thanks for your contribution I did something like that too and got the same
problem you've got and this is way I'm proposing add a bit more of cheap_rtti
to fltk.
I finally managed to have search through inheritance too, with it we can do
this:
------------
// generated by Fast Light User Interface Designer (fluid) version 1.0300
#ifndef resizablebyfont_h
#define resizablebyfont_h
#include <FL/Fl.H>
#include <vector>
typedef struct {
int x, y, w, h;
Fl_Fontsize labelsize, textsize;
Fl_Widget *wdg;
} st_size;
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Browser.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Button.H>
class Resizable_Window : public Fl_Double_Window {
void _Resizable_Window();
public:
Resizable_Window(int X, int Y, int W, int H, const char *L = 0);
Resizable_Window(int W, int H, const char *L = 0);
private:
void cb_Save_i(Fl_Button*, void*);
static void cb_Save(Fl_Button*, void*);
void cb_Cancel_i(Fl_Button*, void*);
static void cb_Cancel(Fl_Button*, void*);
public:
Fl_Input *font_size;
protected:
std::vector<st_size> sizes_at_start;
public:
void resize(int x, int y, int w, int h);
};
#endif
----------------------
// generated by Fast Light User Interface Designer (fluid) version 1.0300
#include "resizablebyfont.h"
#include <FL/fl_ask.h>
void Resizable_Window::cb_Save_i(Fl_Button*, void*) {
//do resize
//fl_alert("resize");
char buf[32];
int value = atoi(font_size->value());
itoa(--value, buf, 10);
font_size->value(buf);
}
void Resizable_Window::cb_Save(Fl_Button* o, void* v) {
((Resizable_Window*)(o->parent()))->cb_Save_i(o,v);
}
void Resizable_Window::cb_Cancel_i(Fl_Button*, void*) {
//do resize
fl_alert("resize");
}
void Resizable_Window::cb_Cancel(Fl_Button* o, void* v) {
((Resizable_Window*)(o->parent()))->cb_Cancel_i(o,v);
}
Resizable_Window::Resizable_Window(int X, int Y, int W, int H, const char *L)
: Fl_Double_Window(X, Y, W, H, L) {
_Resizable_Window();
}
Resizable_Window::Resizable_Window(int W, int H, const char *L)
: Fl_Double_Window(0, 0, W, H, L) {
clear_flag(16);
_Resizable_Window();
}
void Resizable_Window::_Resizable_Window() {
this->box(FL_FLAT_BOX);
this->color(FL_BACKGROUND_COLOR);
this->selection_color(FL_BACKGROUND_COLOR);
this->labeltype(FL_NO_LABEL);
this->labelfont(0);
this->labelsize(14);
this->labelcolor(FL_FOREGROUND_COLOR);
this->align(Fl_Align(FL_ALIGN_TOP));
this->when(FL_WHEN_RELEASE);
{ new Fl_Browser(25, 25, 155, 304);
} // Fl_Browser* o
{ new Fl_Input(260, 30, 285, 24, "Name");
} // Fl_Input* o
{ new Fl_Input(260, 70, 285, 25, "Address");
} // Fl_Input* o
{ new Fl_Input(260, 105, 75, 25, "ZIP");
} // Fl_Input* o
{ new Fl_Input(405, 105, 140, 25, "City");
} // Fl_Input* o
{ Fl_Input* o = new Fl_Input(260, 140, 285, 153, "Notes");
o->type(4);
} // Fl_Input* o
{ Fl_Button* o = new Fl_Button(260, 303, 100, 29, "Save");
o->callback((Fl_Callback*)cb_Save);
} // Fl_Button* o
{ Fl_Button* o = new Fl_Button(450, 303, 95, 29, "Cancel");
o->callback((Fl_Callback*)cb_Cancel);
} // Fl_Button* o
{ font_size = new Fl_Input(374, 302, 61, 30);
font_size->type(2);
font_size->value("12");
} // Fl_Input* font_size
end();
char const *p2 = Fl_Input_::className();
//fl_alert(p2);
for(int i=0; i < this->children(); i++)
{
st_size tmp;
tmp.wdg = this->child(i);
tmp.x = tmp.wdg->x();
tmp.y = tmp.wdg->y();
tmp.w = tmp.wdg->w();
tmp.h = tmp.wdg->h();
tmp.labelsize = tmp.wdg->labelsize();
if (tmp.wdg->inherits_from(p2)){
//fl_alert("Fl_Input on start");
tmp.textsize = ((Fl_Input*)tmp.wdg)->textsize();
}
sizes_at_start.push_back(tmp);
}
}
void Resizable_Window::resize(int x, int y, int w, int h) {
Fl_Double_Window::resize(x,y,w,h);
char const *p2 = Fl_Input_::className();
for(unsigned i=0; i < sizes_at_start.size(); i++)
{
const st_size& tmp = sizes_at_start[i];
//float xratio = this->w() / w;
float fh = tmp.h;
float yratio = tmp.wdg->h() / fh;
tmp.wdg->labelsize( tmp.labelsize * yratio);
if (tmp.wdg->inherits_from(p2)){
//fl_alert("Fl_Input on resize");
((Fl_Input*)tmp.wdg)->textsize( tmp.textsize * yratio);
}
}
}
int main(int argc, char **argv) {
Resizable_Window* w;
{ Resizable_Window* o = new Resizable_Window(595, 370, "Resizabe font by
+/-");
w = o;
o->box(FL_FLAT_BOX);
o->color(FL_BACKGROUND_COLOR);
o->selection_color(FL_BACKGROUND_COLOR);
o->labeltype(FL_NO_LABEL);
o->labelfont(0);
o->labelsize(14);
o->labelcolor(FL_FOREGROUND_COLOR);
o->align(Fl_Align(FL_ALIGN_TOP));
o->when(FL_WHEN_RELEASE);
o->end();
o->resizable(o);
} // Resizable_Window* o
w->show(argc, argv);
return Fl::run();
}
------------
struct st_cheap_rtti {
const char *class_name;
st_cheap_rtti *(*inherits_from_func)(void);
};
#define DECLARE_CLASS_CHEAP_RTTI_1(a1class_name)
DECLARE_CLASS_CHEAP_RTTI_00(a1class_name, , 0)
#define DECLARE_CLASS_CHEAP_RTTI_2(a2class_name, a2base_class) \
DECLARE_CLASS_CHEAP_RTTI_00(a2class_name, : public a2base_class,
&a2base_class::cheap_rtti_info)
#define DECLARE_CLASS_CHEAP_RTTI_00(aclass_name, ainheritage, abase_class) \
class FL_EXPORT aclass_name ainheritage {\
public:\
static st_cheap_rtti *cheap_rtti_info() {\
static st_cheap_rtti scr = {#aclass_name, abase_class};\
return &scr;\
};\
static const char *className(void) {return
aclass_name::cheap_rtti_info()->class_name;}; \
virtual const char *classId(void) {return aclass_name::className();};\
virtual int inherits_from(const char *aclass_id) {\
st_cheap_rtti *cri = aclass_name::cheap_rtti_info();\
if (aclass_id == cri->class_name) return 1;\
do {\
cri = (*cri->inherits_from_func)();\
if (!cri) break;\
if (aclass_id == cri->class_name) return 1;\
} while (cri->inherits_from_func);\
return 0;\
}\
private:
-----------------
//Fl_Widget.H
//class FL_EXPORT Fl_Widget {
DECLARE_CLASS_CHEAP_RTTI_1(Fl_Widget)
------------------
//Fl_Input.h
//class FL_EXPORT Fl_Input : public Fl_Input_ {
DECLARE_CLASS_CHEAP_RTTI_2(Fl_Input, Fl_Input_)
------------------
I'm going to apply it to every class declaration that inherit's from Fl_Widget
directly or indirectly.
I'm proposing to add this to official FLTK distribution.
Again I want to remark that with this macros in place of class declaration will
be easy to extend FLTK for specific needs.
Thanks again for any comment/enhancement !
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk