Author: matt
Date: 2012-07-04 08:10:05 -0700 (Wed, 04 Jul 2012)
New Revision: 9633
Log:
FLTK3: moved color, color2, and box from widget into the style class. Now we 
need to create default styles for the various widgets.

Modified:
   branches/branch-3.0/include/FL/Fl_Widget.H
   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/boxtype.cxx

Modified: branches/branch-3.0/include/FL/Fl_Widget.H
===================================================================
--- branches/branch-3.0/include/FL/Fl_Widget.H  2012-07-04 09:46:59 UTC (rev 
9632)
+++ branches/branch-3.0/include/FL/Fl_Widget.H  2012-07-04 15:10:05 UTC (rev 
9633)
@@ -604,11 +604,11 @@
   }
   
   Fl_Color color2() const {
-    return fltk3::_3to1_color(((fltk3::Widget_I*)_p)->color2());
+    return fltk3::_3to1_color(((fltk3::Widget_I*)_p)->selection_color());
   }
   
   void color2(unsigned a) {
-    ((fltk3::Widget_I*)_p)->color2( fltk3::_1to3_color(a) );
+    ((fltk3::Widget_I*)_p)->selection_color( fltk3::_1to3_color(a) );
   }
 };
 

Modified: branches/branch-3.0/include/fltk3/Style.h
===================================================================
--- branches/branch-3.0/include/fltk3/Style.h   2012-07-04 09:46:59 UTC (rev 
9632)
+++ branches/branch-3.0/include/fltk3/Style.h   2012-07-04 15:10:05 UTC (rev 
9633)
@@ -54,6 +54,10 @@
     Font textfont_;
     Fontsize textsize_;
     Color textcolor_;
+    
+    Color color_;
+    Color color2_;
+    Box* box_;
 
     unsigned int private_:1;
     unsigned int labelfont_set_:1;
@@ -64,8 +68,11 @@
     unsigned int textfont_set_:1;
     unsigned int textsize_set_:1;
     unsigned int textcolor_set_:1;
+    unsigned int color_set_:1;
+    unsigned int color2_set_:1;
+    unsigned int box_set_:1;
     
-    void update();
+    unsigned int update();
     void refresh() const { if (version_ != current_) ((Style*)this)->update(); 
}
     void invalidate() { if (!private_) current_++; }
     
@@ -107,6 +114,19 @@
     void textcolor(Color s) { textcolor_=s; textcolor_set_ = 1; invalidate(); }
     void clear_textcolor() { textcolor_set_=0; invalidate(); }
     
+    Color color() const { refresh(); return color_;}
+    void color(Color s) { color_=s; color_set_ = 1; invalidate(); }
+    void clear_color() { color_set_=0; invalidate(); }
+    
+    Color color2() const { refresh(); return color2_;}
+    void color2(Color s) { color2_=s; color2_set_ = 1; invalidate(); }
+    void clear_color2() { color2_set_=0; invalidate(); }
+    
+    Box* box() const { refresh(); return box_;}
+    void box(Box* b) { box_=b; box_set_ = 1; invalidate(); }
+    void clear_box() { box_set_=0; invalidate(); }
+    
+    
     /**
      Use an existing style for a new label.
      If the style is public, the same style is returned. However, if the style 

Modified: branches/branch-3.0/include/fltk3/Widget.h
===================================================================
--- branches/branch-3.0/include/fltk3/Widget.h  2012-07-04 09:46:59 UTC (rev 
9632)
+++ branches/branch-3.0/include/fltk3/Widget.h  2012-07-04 15:10:05 UTC (rev 
9633)
@@ -221,6 +221,64 @@
      */
     void align(Align alignment) { private_style()->align(alignment); }
     
