]> git.tdb.fi Git - libs/gltk.git/commitdiff
Rearrange members
authorMikko Rasa <tdb@tdb.fi>
Wed, 2 Feb 2011 12:05:28 +0000 (12:05 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 2 Feb 2011 12:05:28 +0000 (12:05 +0000)
Make Container a friend of Widget and get rid of the static helpers

25 files changed:
source/button.cpp
source/button.h
source/container.cpp
source/container.h
source/dialog.h
source/dropdown.cpp
source/dropdown.h
source/entry.cpp
source/entry.h
source/hslider.cpp
source/hslider.h
source/image.h
source/indicator.h
source/label.h
source/list.cpp
source/list.h
source/panel.cpp
source/panel.h
source/slider.h
source/toggle.cpp
source/toggle.h
source/vslider.cpp
source/vslider.h
source/widget.cpp
source/widget.h

index 8e6e7131cb4157c266b096e4bd121931eb68abdb..e81fe02c20a5ffdc609aa74106adf4b4bc879855 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007, 2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -30,6 +30,34 @@ void Button::set_icon(const GL::Texture2D *i)
        icon = i;
 }
 
+void Button::render_special(const Part &part) const
+{
+       if(part.get_name()=="text")
+               text.render(part, geom);
+       if(part.get_name()=="icon" && icon)
+       {
+               Geometry rgeom;
+               rgeom.w = icon->get_width();
+               rgeom.h = icon->get_height();
+               part.get_alignment().apply(rgeom, geom, part.get_margin());
+
+               icon->bind();
+               GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
+               imm.color(1.0f, 1.0f, 1.0f);
+               imm.begin(GL::QUADS);
+               imm.texcoord(0, 0);
+               imm.vertex(rgeom.x, rgeom.y);
+               imm.texcoord(1, 0);
+               imm.vertex(rgeom.x+rgeom.w, rgeom.y);
+               imm.texcoord(1, 1);
+               imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
+               imm.texcoord(0, 1);
+               imm.vertex(rgeom.x, rgeom.y+rgeom.h);
+               imm.end();
+               GL::Texture::unbind();
+       }
+}
+
 void Button::button_press(int, int, unsigned btn)
 {
        if(btn==1)
@@ -62,34 +90,6 @@ void Button::pointer_motion(int x, int y)
        }
 }
 
-void Button::render_special(const Part &part) const
-{
-       if(part.get_name()=="text")
-               text.render(part, geom);
-       if(part.get_name()=="icon" && icon)
-       {
-               Geometry rgeom;
-               rgeom.w = icon->get_width();
-               rgeom.h = icon->get_height();
-               part.get_alignment().apply(rgeom, geom, part.get_margin());
-
-               icon->bind();
-               GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
-               imm.color(1.0f, 1.0f, 1.0f);
-               imm.begin(GL::QUADS);
-               imm.texcoord(0, 0);
-               imm.vertex(rgeom.x, rgeom.y);
-               imm.texcoord(1, 0);
-               imm.vertex(rgeom.x+rgeom.w, rgeom.y);
-               imm.texcoord(1, 1);
-               imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
-               imm.texcoord(0, 1);
-               imm.vertex(rgeom.x, rgeom.y+rgeom.h);
-               imm.end();
-               GL::Texture::unbind();
-       }
-}
-
 void Button::on_style_change()
 {
        text.set_style(style);
index b84511e310707655e70bc1c76392394e86f3634c..8d4c3c6c2de27081ecf782bdf127035f0c0b9167 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007, 2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -31,25 +31,29 @@ public:
                void text(const std::string &);
        };
 
+       sigc::signal<void> signal_clicked;
+
 private:
        Text text;
        const GL::Texture2D *icon;
        bool pressed;
 
 public:
-       sigc::signal<void> signal_clicked;
-
        Button(const std::string & = std::string());
 
+       virtual const char *get_class() const { return "button"; }
+
        void set_text(const std::string &);
        void set_icon(const GL::Texture2D *);
+
+private:
+       virtual void render_special(const Part &) const;
+
+public:
        virtual void button_press(int, int, unsigned);
        virtual void button_release(int, int, unsigned);
        virtual void pointer_motion(int, int);
 private:
-       virtual const char *get_class() const { return "button"; }
-       virtual void render_special(const Part &) const;
-
        virtual void on_style_change();
 };
 
index b2b8c56adaec281394847f0d954d9f516e5859a6..9ad66482a15a2ad2503d7f0efcb12a6fe14383c4 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2009-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -25,7 +25,7 @@ Container::~Container()
 
 void Container::add(Widget &wdg)
 {
-       set_parent(wdg, this);
+       wdg.set_parent(this);
        children.push_back(create_child(&wdg));
 }
 
@@ -34,7 +34,7 @@ void Container::remove(Widget &wdg)
        for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
                if((*i)->widget==&wdg)
                {
-                       set_parent(wdg, 0);
+                       wdg.set_parent(0);
                        delete *i;
                        children.erase(i);
                        return;
@@ -43,6 +43,11 @@ void Container::remove(Widget &wdg)
        throw InvalidState("That Widget is not in this Container");
 }
 
+Container::Child *Container::create_child(Widget *wdg)
+{
+       return new Child(*this, wdg);
+}
+
 list<Widget *> Container::get_children() const
 {
        list<Widget *> result;
@@ -139,18 +144,13 @@ void Container::pointer_leave()
        click_focus = 0;
 }
 
-Container::Child *Container::create_child(Widget *wdg)
-{
-       return new Child(*this, wdg);
-}
-
 void Container::on_reparent()
 {
        for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
        {
                if(Container *c = dynamic_cast<Container *>((*i)->widget))
                        c->on_reparent();
-               update_style(*(*i)->widget);
+               (*i)->widget->update_style();
        }
 }
 
index 0384521d4c8657a9a6282618b90f7b6de7dafa38..ddccb06b7dd0e1f16faef7c34807e9444884d2b1 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2009-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -39,6 +39,9 @@ public:
 
        void add(Widget &);
        void remove(Widget &);
+protected:
+       virtual Child *create_child(Widget *);
+public:
        std::list<Widget *> get_children() const;
        Widget *get_child_at(int, int);
        Widget *get_descendant_at(int, int);
@@ -48,7 +51,6 @@ public:
        virtual void pointer_motion(int, int);
        virtual void pointer_leave();
 protected:
-       virtual Child *create_child(Widget *);
        virtual void on_reparent();
 };
 
