|
Author: matt
Date: 2011-08-28 13:40:32 -0700 (Sun, 28 Aug 2011)
New Revision: 9020
Log:
Implemented Styles for two aspcts of a Widget (labelfont and labelsize).
Modified:
branches/branch-3.0/include/fltk3/Style.h
branches/branch-3.0/include/fltk3/Widget.h
branches/branch-3.0/src/fltk3/Style.cxx
branches/branch-3.0/src/fltk3/Widget.cxx
branches/branch-3.0/src/fltk3/labeltype.cxx
Modified: branches/branch-3.0/include/fltk3/Style.h
===================================================================
--- branches/branch-3.0/include/fltk3/Style.h 2011-08-28 15:30:35 UTC (rev 9019)
+++ branches/branch-3.0/include/fltk3/Style.h 2011-08-28 20:40:32 UTC (rev 9020)
@@ -32,6 +32,51 @@
#define FLTK3_STYLE_H
+#include "enumerations.h"
+
+
+namespace fltk3 {
+
+ class Style {
+
+ protected:
+
+ static unsigned int current_;
+
+ unsigned int version_;
+ Style *parent_;
+
+ Font labelfont_;
+ Fontsize labelsize_;
+
+ unsigned int private_:1;
+ unsigned int labelfont_set_:1;
+ unsigned int labelsize_set_:1;
+
+ void update();
+ void refresh() const { if (version_ != current_) ((Style*)this)->update(); }
+ void invalidate() { if (!private_) current_++; }
+
+ public:
+
+ Style();
+ Style(Style *parent);
+ ~Style();
+
+ Font labelfont() const { refresh(); return labelfont_;}
+ void labelfont(fltk3::Font f) { labelfont_=f; labelfont_set_ = 1; invalidate(); }
+ void clear_labelfont() { labelfont_set_=0; invalidate(); }
+
+ Fontsize labelsize() const { refresh(); return labelsize_;}
+ void labelsize(fltk3::Fontsize s) { labelsize_=s; labelsize_set_ = 1; invalidate(); }
+ void clear_labelsize() { labelsize_set_=0; invalidate(); }
+
+ Style *make_private();
+ };
+
+ extern Style default_style;
+};
+
#endif
//
Modified: branches/branch-3.0/include/fltk3/Widget.h
===================================================================
--- branches/branch-3.0/include/fltk3/Widget.h 2011-08-28 15:30:35 UTC (rev 9019)
+++ branches/branch-3.0/include/fltk3/Widget.h 2011-08-28 20:40:32 UTC (rev 9020)
@@ -33,6 +33,7 @@
#include "enumerations.h"
#include "Rectangle.h"
+#include "Style.h"
/**
\todo typedef's fl_intptr_t and fl_uintptr_t should be documented.
@@ -56,6 +57,7 @@
class Window;
class Image;
class GLWindow;
+ class Style;
/** Default callback type definition for all fltk widgets (by far the most used) */
typedef void (Callback)(Widget*, void*);
@@ -74,17 +76,16 @@
interface for very complex labels, containing html or vector graphics.
*/
class FLTK3_EXPORT Label : public Rectangle {
+
protected:
+ /** use all repeating graphics information from the style - never NULL */
+ Style *style_;
/** label text */
const char* labeltext_;
/** type of label. \see fltk3::Labeltype */
uchar labeltype_;
/** text color */
fltk3::Color labelcolor_;
- /** label font used in text */
- fltk3::Font labelfont_;
- /** size of label font */
- fltk3::Fontsize labelsize_;
/** alignment of label */
fltk3::Align align_;
/** various flags for the label and derived classes */
@@ -110,6 +111,14 @@
~Label();
+ /** Returns the current style. */
+ Style *style() { return style_; }
+ const Style *style() const { return style_; }
+ Style *private_style() { return (style_ = style_->make_private()); }
+
+ /** Set the current style. */
+ void style(Style *s) { style_ = s; }
+
/** Draws the label aligned to the given box */
void draw(int,int,int,int, fltk3::Align) const ;
@@ -169,7 +178,7 @@
\return current font used by the label
\see fltk3::Font
*/
- fltk3::Font labelfont() const {return labelfont_;}
+ fltk3::Font labelfont() const {return style()->labelfont();}
/** Sets the font to use.
Fonts are identified by indexes into a table. The default value
@@ -178,19 +187,19 @@
\param[in] f the new font for the label
\see fltk3::Font
*/
- void labelfont(fltk3::Font f) {labelfont_=f;}
+ void labelfont(fltk3::Font f) {private_style()->labelfont(f);}
/** Gets the font size in pixels.
The default size is 14 pixels.
\return the current font size
*/
- fltk3::Fontsize labelsize() const {return labelsize_;}
+ fltk3::Fontsize labelsize() const {return style()->labelsize();}
/** Sets the font size in pixels.
\param[in] pix the new font size
\see fltk3::Fontsize labelsize()
*/
- void labelsize(fltk3::Fontsize pix) {labelsize_=pix;}
+ void labelsize(fltk3::Fontsize pix) {private_style()->labelsize(pix);}
/** Gets the label type.
\return the current label type.
Modified: branches/branch-3.0/src/fltk3/Style.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Style.cxx 2011-08-28 15:30:35 UTC (rev 9019)
+++ branches/branch-3.0/src/fltk3/Style.cxx 2011-08-28 20:40:32 UTC (rev 9020)
@@ -27,8 +27,67 @@
#include <fltk3/Style.h>
-// nothing to see here yet
+unsigned int fltk3::Style::current_ = 0;
+fltk3::Style fltk3::default_style;
+
+
+fltk3::Style::Style() :
+ version_(current_),
+ parent_(0),
+ labelfont_(fltk3::HELVETICA),
+ labelsize_(fltk3::NORMAL_SIZE),
+ private_(0),
+ labelfont_set_(1),
+ labelsize_set_(1)
+{
+}
+
+
+fltk3::Style::Style(Style *parent) :
+ version_(current_),
+ parent_(parent),
+ labelfont_(parent->labelfont_),
+ labelsize_(parent->labelsize_),
+ private_(0),
+ labelfont_set_(0),
+ labelsize_set_(0)
+{
+}
+
+
+fltk3::Style::~Style()
+{
+}
+
+
+fltk3::Style *fltk3::Style::make_private()
+{
+ if (private_)
+ return this;
+ else {
+ Style *s = new Style(this);
+ s->private_ = 1;
+ return s;
+ }
+}
+
+
+void fltk3::Style::update()
+{
+ if (version_==current_ || parent_==0L)
+ return;
+ parent_->refresh();
+
+ if (!labelfont_set_)
+ labelfont_ = parent_->labelfont_;
+ if (!labelsize_set_)
+ labelsize_ = parent_->labelsize_;
+
+ version_ = current_;
+}
+
+
//
// End of "$Id$".
//
Modified: branches/branch-3.0/src/fltk3/Widget.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Widget.cxx 2011-08-28 15:30:35 UTC (rev 9019)
+++ branches/branch-3.0/src/fltk3/Widget.cxx 2011-08-28 20:40:32 UTC (rev 9020)
@@ -106,11 +106,10 @@
fltk3::Label::Label(int X, int Y, int W, int H, const char* L)
: fltk3::Rectangle(X, Y, W, H),
+ style_(&fltk3::default_style),
labeltext_(L),
-labeltype_(fltk3::NORMAL_LABEL),
+ labeltype_(fltk3::NORMAL_LABEL),
labelcolor_(fltk3::FOREGROUND_COLOR),
- labelfont_(fltk3::HELVETICA),
- labelsize_(fltk3::NORMAL_SIZE),
align_(fltk3::ALIGN_CENTER),
flags_(0),
textfont_(0),
@@ -123,11 +122,10 @@
fltk3::Label::Label(const fltk3::Label &s)
: fltk3::Rectangle(s),
+ style_(s.style_), // FIXME: do not just link to private styles
labeltext_(0L),
labeltype_(s.labeltype_),
labelcolor_(s.labelcolor_),
- labelfont_(s.labelfont_),
- labelsize_(s.labelsize_),
align_(s.align_),
flags_(s.flags_),
textfont_(s.textfont_),
@@ -147,10 +145,9 @@
fltk3::Label::Label()
: fltk3::Rectangle(),
+ style_(&fltk3::default_style),
labeltype_(fltk3::NORMAL_LABEL),
labelcolor_(fltk3::FOREGROUND_COLOR),
- labelfont_(fltk3::HELVETICA),
- labelsize_(fltk3::NORMAL_SIZE),
align_(fltk3::ALIGN_CENTER),
flags_(0),
textfont_(fltk3::HELVETICA),
Modified: branches/branch-3.0/src/fltk3/labeltype.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/labeltype.cxx 2011-08-28 15:30:35 UTC (rev 9019)
+++ branches/branch-3.0/src/fltk3/labeltype.cxx 2011-08-28 20:40:32 UTC (rev 9020)
@@ -144,12 +144,14 @@
*/
void fltk3::Widget::draw_label(int X, int Y, int W, int H, fltk3::Align a) const {
if (flags()&SHORTCUT_LABEL) fltk3::draw_shortcut = 1;
- fltk3::Label l1(*this);
if (!active_r()) {
+ fltk3::Label l1(*this);
l1.labelcolor( fltk3::inactive((fltk3::Color)l1.labelcolor()) );
if (l1.deimage()) l1.image(l1.deimage());
+ l1.draw(X,Y,W,H,a);
+ } else {
+ Label::draw(X,Y,W,H,a);
}
- l1.draw(X,Y,W,H,a);
fltk3::draw_shortcut = 0;
}
[ Direct Link to Message ] | |