+    /** Gets the box type of the widget.
+     \return the current box type
+     \see box(fltk3::Boxtype), fltk3::Boxtype
+     */
+    Box* box() const {return style()->box();}
+    
+    /** Sets the box type for the widget. 
+     This identifies a routine that draws the background of the widget.
+     See fltk3::Boxtype for the available types. The default depends on the 
+     widget, but is usually fltk3::NO_BOX or fltk3::UP_BOX.
+     \param[in] new_box the new box type
+     \see box(), fltk3::Boxtype
+     */
+    void box(Box* new_box) {private_style()->box(new_box);}
+    
+    /** Gets the background color of the widget.
+     \return current background color
+     \see color(fltk3::Color), color(fltk3::Color, fltk3::Color)
+     */
+    Color color() const {return style()->color();}
+    
+    /** Sets the background color of the widget. 
+     The color is passed to the box routine. The color is either an index into 
+     an internal table of RGB colors or an RGB color value generated using 
+     fltk3::rgb_color().
+     
+     The default for most widgets is fltk3::BACKGROUND_COLOR. Use 
fltk3::set_color()
+     to redefine colors in the color map.
+     \param[in] bg background color
+     \see color(), color(fltk3::Color, fltk3::Color), 
selection_color(fltk3::Color)
+     */
+    void color(Color bg) {private_style()->color(bg);}
+    
+    /** Gets the selection color.
+     \return the current selection color
+     \see selection_color(fltk3::Color), color(fltk3::Color, fltk3::Color)
+     */
+    fltk3::Color selection_color() const {return style()->color2();}
+    
+    /** Sets the selection color.
+     The selection color is defined for Forms compatibility and is usually 
+     used to color the widget when it is selected, although some widgets 
+     use this color for other purposes. You can set both colors at once 
+     with color(fltk3::Color bg, fltk3::Color sel).
+     \param[in] a the new selection color
+     \see selection_color(), color(fltk3::Color, fltk3::Color)
+     */
+    void selection_color(fltk3::Color a) {private_style()->color2(a);}
+    
+    /** Sets the background and selection color of the widget. 
+     
+     The two color form sets both the background and selection colors. 
+     \param[in] bg background color
+     \param[in] sel selection color
+     \see color(unsigned), selection_color(unsigned)
+     */
+    void color(fltk3::Color bg, fltk3::Color sel) {private_style()->color(bg); 
private_style()->color2(sel);}
+    
     /** Gets the widget flags mask */
     unsigned int flags() const {return flags_;}
     
@@ -334,9 +392,6 @@
     fltk3::Group* parent_;
     fltk3::Callback* callback_;
     void* user_data_;
-    Color color_;  // FIXME: should be in Style
-    Color color2_;  // FIXME: should be in Style
-    Box* box_;  // FIXME: should be in Style
     uchar type_;
     uchar damage_;
     uchar when_;    
@@ -521,64 +576,6 @@
      */
     void size(int W,int H) {resize(x_,y_,W,H);}
     
-    /** Gets the box type of the widget.
-     \return the current box type
-     \see box(fltk3::Boxtype), fltk3::Boxtype
-     */
-    Box* box() const {return box_;}
-    
-    /** Sets the box type for the widget. 
-     This identifies a routine that draws the background of the widget.
-     See fltk3::Boxtype for the available types. The default depends on the 
-     widget, but is usually fltk3::NO_BOX or fltk3::UP_BOX.
-     \param[in] new_box the new box type
-     \see box(), fltk3::Boxtype
-     */
-    void box(Box* new_box) {box_ = new_box;}
-    
-    /** Gets the background color of the widget.
-     \return current background color
-     \see color(fltk3::Color), color(fltk3::Color, fltk3::Color)
-     */
-    Color color() const {return color_;}
-    
-    /** Sets the background color of the widget. 
-     The color is passed to the box routine. The color is either an index into 
-     an internal table of RGB colors or an RGB color value generated using 
-     fltk3::rgb_color().
-     
-     The default for most widgets is fltk3::BACKGROUND_COLOR. Use 
fltk3::set_color()
-     to redefine colors in the color map.
-     \param[in] bg background color
-     \see color(), color(fltk3::Color, fltk3::Color), 
selection_color(fltk3::Color)
-     */
-    void color(Color bg) {color_ = bg;}
-    
-    /** Gets the selection color.
-     \return the current selection color
-     \see selection_color(fltk3::Color), color(fltk3::Color, fltk3::Color)
-     */
-    fltk3::Color selection_color() const {return color2_;}
-    
-    /** Sets the selection color.
-     The selection color is defined for Forms compatibility and is usually 
-     used to color the widget when it is selected, although some widgets 
-     use this color for other purposes. You can set both colors at once 
-     with color(fltk3::Color bg, fltk3::Color sel).
-     \param[in] a the new selection color
-     \see selection_color(), color(fltk3::Color, fltk3::Color)
-     */
-    void selection_color(fltk3::Color a) {color2_ = a;}
-    
-    /** Sets the background and selection color of the widget. 
-     
-     The two color form sets both the background and selection colors. 
-     \param[in] bg background color
-     \param[in] sel selection color
-     \see color(unsigned), selection_color(unsigned)
-     */
-    void color(fltk3::Color bg, fltk3::Color sel) {color_=bg; color2_=sel;}
-    
     /** Gets the current tooltip text.
      \return a pointer to the tooltip text or NULL
      \see tooltip(const char*), copy_tooltip(const char*)
@@ -1027,16 +1024,6 @@
      */
     virtual class fltk3::GLWindow* as_gl_window() {return 0;}
     
-    /** For back compatibility only.
-     \deprecated Use selection_color() instead.
-     */
-    fltk3::Color color2() const {return (fltk3::Color)color2_;}
-    
-    /** For back compatibility only.
-     \deprecated Use selection_color(unsigned) instead.
-     */
-    void color2(unsigned a) {color2_ = a;}    
-    
 };
   
   

Modified: branches/branch-3.0/src/fltk3/Style.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Style.cxx     2012-07-04 09:46:59 UTC (rev 
9632)
+++ branches/branch-3.0/src/fltk3/Style.cxx     2012-07-04 15:10:05 UTC (rev 
9633)
@@ -43,6 +43,9 @@
   textfont_(fltk3::HELVETICA),
   textsize_(fltk3::NORMAL_SIZE),
   textcolor_(fltk3::FOREGROUND_COLOR),
+  color_(fltk3::GRAY),
+  color2_(fltk3::GRAY),
+  box_(fltk3::NO_BOX),
   private_(0),
   labelfont_set_(1),
   labelsize_set_(1),
@@ -51,13 +54,16 @@
   align_set_(1),
   textfont_set_(1),
   textsize_set_(1),
-  textcolor_set_(1)
+  textcolor_set_(1),
+  color_set_(1),
+  color2_set_(1),
+  box_set_(1)
 {
 }
 
 
 fltk3::Style::Style(Style *parent) :
-  version_(current_),
+  version_(parent->update()),
   parent_(parent),
   labelfont_(parent->labelfont_),
   labelsize_(parent->labelsize_),
@@ -67,6 +73,9 @@
   textfont_(parent->textfont_),
   textsize_(parent->textsize_),
   textcolor_(parent->textcolor_),
+  color_(parent->color_),
+  color2_(parent->color2_),
+  box_(parent->box_),
   private_(0),
   labelfont_set_(0),
   labelsize_set_(0),
@@ -75,7 +84,10 @@
   align_set_(0),
   textfont_set_(0),
   textsize_set_(0),
-  textcolor_set_(0)
+  textcolor_set_(0),
+  color_set_(0),
+  color2_set_(0),
+  box_set_(0)
 {
 }
 
@@ -112,10 +124,10 @@
 }
 
 
-void fltk3::Style::update()
+unsigned int fltk3::Style::update()
 {
   if (version_==current_ || parent_==0L)
-    return;
+    return current_;
   parent_->refresh();
   
   if (!labelfont_set_)
@@ -134,8 +146,15 @@
     textsize_ = parent_->textsize_;
   if (!textcolor_set_)
     textcolor_ = parent_->textcolor_;
+  if (!color_set_)
+    color_ = parent_->color_;
+  if (!color2_set_)
+    color2_ = parent_->color2_;
+  if (!box_set_)
+    box_ = parent_->box_;
   
   version_ = current_;
+  return current_;
 }
 
 

Modified: branches/branch-3.0/src/fltk3/Widget.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Widget.cxx    2012-07-04 09:46:59 UTC (rev 
9632)
+++ branches/branch-3.0/src/fltk3/Widget.cxx    2012-07-04 15:10:05 UTC (rev 
9633)
@@ -165,9 +165,6 @@
   type_                 = 0;
   flags_        = VISIBLE_FOCUS;
   damage_       = 0;
-  box_          = fltk3::NO_BOX;
-  color_        = fltk3::GRAY;
-  color2_       = fltk3::GRAY;
   when_                 = fltk3::WHEN_RELEASE;
   
   parent_ = 0;
@@ -183,13 +180,11 @@
   type_                 = 0;
   flags_        = VISIBLE_FOCUS;
   damage_       = 0;
-  box_          = b;
-  color_        = fltk3::GRAY;
-  color2_       = fltk3::GRAY;
   when_                 = fltk3::WHEN_RELEASE;
-  
   parent_ = 0;
   if (fltk3::Group::current()) fltk3::Group::current()->add(this);
+  
+  box(b);
 }
 
 void fltk3::Widget::resize(int X, int Y, int W, int H) {

Modified: branches/branch-3.0/src/fltk3/boxtype.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/boxtype.cxx   2012-07-04 09:46:59 UTC (rev 
9632)
+++ branches/branch-3.0/src/fltk3/boxtype.cxx   2012-07-04 15:10:05 UTC (rev 
9633)
@@ -449,8 +449,8 @@
 //extern fltk3::Widget *fl_boxcheat; // hack set by fltk3::Window.cxx
 /** Draws the widget box according its box style */
 void fltk3::Widget::draw_box() const {
-  if (box_) {
-    draw_box(box_, 0, 0, w_, h_, color_);
+  if (box()) {
+    draw_box(box(), 0, 0, w_, h_, color());
   }
   draw_backdrop();
 }

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to