index 89065dcf050861542f52548bdeb28af77dd2a22e..eb2d17620117675781b605657e51d73080a79a38 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2010  Mikko Rasa, Mikkosoft Productions
+Copyright © 2010-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -21,12 +21,13 @@ Dialog's action buttons are clicked, it will emit a signal and delete itself.
 */
 class Dialog: public Panel
 {
+public:
+       sigc::signal<void, int> signal_response;
+
 private:
        bool stale;
 
 public:
-       sigc::signal<void, int> signal_response;
-
        Dialog();
 
        /** Adds an action button to the dialog.  Pressing the button will invoke
index bcd501950a08aee01f584c925725717c5b83223b..e9634f5e676f781675c646c9e0d4f3a65a9841c5 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007-2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -69,6 +69,17 @@ int Dropdown::get_selected_index() const
        return list.get_selected_index();
 }
 
+void Dropdown::render_special(const Part &part) const
+{
+       if(part.get_name()=="text")
+       {
+               if(list.get_selected_index()>=0)
+                       Text(*style, list.get_selected()).render(part, geom);
+       }
+       else if(part.get_name()=="list" && dropped)
+               list.render();
+}
+
 void Dropdown::button_press(int x, int y, unsigned btn)
 {
        if(dropped)
@@ -89,17 +100,6 @@ void Dropdown::button_press(int x, int y, unsigned btn)
        }
 }
 
-void Dropdown::render_special(const Part &part) const
-{
-       if(part.get_name()=="text")
-       {
-               if(list.get_selected_index()>=0)
-                       Text(*style, list.get_selected()).render(part, geom);
-       }
-       else if(part.get_name()=="list" && dropped)
-               list.render();
-}
-
 void Dropdown::on_geometry_change()
 {
        resize_list();
index 2fe82d0a194c41421bfee2b057813b3d5cc01841..51ba72434956d1c1728f1a6e021c73dfec73ad18 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007-2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -28,15 +28,17 @@ public:
                void item(const std::string &);
        };
 
+       sigc::signal<void, int, const std::string &> signal_item_selected;
+
 private:
        List list;
        bool dropped;
 
 public:
-       sigc::signal<void, int, const std::string &> signal_item_selected;
-
        Dropdown();
 
+       virtual const char *get_class() const { return "dropdown"; }
+
        void append(const std::string &);
        void insert(unsigned, const std::string &);
        void remove(unsigned);
@@ -47,16 +49,16 @@ public:
        const std::string &get_selected() const;
        int get_selected_index() const;
 
-       virtual void button_press(int, int, unsigned);
-
 private:
-       virtual const char *get_class() const { return "dropdown"; }
        virtual void render_special(const Part &) const;
 
+public:
+       virtual void button_press(int, int, unsigned);
+private:
        virtual void on_geometry_change();
        virtual void on_style_change();
-       void resize_list();
 
+       void resize_list();
        void list_item_selected(unsigned, const std::string &);
 };
 
index 2c9cb357fa55d38215c64358b4f1ae22fe972932..271c49a4b6cda21ca063f9e7e7339ea460c96de5 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007-2010  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -58,6 +58,32 @@ void Entry::set_multiline(bool m)
        }
 }
 
+void Entry::render_special(const Part &part) const
+{
+       if(part.get_name()=="text")
+               text.render(part, geom, first_row);
+       else if(part.get_name()=="cursor")
+       {
+               if(!text_part || !part.get_graphic(state))
+                       return;
+
+               unsigned row, col;
+               text.offset_to_coords(edit_pos, row, col);
+
+               if(row<first_row || row>=first_row+visible_rows)
+                       return;
+
+               Geometry rgeom = text.coords_to_geometry(*text_part, geom, first_row, row, col);
+
+               GL::push_matrix();
+               GL::translate(rgeom.x, rgeom.y, 0);
+               part.get_graphic(state)->render(part.get_geometry().w, part.get_geometry().h);
+               GL::pop_matrix();
+       }
+       else if(part.get_name()=="slider")
+               slider->render();
+}
+
 void Entry::key_press(unsigned key, unsigned, wchar_t ch)
 {
        if(key==Input::KEY_LEFT)
@@ -120,32 +146,6 @@ void Entry::key_press(unsigned key, unsigned, wchar_t ch)
        }
 }
 
-void Entry::render_special(const Part &part) const
-{
-       if(part.get_name()=="text")
-               text.render(part, geom, first_row);
-       else if(part.get_name()=="cursor")
-       {
-               if(!text_part || !part.get_graphic(state))
-                       return;
-
-               unsigned row, col;
-               text.offset_to_coords(edit_pos, row, col);
-
-               if(row<first_row || row>=first_row+visible_rows)
-                       return;
-
-               Geometry rgeom = text.coords_to_geometry(*text_part, geom, first_row, row, col);
-
-               GL::push_matrix();
-               GL::translate(rgeom.x, rgeom.y, 0);
-               part.get_graphic(state)->render(part.get_geometry().w, part.get_geometry().h);
-               GL::pop_matrix();
-       }
-       else if(part.get_name()=="slider")
-               slider->render();
-}
-
 void Entry::on_geometry_change()
 {
        reposition_slider();
@@ -185,12 +185,6 @@ void Entry::reposition_slider()
        }
 }
 
-void Entry::slider_value_changed(double value)
-{
-       if(text.get_n_lines()>visible_rows)
-               first_row = text.get_n_lines()-visible_rows-static_cast<unsigned>(value);
-}
-
 void Entry::check_view_range()
 {
        if(!multiline || !text_part)
@@ -219,6 +213,12 @@ void Entry::check_view_range()
        }
 }
 
+void Entry::slider_value_changed(double value)
+{
+       if(text.get_n_lines()>visible_rows)
+               first_row = text.get_n_lines()-visible_rows-static_cast<unsigned>(value);
+}
+
 
 Entry::Loader::Loader(Entry &ent):
        Widget::Loader(ent)
index 53270647a61acc31158c1c34c8c2cded3ef247bd..bc4a26bfb067513839760e5562c71f4fb72928c2 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007-2010  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -35,6 +35,8 @@ public:
                Loader(Entry &);
        };
 
+       sigc::signal<void> signal_enter;
+
 private:
        Text text;
        bool multiline;
@@ -45,25 +47,27 @@ private:
        VSlider *slider;
 
 public:
-       sigc::signal<void> signal_enter;
-
        Entry(const std::string & = std::string());
 
+       virtual const char *get_class() const { return "entry"; }
+
        void set_text(const std::string &);
        const std::string &get_text() const { return text.get(); }
        void set_multiline(bool);
        bool is_multiline() const { return multiline; }
 
-       virtual void key_press(unsigned, unsigned, wchar_t);
 private:
-       virtual const char *get_class() const { return "entry"; }
        virtual void render_special(const Part &) const;
 
+public:
+       virtual void key_press(unsigned, unsigned, wchar_t);
+private:
        virtual void on_geometry_change();
        virtual void on_style_change();
+
        void reposition_slider();
-       void slider_value_changed(double);
        void check_view_range();
+       void slider_value_changed(double);
 };
 
 } // namespace GLtk
index a4378f0c9e62fbf491b6b73c2759ca97e11baf7c..e86cc4b17da02f56f8d26906eb2382ab59af0761 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2008, 2010-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -19,6 +19,24 @@ HSlider::HSlider():
        slider_size(1)
 { }
 
+void HSlider::render_special(const Part &part) const
+{
+       if(part.get_name()=="slider")
+       {
+               Alignment align = part.get_alignment();
+               if(max>min)
+                       align.x = (value-min)/(max-min);
+
+               Geometry pgeom = part.get_geometry();
+               align.apply(pgeom, geom, part.get_margin());
+
+               GL::push_matrix();
+               GL::translate(pgeom.x, pgeom.y, 0);
+               part.get_graphic(state)->render(pgeom.w, pgeom.h);
+               GL::pop_matrix();
+       }
+}
+
 void HSlider::button_press(int x, int y, unsigned btn)
 {
        if(btn==1 && geom.is_inside_relative(x, y) && max>min)
@@ -45,24 +63,6 @@ void HSlider::pointer_motion(int x, int)
                drag(x);
 }
 
-void HSlider::render_special(const Part &part) const
-{
-       if(part.get_name()=="slider")
-       {
-               Alignment align = part.get_alignment();
-               if(max>min)
-                       align.x = (value-min)/(max-min);
-
-               Geometry pgeom = part.get_geometry();
-               align.apply(pgeom, geom, part.get_margin());
-
-               GL::push_matrix();
-               GL::translate(pgeom.x, pgeom.y, 0);
-               part.get_graphic(state)->render(pgeom.w, pgeom.h);
-               GL::pop_matrix();
-       }
-}
-
 void HSlider::on_geometry_change()
 {
        drag_area_size = geom.w-slider_size;
index 47066998c5a4e4f336422772a5bcd02b9f61a5ee..493f00cf97ab50d396211b76a1166e9d211b8c29 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2010-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -24,13 +24,17 @@ private:
 
 public:
        HSlider();
+
+       virtual const char *get_class() const { return "hslider"; }
+
+private:
+       virtual void render_special(const Part &) const;
+
+public:
        virtual void button_press(int, int, unsigned);
        virtual void button_release(int, int, unsigned);
        virtual void pointer_motion(int, int);
 private:
-       virtual const char *get_class() const { return "hslider"; }
-       virtual void render_special(const Part &) const;
-
        virtual void on_geometry_change();
        virtual void on_style_change();
 };
index 8256a8d9c5c1749bbee6da77793fbc91e7b09a81..efc814487f88c39f38e2cc209382b5d53db0a50e 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2010-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -26,10 +26,12 @@ private:
 public:
        Image(const GL::Texture2D * = 0);
 
+       virtual const char *get_class() const { return "image"; }
+
        void set_image(const GL::Texture2D *);
        void set_keep_aspect(bool);
+
 private:
-       virtual const char *get_class() const { return "image"; }
        virtual void render_special(const Part &) const;
 };
 
index ce95151665e30bd7048fa1b2808d471941470132..fdc83b415ed6f89b904bb19281d0f7d7c69c8fdc 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2010-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -20,9 +20,10 @@ class Indicator: public Widget
 {
 public:
        Indicator();
-       void set_active(bool);
-private:
+
        virtual const char *get_class() const { return "indicator"; }
+
+       void set_active(bool);
 };
 
 } // namespace GLtk
index 87835da73811a4a816cdadc11c746f6a416bc3ef..20219c4d9d97db3ea9cf9fca5f574f69da5d3857 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2009-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -34,11 +34,12 @@ private:
 public:
        Label(const std::string & = std::string());
 
+       virtual const char *get_class() const { return "label"; }
+
        virtual void autosize();
        void set_text(const std::string &);
 
 private:
-       virtual const char *get_class() const { return "label"; }
        virtual void render_special(const Part &) const;
 
        virtual void on_style_change();
index 672cf4911bbf028e4e3850579959794e9c4f11f2..ac8b48cb77432dfb5069bf038c1a705510cd2684 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007-2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -114,24 +114,6 @@ const string &List::get_selected() const
        return items[sel_index];
 }
 
-void List::button_press(int x, int y, unsigned btn)
-{
-       Container::button_press(x, y, btn);
-       if(!click_focus && btn==1)
-       {
-               if(items_part)
-                       y += items_part->get_margin().top;
-
-               unsigned i = (geom.h-1-y)/row_height;
-               if(i<n_visible && first+i<items.size())
-               {
-                       sel_index = first+i;
-
-                       signal_item_selected.emit(sel_index, items[sel_index]);
-               }
-       }
-}
-
 void List::render_special(const Part &part) const
 {
        if(part.get_name()=="items")
@@ -175,6 +157,24 @@ void List::render_special(const Part &part) const
                slider.render();
 }
 
+void List::button_press(int x, int y, unsigned btn)
+{
+       Container::button_press(x, y, btn);
+       if(!click_focus && btn==1)
+       {
+               if(items_part)
+                       y += items_part->get_margin().top;
+
+               unsigned i = (geom.h-1-y)/row_height;
+               if(i<n_visible && first+i<items.size())
+               {
+                       sel_index = first+i;
+
+                       signal_item_selected.emit(sel_index, items[sel_index]);
+               }
+       }
+}
+
 void List::on_geometry_change()
 {
        reposition_slider();
index f1e9ac3fba6172da86fa46e1fa3a530118977d6e..b6cae50c876071747945d01cd8f3d1ee3d7231c1 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007-2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -30,6 +30,8 @@ public:
                void item(const std::string &);
        };
 
+       sigc::signal<void, unsigned, const std::string &> signal_item_selected;
+
 private:
        std::vector<std::string> items;
        int sel_index;
@@ -42,10 +44,10 @@ private:
        VSlider slider;
 
 public:
-       sigc::signal<void, unsigned, const std::string &> signal_item_selected;
-
        List();
 
+       virtual const char *get_class() const { return "list"; }
+
        virtual void autosize();
 
        void append(const std::string &);
@@ -58,14 +60,15 @@ public:
        const std::string &get_selected() const;
        int get_selected_index() const { return sel_index; }
 
-       virtual void button_press(int, int, unsigned);
-
 private:
-       virtual const char *get_class() const { return "list"; }
        virtual void render_special(const Part &) const;
 
+public:
+       virtual void button_press(int, int, unsigned);
+private:
        virtual void on_geometry_change();
        virtual void on_style_change();
+
        void reposition_slider();
        void check_view_range();
        void slider_value_changed(double);
index f0c1c7c69f0f120b2d2696a049b75a3d975d3ed4..0ecdf1077ca0a7ae05abaa957dad2fb327493c5c 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007-2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -31,6 +31,11 @@ Panel::Panel():
        input_focus(0)
 { }
 
+Panel::Child *Panel::create_child(Widget *wdg)
+{
+       return new Child(*this, wdg);
+}
+
 void Panel::raise(Widget &wdg)
 {
        for(list<Container::Child *>::iterator i=children.begin(); i!=children.end(); ++i)
@@ -54,6 +59,16 @@ Widget *Panel::get_final_input_focus() const
        return input_focus;
 }
 
+void Panel::render_special(const Part &part) const
+{
+       if(part.get_name()=="children")
+       {
+               for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
+                       if((*i)->widget->is_visible())
+                               (*i)->widget->render();
+       }
+}
+
 void Panel::button_press(int x, int y, unsigned btn)
 {
        if(pointer_grabbed)
@@ -121,21 +136,6 @@ void Panel::focus_out()
        set_input_focus(0);
 }
 
-void Panel::render_special(const Part &part) const
-{
-       if(part.get_name()=="children")
-       {
-               for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
-                       if((*i)->widget->is_visible())
-                               (*i)->widget->render();
-       }
-}
-
-Panel::Child *Panel::create_child(Widget *wdg)
-{
-       return new Child(*this, wdg);
-}
-
 void Panel::set_pointer_focus(Widget *wdg)
 {
        if(wdg!=pointer_focus)
index dc9841654aa7b623e948610910f0fa35455907a1..748ecb48d508c53c32a7186ede84472c581d7b85 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007-2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -57,10 +57,20 @@ protected:
 public:
        Panel();
 
+       virtual const char *get_class() const { return "panel"; }
+
+protected:
+       virtual Child *create_child(Widget *);
+
+public:
        void raise(Widget &);
        Widget *get_input_focus() const { return input_focus; }
        Widget *get_final_input_focus() const;
 
+protected:
+       virtual void render_special(const Part &) const;
+
+public:
        virtual void button_press(int, int, unsigned);
        virtual void button_release(int, int, unsigned);
        virtual void pointer_motion(int, int);
@@ -68,11 +78,8 @@ public:
        virtual void key_press(unsigned, unsigned, wchar_t);
        virtual void key_release(unsigned, unsigned);
        virtual void focus_out();
-protected:
-       virtual const char *get_class() const { return "panel"; }
-       virtual void render_special(const Part &) const;
-       virtual Child *create_child(Widget *);
 
+protected:
        void set_pointer_focus(Widget *);
        void set_input_focus(Widget *);
 };
index c4326e3eac0edf5571ac29b96ee82adb3ba63abc..edaa5d8ad932bea7b5b64891d361f81c138754f7 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2010-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -29,6 +29,8 @@ public:
                Slider &get_object() const;
        };
 
+       sigc::signal<void, double> signal_value_changed;
+
 protected:
        double min, max;
        double value;
@@ -39,16 +41,14 @@ protected:
        double drag_start_value;
        unsigned drag_area_size;
 
-public:
-       sigc::signal<void, double> signal_value_changed;
-
-protected:
        Slider();
+
 public:
        void set_value(double);
        void set_range(double, double);
        void set_step(double);
        double get_value() const { return value; }
+
 protected:
        void start_drag(int);
        void drag(int);
index a950b971307aae231b91783624a234155aee8ae3..7edbbb08823c5018aac2a6e4b217309b66fbf8d9 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -35,6 +35,15 @@ void Toggle::set_exclusive(bool e)
                exclude_siblings();
 }
 
+void Toggle::exclude_siblings()
+{
+       const list<Widget *> &siblings = parent->get_children();
+       for(list<Widget *>::const_iterator i=siblings.begin(); i!=siblings.end(); ++i)
+               if(Toggle *tgl = dynamic_cast<Toggle *>(*i))
+                       if(tgl!=this && tgl->get_exclusive() && tgl->get_value())
+                               tgl->set_value(false);
+}
+
 void Toggle::set_value(bool v)
 {
        value = v;
@@ -48,6 +57,12 @@ void Toggle::set_value(bool v)
                state &= ~ACTIVE;
 }
 
+void Toggle::render_special(const Part &part) const
+{
+       if(part.get_name()=="text")
+               text.render(part, geom);
+}
+
 void Toggle::button_press(int, int, unsigned btn)
 {
        if(btn==1)
@@ -68,21 +83,6 @@ void Toggle::button_release(int x, int y, unsigned btn)
        }
 }
 
-void Toggle::render_special(const Part &part) const
-{
-       if(part.get_name()=="text")
-               text.render(part, geom);
-}
-
-void Toggle::exclude_siblings()
-{
-       const list<Widget *> &siblings = parent->get_children();
-       for(list<Widget *>::const_iterator i=siblings.begin(); i!=siblings.end(); ++i)
-               if(Toggle *tgl = dynamic_cast<Toggle *>(*i))
-                       if(tgl!=this && tgl->get_exclusive() && tgl->get_value())
-                               tgl->set_value(false);
-}
-
 void Toggle::on_style_change()
 {
        text.set_style(style);
index 24dfe4867651081163a0302b88b902092213fefb..ff65440a66f49fd1cc87bae8993b3c48c13b572a 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -31,6 +31,8 @@ public:
                void text(const std::string &);
        };
 
+       sigc::signal<void, bool> signal_toggled;
+
 private:
        Text text;
        bool pressed;
@@ -38,24 +40,26 @@ private:
        bool exclusive;
 
 public:
-       sigc::signal<void, bool> signal_toggled;
-
        Toggle(const std::string & = std::string());
 
+       virtual const char *get_class() const { return "toggle"; }
+
        void set_text(const std::string &);
        void set_exclusive(bool);
        bool get_exclusive() const { return exclusive; }
+private:
+       void exclude_siblings();
+public:
        void set_value(bool);
        bool get_value() const { return value; }
 
-       virtual void button_press(int, int, unsigned);
-       virtual void button_release(int, int, unsigned);
 private:
-       virtual const char *get_class() const { return "toggle"; }
        virtual void render_special(const Part &) const;
 
-       void exclude_siblings();
-
+public:
+       virtual void button_press(int, int, unsigned);
+       virtual void button_release(int, int, unsigned);
+private:
        virtual void on_style_change();
 };
 
index cdd2675952a1bf3ddf2737a08bfc414be01e4d5c..65cac69846f9763efc2dead8fddc06e04bde8048 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2008, 2010-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -17,7 +17,24 @@ namespace GLtk {
 
 VSlider::VSlider():
        slider_size(1)
+{ }
+
+void VSlider::render_special(const Part &part) const
 {
+       if(part.get_name()=="slider")
+       {
+               Alignment align = part.get_alignment();
+               if(max>min)
+                       align.y = (value-min)/(max-min);
+
+               Geometry pgeom = part.get_geometry();
+               align.apply(pgeom, geom, part.get_margin());
+
+               GL::push_matrix();
+               GL::translate(pgeom.x, pgeom.y, 0);
+               part.get_graphic(state)->render(pgeom.w, pgeom.h);
+               GL::pop_matrix();
+       }
 }
 
 void VSlider::button_press(int x, int y, unsigned btn)
@@ -46,24 +63,6 @@ void VSlider::pointer_motion(int, int y)
                drag(y);
 }
 
-void VSlider::render_special(const Part &part) const
-{
-       if(part.get_name()=="slider")
-       {
-               Alignment align = part.get_alignment();
-               if(max>min)
-                       align.y = (value-min)/(max-min);
-
-               Geometry pgeom = part.get_geometry();
-               align.apply(pgeom, geom, part.get_margin());
-
-               GL::push_matrix();
-               GL::translate(pgeom.x, pgeom.y, 0);
-               part.get_graphic(state)->render(pgeom.w, pgeom.h);
-               GL::pop_matrix();
-       }
-}
-
 void VSlider::on_geometry_change()
 {
        drag_area_size = geom.h-slider_size;
index 2d2ac58c890ef5cd64fd72823f3bddd282ee2c44..5c5e61f86959bdbd3fb0ef6c65479785876c0671 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2010-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -20,13 +20,17 @@ private:
 
 public:
        VSlider();
+
+       virtual const char *get_class() const { return "vslider"; }
+
+private:
+       virtual void render_special(const Part &) const;
+
+public:
        virtual void button_press(int, int, unsigned);
        virtual void button_release(int, int, unsigned);
        virtual void pointer_motion(int, int);
 private:
-       virtual const char *get_class() const { return "vslider"; }
-       virtual void render_special(const Part &) const;
-
        virtual void on_geometry_change();
        virtual void on_style_change();
 };
index 434ec454ea022beb1a31964025c7a98808d25d8f..9cd9066bc82663150daa9ad8fddc65b629650c02 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007-2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -53,12 +53,44 @@ void Widget::set_geometry(const Geometry &g)
        on_geometry_change();
 }
 
+void Widget::set_parent(Container *p)
+{
+       if(parent && p)
+               throw InvalidState("Widget is already in a Container");
+       parent = p;
+
+       on_reparent();
+       update_style();
+}
+
 void Widget::set_style(const string &s)
 {
        style_name = s;
        update_style();
 }
 
+void Widget::update_style()
+{
+       Widget *top;
+       for(top=this; top->parent; top=top->parent) ;
+       Root *root = dynamic_cast<Root *>(top);
+       if(!root)
+               style = 0;
+       else
+       {
+               string sname = get_class();
+               if(!style_name.empty())
+               {
+                       sname += '-';
+                       sname += style_name;
+               }
+
+               style = root->get_resources().get<Style>(sname);
+       }
+
+       on_style_change();
+}
+
 void Widget::set_tooltip(const string &t)
 {
        tooltip = t;
@@ -129,48 +161,6 @@ void Widget::focus_out()
        state &= ~FOCUS;
 }
 
-void Widget::update_style()
-{
-       Widget *top;
-       for(top=this; top->parent; top=top->parent) ;
-       Root *root = dynamic_cast<Root *>(top);
-       if(!root)
-               style = 0;
-       else
-       {
-               string sname = get_class();
-               if(!style_name.empty())
-               {
-                       sname += '-';
-                       sname += style_name;
-               }
-
-               style = root->get_resources().get<Style>(sname);
-       }
-
-       on_style_change();
-}
-
-void Widget::update_style(Widget &w)
-{
-       w.update_style();
-}
-
-void Widget::set_parent(Container *p)
-{
-       if(parent && p)
-               throw InvalidState("Widget is already in a Container");
-       parent = p;
-
-       on_reparent();
-       update_style();
-}
-
-void Widget::set_parent(Widget &w, Container *p)
-{
-       w.set_parent(p);
-}
-
 
 Widget::Loader::Loader(Widget &w):
        wdg(w)
index d5bc0ff04c232504a657275b956b9f14c3ec36de..bc9b90a69696a8e944af0d88042ad318ab481ec1 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007-2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -26,6 +26,8 @@ constructor, because it can't be done correctly in the Widget constructor.
 */
 class Widget
 {
+       friend class Container;
+
 public:
        class Loader: public Msp::DataFile::Loader
        {
@@ -60,12 +62,25 @@ protected:
 public:
        virtual ~Widget();
 
+       /**
+       Returns the name of the widget class.  Used for style lookup.
+       */
+       virtual const char *get_class() const { return "widget"; }
+
        void set_position(int, int);
        void set_size(unsigned, unsigned);
        virtual void autosize() { }
        void set_geometry(const Geometry &);
        const Geometry &get_geometry() const { return geom; }
 
+protected:
+       /**
+       Sets the widget's parent Container.  The widget must be unparented when
+       calling this function with a non-null parameter.
+       */
+       void set_parent(Container *);
+
+public:
        /**
        Sets the widget style.  The final style name is constructed by concatenating
        the widget class and the style name with a dash.
@@ -73,6 +88,14 @@ public:
        void set_style(const std::string &);
        const Style &get_style() const { return *style; }
 
+protected:
+       /**
+       Gets a style object from the resource collection based on the class and
+       style names of the widget.
+       */
+       void update_style();
+
+public:
        void set_tooltip(const std::string &);
        const std::string &get_tooltip() const { return tooltip; }
 
@@ -97,33 +120,7 @@ public:
        virtual void key_release(unsigned, unsigned) { }
        virtual void focus_in();
        virtual void focus_out();
-
 protected:
-       /**
-       Returns the name of the widget class.  Used for style lookup.
-       */
-       virtual const char *get_class() const { return "widget"; }
-
-       /**
-       Gets a style object from the resource collection based on the class and
-       style names of the widget.
-       */
-       void update_style();
-
-       static void update_style(Widget &);
-
-       /**
-       Sets the widget's parent Panel.  The widget must be unparented when calling
-       this function with a nonzero parameter.
-       */
-       void set_parent(Container *);
-
-       /**
-       A helper function to set the parent of another widget.
-       */
-       static void set_parent(Widget &, Container *);
-
-       // More events
        virtual void on_geometry_change() { }
        virtual void on_style_change() { }
        virtual void on_reparent() { }