Edzard Egberts schrieb:
He also could wait until tomorrow
not really necessary.
fl_basic_font_size< Fl_Window > Window(400, 200);
Window.resizable(&Window);
new Fl_Box(100, 100, 100, 25, "Hello World");
Window.end();
Window.show();
return Fl::run();
If you don't want to apply the template directly:
typedef f_font_size::f_basic_font_size< Fl_Double_Window >
Fl_Double_Resize_Window;
This is current state and I think it is almost finished. There are some
additional classes missing, like a FL_Font_Dialog() for changing fonts
and I want to figure out some additional details, but for the OP this
should work:
//----------------------------------------------------------------------------
// Projekt Code by Ed
//
// i_fonts_dialog.h
// - Interface f�r Fl_Fonts_Dialog
//
// Copyright � 2003 by Edzard Egberts
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// Static linking of this library (or any modified version) to your software
// is explicitly allowed.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//----------------------------------------------------------------------------
#ifndef i_fonts_dialog_h
#define i_fonts_dialog_h
#include <iosfwd>
#include <string>
#include <FL/Enumerations.H>
#include <FL/Fl_Widget.H>
class Fl_Window;
class Fl_Group;
/*
Overview:
The following interfaces are ment to adjust labelfont/textfont and
labelsize/textsize of FLTK dialogs.
For realising these adjustments there is a dialog Fl_Fonts_Dialog,
which uses interface
i_fonts_dialog to access the dialog to be changed.
When adjusting for each widget the fonts and sizes must be set. Because
these methods
are only for sure defined for labels and not for texts there is an
interface i_font_size. You
can use it to add adjustment interface to self defined widgets.
Because the adjustment should not only affekt the main window, but also
subwindows and
other windows without adjusting each of them, there is an interface
f_basic_font_size
for transfer of current settings. It will be queried by interface
i_local_font_size,
which takes over the settings to another dialog. The dialog must be
inherited by the
i_local_font_size, or must be given to an i_local_font_size and a
pointer to
f_basic_font_size must be delivered to it. After that it takes over the
settings,
when Update_Font_Size() is called.
In speciality the windows size must be cared of. When a window was
resized and also get
taller textsizes, also the subwindow must be resized, because otherwise
the taller texts
won't fit into the small window. Because of that the textsize refers to
original window size.
*/
namespace f_font_size
{
//============================================================================
// General Functions for Widgets
//
// cast to text
int Get_Text_Size(Fl_Widget* pWdg);
bool Set_Text_Size(Fl_Widget* pWdg, int TS);
void Set_Text_Font(Fl_Widget* pWdg, Fl_Font Txt_Font);
Fl_Font Get_Text_Font(Fl_Widget* pWdg);
// Resize and fonts of all pWdg and all widgets inside
void Resize_Fonts(Fl_Widget* pWdg, int Labelsize, int Textsize);
void Set_Fonts(Fl_Widget* pWdg, Fl_Font Lbl_Font, Fl_Font Txt_Font);
// Operate all existing windows:
void Resize_Fonts(int Labelsize, int Textsize);
void Set_Fonts(Fl_Font Lbl_Font, Fl_Font Txt_Font);
//============================================================================
class dt_font_size
{ // font size data
public:
dt_font_size(Fl_Font Lbl_Font= FL_HELVETICA, Fl_Font
Txt_Font= FL_HELVETICA, int Lbl_Size= 14, int Txt_Size= 14):
m_Lbl_Font(Lbl_Font), m_Txt_Font(Txt_Font),
m_Lbl_Size(Lbl_Size), m_Txt_Size(Txt_Size)
{}
inline Fl_Font Lbl_Font() const
{ return m_Lbl_Font; }
inline Fl_Font Txt_Font() const
{ return m_Txt_Font; }
inline int Lbl_Size() const
{ return m_Lbl_Size; }
inline int Txt_Size() const
{ return m_Txt_Size; }
inline void Lbl_Font(Fl_Font F)
{ m_Lbl_Font= F; }
inline void Txt_Font(Fl_Font F)
{ m_Txt_Font= F; }
inline void Lbl_Size(int S)
{ m_Lbl_Size= S; }
inline void Txt_Size(int S)
{ m_Txt_Size= S; }
void Set_Local_Fonts(Fl_Font Labelfont, int Labelsize,
Fl_Font Textfont, int Textsize);
void Get_Settings(Fl_Widget* pW);
void Read(std::istream& In);
void Write(std::ostream& Out);
protected:
Fl_Font m_Lbl_Font;
// labelfont
Fl_Font m_Txt_Font;
// textfont
int m_Lbl_Size;
// labelsize
int m_Txt_Size;
// textsize
};
//------------------------------------------------------------------------------
class dt_window
{ // window data
public:
dt_window(int x, int y, int w, int h, const char* pT= ""):
m_x0(x), m_y0(y), m_w0(w), m_h0(h)
{}
inline int x0() const
{ return m_x0; }
inline int y0() const
{ return m_y0; }
inline int w0() const
{ return m_w0; }
inline int h0() const
{ return m_h0; }
inline void x0(int x)
{ m_x0= x; }
inline void y0(int y)
{ m_y0= y; }
inline void w0(int w)
{ m_w0= w; }
inline void h0(int h)
{ m_h0= h; }
void Read(std::istream& In);
void Write(std::ostream& Out);
protected:
int m_x0;
// original position x
int m_y0;
// original position x
int m_w0;
// original width
int m_h0;
// original heigt
};
//============================================================================
struct i_font_size
{ // Interface for adjustment of fonts and sizes for self defined
widgets
virtual ~i_font_size() {}
virtual unsigned char textsize() const= 0;
virtual Fl_Font textfont() const= 0;
virtual void textsize(unsigned char Size)= 0;
virtual void textfont(Fl_Font Font)= 0;
};
//============================================================================
template < class T > class f_basic_font_size: public T, public dt_window
{ // Interface for adjustment of fonts and sizes. Can be added to
each kind of widget
// for control of local fonts setting, especially to windows
for control of whole window content.
public:
f_basic_font_size(int w, int h, const char* lbl= 0):
T(w, h, lbl),
dt_window(-1, -1, w, h, lbl),
mp_Format(0)
{}
f_basic_font_size(int x, int y, int w, int h, const
char* lbl= 0):
T(x, y, w, h, lbl), // initialise Widget
dt_window(-1, -1, w, h, lbl),
mp_Format(0)
{}
virtual ~f_basic_font_size() {}
inline dt_font_size* pFormat() {
return mp_Format; }
inline void pFormat(dt_font_size* pF) { mp_Format=
pF; }
//------------------------------------------------------------------------------
void Get_Size_From(const f_basic_font_size& FS)
{ // Take zoom, but keep ratio:
int nh= int(double(m_h0) *
double(FS.h())/double(FS.h0()) + 0.5); // new h from widget
int nw= int(double(m_w0) *
double(nh)/double(m_h0) + 0.5); // new w from ration
T* pT= dynamic_cast< T* >(this);
if (pT) pT->resize(pT->x(), pT->y(), nw, nh);
}
//------------------------------------------------------------------------------
void Update()
{ // Update Format
if (mp_Format)
{ // Format is given
if (T* pT= dynamic_cast< T* >(this))
{ // Cast to widget TODO: New
size by factor to keep different local settings
Set_Fonts(pT,
mp_Format->Lbl_Font(), mp_Format->Txt_Font());
Resize_Fonts(pT,
mp_Format->Lbl_Size(), mp_Format->Txt_Size());
}
}
}
//------------------------------------------------------------------------------
virtual void resize(int x, int y, int w, int h)
{ // resize
T::resize(x, y, w, h); //
Resize widget
if (mp_Format)
{ // Text soll bei resize gezoomt werden
Resize_Fonts( // Start mit this, alle
tieferen Widgets �ndern
this,
double(mp_Format->Lbl_Size() *
double(h)/double(m_h0) + 0.5),
double(mp_Format->Txt_Size() *
double(h)/double(m_h0) + 0.5));
}
}
protected:
dt_font_size* mp_Format; //
Pointer to format of current resize factor and font
};
};
#endif
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk