]> git.tdb.fi Git - libs/gltk.git/commitdiff
Simplify constructors with C++11
authorMikko Rasa <tdb@tdb.fi>
Sun, 20 Aug 2023 09:10:32 +0000 (12:10 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 20 Aug 2023 10:01:19 +0000 (13:01 +0300)
Use default member initializers, defaulted constructors and constructor
delegation.

54 files changed:
source/arrangement.cpp
source/arrangement.h
source/button.cpp
source/button.h
source/container.cpp
source/container.h
source/dialog.cpp
source/dialog.h
source/draghandle.cpp
source/draghandle.h
source/dropdown.cpp
source/dropdown.h
source/entry.cpp
source/entry.h
source/geometry.cpp
source/geometry.h
source/graphic.cpp
source/graphic.h
source/grid.cpp
source/grid.h
source/image.cpp
source/image.h
source/inputmethod.h
source/layout.cpp
source/layout.h
source/lineararrangement.cpp
source/lineararrangement.h
source/list.cpp
source/list.h
source/listdata.h
source/panel.cpp
source/panel.h
source/part.cpp
source/part.h
source/partcache.cpp
source/partcache.h
source/progressbar.cpp
source/progressbar.h
source/resources.cpp
source/resources.h
source/root.cpp
source/root.h
source/slider.cpp
source/slider.h
source/style.cpp
source/style.h
source/systemkeyboardinput.cpp
source/systemkeyboardinput.h
source/text.cpp
source/text.h
source/toggle.cpp
source/toggle.h
source/widget.cpp
source/widget.h

index 838a488ea9fdfccebef388b22241bb5771542dbc..2adb9654ae059a2abf823add64d5f165297268bb 100644 (file)
@@ -79,10 +79,6 @@ Layout::ConstraintType Arrangement::get_align_constraint(Side s)
 }
 
 
-Arrangement::Edge::Edge():
-       aligned(false)
-{ }
-
 void Arrangement::Edge::clear()
 {
        widgets.clear();
index 31001c4d081686e8932e68acf541f1a0b6fb957e..164a091c6a9032bdb3078d54e928e3ceee480483 100644 (file)
@@ -32,9 +32,7 @@ protected:
        struct Edge
        {
                std::list<Widget *> widgets;
-               bool aligned;
-
-               Edge();
+               bool aligned = false;
 
                bool empty() { return widgets.empty(); }
                void clear();
@@ -43,7 +41,7 @@ protected:
        };
 
        Layout &layout;
-       Arrangement *parent;
+       Arrangement *parent = 0;
        Edge edges[4];
 
        Arrangement(Layout &);
index abdc1f677b0ff379220813ae67cc0a16187c561a..0dd20c7a6abb841cd4d2f9e98d1b75030d912d98 100644 (file)
@@ -8,10 +8,7 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-Button::Button(const std::string &t):
-       text(),
-       icon(0),
-       pressed(false)
+Button::Button(const std::string &t)
 {
        input_type = INPUT_NAVIGATION;
        set_text(t);
index 2af9cf9d02c520b8cc1beb39f6b5f12230f249c5..09084f183a938defe07b07a45045cacb4ab1532a 100644 (file)
@@ -29,8 +29,8 @@ public:
 
 private:
        Text text;
-       const GL::Texture2D *icon;
-       bool pressed;
+       const GL::Texture2D *icon = 0;
+       bool pressed = false;
 
 public:
        Button(const std::string & = std::string());
index d5fa6d59e3d0882fc593611c640af316d6124947..ef837a2d26180a20faa9808bec18fc7868cab0d3 100644 (file)
@@ -12,17 +12,6 @@ hierarchy_error::hierarchy_error(const string &w):
 { }
 
 
-Container::Container():
-       click_focus(0),
-       click_button(0),
-       pointer_focus(0),
-       pointer_grabbed(false),
-       input_focus(0),
-       saved_input_focus(0),
-       touch_focus(0),
-       children_rebuild_needed(false)
-{ }
-
 Container::~Container()
 {
        while(!children.empty())
index 4c38675ea85e4f1dbc2cab354feb183c2ef8b780..61502e44177c2d963f617da91fc1e4e5d86a570d 100644 (file)
@@ -24,7 +24,7 @@ protected:
        struct Child: public sigc::trackable
        {
                Container &container;
-               Widget *widget;
+               Widget *widget = 0;
                Time::TimeDelta time_since_animate;
 
                Child(Container &, Widget *);
@@ -39,16 +39,16 @@ protected:
        };
 
        std::list<Child *> children;
-       Widget *click_focus;
-       unsigned click_button;
-       Widget *pointer_focus;
-       bool pointer_grabbed;
-       Widget *input_focus;
-       Widget *saved_input_focus;
-       Widget *touch_focus;
-       bool children_rebuild_needed;
-
-       Container();
+       Widget *click_focus = 0;
+       unsigned click_button = 0;
+       Widget *pointer_focus = 0;
+       bool pointer_grabbed = false;
+       Widget *input_focus = 0;
+       Widget *saved_input_focus = 0;
+       Widget *touch_focus = 0;
+       bool children_rebuild_needed = false;
+
+       Container() = default;
 public:
        virtual ~Container();
 
index a264fbe87ce753de12b4b7c89ba76d5a849f2fa9..5f63dcf75ed519fbf52c65e723422304fe395234 100644 (file)
@@ -6,10 +6,6 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-Dialog::Dialog():
-       stale(false)
-{ }
-
 void Dialog::add_button(Button &button, int code)
 {
        add(button);
index 3eb3f98d2845cbe77a68f592ce418dc38103597d..e71222739cc415acf1876f3e1f3e60a560f11752 100644 (file)
@@ -27,11 +27,9 @@ public:
        sigc::signal<void, int> signal_response;
 
 private:
-       bool stale;
+       bool stale = false;
 
 public:
-       Dialog();
-
        virtual const char *get_class() const { return "dialog"; }
 
        /** Adds an action button to the dialog.  Pressing the button will invoke
index 067a515c2b533e39bc31dca4f60c872056719c81..c9e7c58d9102970c498ba0a75bce6f1b70c345e1 100644 (file)
@@ -4,12 +4,6 @@
 namespace Msp {
 namespace GLtk {
 
-DragHandle::DragHandle():
-       dragging(false),
-       drag_x(0),
-       drag_y(0)
-{ }
-
 void DragHandle::button_press(int x, int y, unsigned btn)
 {
        if(btn==1 && parent)
index 0aae73231877a819cecff1aff7ed733d9d4f6d17..d3cd6f2b94cd88c6c17f9d22381c289308e26b47 100644 (file)
@@ -14,13 +14,11 @@ into a movable window.
 class MSPGLTK_API DragHandle: public Widget
 {
 private:
-       bool dragging;
-       int drag_x;
-       int drag_y;
+       bool dragging = false;
+       int drag_x = 0;
+       int drag_y = 0;
 
 public:
-       DragHandle();
-
        virtual const char *get_class() const { return "draghandle"; }
 
        virtual void button_press(int, int, unsigned);
index 1084612304f03b68a303af130aa2b3bd3b1b2f82..68c1beed1321fea803981b36701246576273a397 100644 (file)
@@ -27,8 +27,6 @@ void Dropdown::init()
 {
        input_type = INPUT_NAVIGATION;
 
-       dropped = false;
-
        add(list);
        list.set_visible(false);
        list.set_view_all();
index 2de7a87afc2126210c52cd81cec1cc96dee30394..70a9faaf646c4b6381bd023eda3262d0a48c41cd 100644 (file)
@@ -27,7 +27,7 @@ public:
 
 private:
        List list;
-       bool dropped;
+       bool dropped = false;
        Text text;
 
 public:
index 7ee7a32cdd9e6f8cecb77a2297e55b61fa0a5a07..19bbaf9dc693f685a875ef962dcb03ac3a42340c 100644 (file)
@@ -13,20 +13,7 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-Entry::Entry(const string &t):
-       text(),
-       multiline(false),
-       edit_width(10),
-       edit_height(1),
-       edit_pos(0),
-       first_row(0),
-       visible_rows(1),
-       text_part(0),
-       slider(0),
-       got_key_press(false),
-       cursor_blink(true),
-       selection_active(false),
-       selection_pos(0)
+Entry::Entry(const string &t)
 {
        input_type = INPUT_TEXT;
        set_text(t);
index 60beef78f80ab1f371d488c61778f1696a59ca78..871024da89af32b33c4f8ae1864370a817f488e7 100644 (file)
@@ -39,18 +39,18 @@ public:
 
 private:
        Text text;
-       bool multiline;
-       unsigned edit_width;
-       unsigned edit_height;
-       unsigned edit_pos;
-       unsigned first_row;
-       unsigned visible_rows;
-       const Part *text_part;
-       VSlider *slider;
-       bool got_key_press;
-       bool cursor_blink;
-       bool selection_active;
-       unsigned selection_pos;
+       bool multiline = false;
+       unsigned edit_width = 10;
+       unsigned edit_height = 1;
+       unsigned edit_pos = 0;
+       unsigned first_row = 0;
+       unsigned visible_rows = 1;
+       const Part *text_part = 0;
+       VSlider *slider = 0;
+       bool got_key_press = false;
+       bool cursor_blink = true;
+       bool selection_active = false;
+       unsigned selection_pos = 0;
 
 public:
        Entry(const std::string & = std::string());
index 0cb78ffcc392d636a45a7e7469d4ea5690601bbb..ba47c0593c620d13bc0a403457fb05c947f31af6 100644 (file)
@@ -14,13 +14,6 @@ bool Geometry::is_inside_relative(int x_, int y_) const
 }
 
 
-Sides::Sides():
-       top(0),
-       right(0),
-       bottom(0),
-       left(0)
-{ }
-
 Sides::Sides(unsigned s):
        top(s),
        right(s),
index 8c8c9897335caa0fd55ea79666c2f78de1a73db0..fac3bbc7a506ea9cde32a37fad8a5e50618d562a 100644 (file)
@@ -12,10 +12,12 @@ Specifies the position and size of a widget or graphic.
 */
 struct MSPGLTK_API Geometry
 {
-       int x, y;
-       unsigned w, h;
+       int x = 0;
+       int y = 0;
+       unsigned w = 1;
+       unsigned h = 1;
 
-       Geometry(): x(0), y(0), w(1), h(1) { }
+       Geometry() = default;
        Geometry(int x_, int y_, unsigned w_, unsigned h_): x(x_), y(y_), w(w_), h(h_) { }
        bool is_inside(int, int) const;
        bool is_inside_relative(int, int) const;
@@ -36,12 +38,12 @@ struct MSPGLTK_API Sides
                void vertical(unsigned);
        };
 
-       unsigned top;
-       unsigned right;
-       unsigned bottom;
-       unsigned left;
+       unsigned top = 0;
+       unsigned right = 0;
+       unsigned bottom = 0;
+       unsigned left = 0;
 
-       Sides();
+       Sides() = default;
        Sides(unsigned);
        Sides(unsigned, unsigned);
        Sides(unsigned, unsigned, unsigned);
@@ -54,10 +56,11 @@ Performs alignment of nested geometries, such as widgets and their parts.
 */
 struct MSPGLTK_API Alignment
 {
-       float x, y;
-       float w, h;
+       float x = 0.0f;
+       float y = 0.0f;
+       float w = 1.0f;
+       float h = 1.0f;
 
-       Alignment(): x(0), y(0), w(1), h(1) { }
        void apply(Geometry &, const Geometry &) const;
        void apply(Geometry &, const Geometry &, const Sides &) const;
 };
index 75e10888ecde2eebef7202659aaf21320520fba8..095e19441be082aed682be2f4b6a928229cbe7fb 100644 (file)
@@ -6,11 +6,6 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-Graphic::Graphic():
-       texture(0),
-       repeat(false)
-{ }
-
 void Graphic::build(unsigned wd, unsigned ht, GL::PrimitiveBuilder &bld) const
 {
        vector<float> x, y;
index 4fed368938016e8613e4a6132155d932889d48a0..b114d7e1c96eba41fd555453d71cb6d1b5dd4cc4 100644 (file)
@@ -33,12 +33,11 @@ public:
 private:
        Sides border;
        Sides shadow;
-       const GL::Texture2D *texture;
+       const GL::Texture2D *texture = 0;
        Geometry slice;
-       bool repeat;
+       bool repeat = false;
 
 public:
-       Graphic();
        const Sides &get_border() const { return border; }
        const Sides &get_shadow() const { return shadow; }
        const GL::Texture2D *get_texture() const { return texture; }
index 3b44ac857e0058e9e6d34de38ffd158aced3e17e..c8631cf84bc6d6b6e8ed4ac714a2c9dac1e44213 100644 (file)
@@ -5,9 +5,7 @@ namespace GLtk {
 
 Grid::Grid(Layout &l, unsigned c):
        Arrangement(l),
-       columns(c),
-       first_row(true),
-       column(0)
+       columns(c)
 { }
 
 void Grid::skip()
index 29d7b6d37257686cfd0d56b8abb274a333c556f5..9324f95fac937b1bb53c1d1167a861da338109d8 100644 (file)
@@ -30,8 +30,8 @@ private:
        std::vector<Column> columns;
        Edge row_top;
        Edge row_bottom;
-       bool first_row;
-       unsigned column;
+       bool first_row = true;
+       unsigned column = 0;
 
 public:
        Grid(Layout &, unsigned);
index bc9185672d13b5cb070333857e5a37c90143f6df..8dbf6cf74fe881e6e871be3894e0ae51aa3147b6 100644 (file)
@@ -11,8 +11,7 @@ namespace Msp {
 namespace GLtk {
 
 Image::Image(const GL::Texture2D *i):
-       image(i),
-       keep_aspect(true)
+       image(i)
 {
 }
 
index 77357561ead0a54fc147681e580bd67fa80c989c..026aaca82aebbcc4b326b706d4df052f98ea3d8d 100644 (file)
@@ -21,9 +21,9 @@ public:
        };
 
 private:
-       const GL::Texture2D *image;
+       const GL::Texture2D *image = 0;
        std::string icon_name;
-       bool keep_aspect;
+       bool keep_aspect = true;
 
 public:
        Image(const GL::Texture2D * = 0);
index 1e0f613383392dae36e84dae944fe2a3115364be..28019cd1e9a26b000e05b214ae4df8c972641788 100644 (file)
@@ -43,7 +43,7 @@ protected:
 
        InputMethod(Root &);
 public:
-       virtual ~InputMethod() { }
+       virtual ~InputMethod() = default;
 };
 
 } // namespace GLtk
index 200801f36285b7c3d9ed55402fd764a27f0a8813..b6248e6ad8511bb8dbaa9bc0d1ba5b1eaeaa18ba 100644 (file)
@@ -37,11 +37,11 @@ private:
                Column();
        };
 
-       unsigned n_columns;
-       unsigned n_rows;
+       unsigned n_columns = 1;
+       unsigned n_rows = 1;
        std::vector<Column> columns;
-       bool solved;
-       bool infeasible;
+       bool solved = false;
+       bool infeasible = false;
 
 public:
        LinearProgram(unsigned);
@@ -85,17 +85,6 @@ Layout::Pointers Layout::pointers[2] =
 } };
 
 
-Layout::Layout():
-       container(0),
-       n_active_slots(0),
-       margin(8),
-       row_spacing(5),
-       col_spacing(4)
-{
-       n_slack_vars[0] = 0;
-       n_slack_vars[1] = 0;
-}
-
 Layout::~Layout()
 {
        for(Slot *s: slots)
@@ -481,23 +470,13 @@ void Layout::solve_constraints(int dir, SolveMode mode)
 
 Layout::Constraint::Constraint(ConstraintType t, Slot &s):
        type(t),
-       target(s),
-       spacing(-1)
-{ }
-
-
-Layout::Packing::Packing():
-       gravity(-1),
-       expand(false)
+       target(s)
 { }
 
 
 Layout::Slot::Slot(Layout &l, Widget &w):
        layout(l),
-       index(0),
-       widget(w),
-       ghost(false),
-       floating(false)
+       widget(w)
 {
        vert_pack.gravity = 1;
        widget.signal_autosize_changed.connect(sigc::mem_fun(this, &Slot::autosize_changed));
@@ -647,10 +626,7 @@ void operator>>(const LexicalConverter &conv, Layout::ConstraintType &ctype)
 
 Layout::LinearProgram::LinearProgram(unsigned s):
        n_columns(s),
-       n_rows(1),
-       columns(n_columns),
-       solved(false),
-       infeasible(false)
+       columns(n_columns)
 { }
 
 Layout::LinearProgram::Row Layout::LinearProgram::add_row()
index 7986686c86e440757cbe6d2172526fa8844b275e..8b1c527640e4e29e69bd61c3f9fab4a4188044be 100644 (file)
@@ -133,31 +133,29 @@ private:
        {
                ConstraintType type;
                Slot &target;
-               int spacing;
+               int spacing = -1;
 
                Constraint(ConstraintType, Slot &);
        };
 
        struct Packing
        {
-               int gravity;
-               bool expand;
-
-               Packing();
+               int gravity = -1;
+               bool expand = false;
        };
 
        struct Slot: public sigc::trackable
        {
                Layout &layout;
-               int index;
+               int index = 0;
                Widget &widget;
                Geometry autosize_geom;
                Geometry geom;
                std::list<Constraint> constraints;
                Packing horiz_pack;
                Packing vert_pack;
-               bool ghost;
-               bool floating;
+               bool ghost = false;
+               bool floating = false;
 
                Slot(Layout &, Widget &);
 
@@ -174,20 +172,19 @@ private:
        class LinearProgram;
        struct Pointers;
 
-       Container *container;
+       Container *container = 0;
        std::list<Slot *> slots;
-       unsigned n_active_slots;
-       unsigned n_slack_vars[2];
-       Sides margin;
-       unsigned row_spacing;
-       unsigned col_spacing;
+       unsigned n_active_slots = 0;
+       unsigned n_slack_vars[2] = { 0, 0 };
+       Sides margin{ 8 };
+       unsigned row_spacing = 5;
+       unsigned col_spacing = 4;
        Geometry autosize_geom;
        std::list<Arrangement *> arrangement_stack;
 
        static Pointers pointers[2];
 
 public:
-       Layout();
        ~Layout();
 
        void set_container(Container &);
index 5294252a11b5f38ffec445c24880e0d4009f69eb..3ac686e85d9fded12a71fdfaabf7b6a75f71f4e0 100644 (file)
@@ -5,15 +5,7 @@ namespace GLtk {
 
 LinearArrangement::LinearArrangement(Layout &l, Side p):
        Arrangement(l),
-       primary(p),
-       opposite(static_cast<Side>((primary+2)%4)),
-       first(true),
-       split_here(false),
-       gravity(opposite),
-       internal_aligned(false),
-       uniform(false),
-       uniform_ref(0),
-       next_spacing(-1)
+       primary(p)
 { }
 
 void LinearArrangement::set_uniform(bool u)
index 71ffcfeebe43314d30a75dbf80a218e6c2023bd9..917b595cb8caa8dae8259fa579cb619ef94bffe7 100644 (file)
@@ -23,16 +23,16 @@ public:
        };
 
 protected:
-       Side primary;
-       Side opposite;
+       Side primary = RIGHT;
+       Side opposite = static_cast<Side>(primary^2);
        Edge next;
-       bool first;
-       bool split_here;
-       Side gravity;
-       bool internal_aligned;
-       bool uniform;
-       Widget *uniform_ref;
-       int next_spacing;
+       bool first = true;
+       bool split_here = false;
+       Side gravity = opposite;
+       bool internal_aligned = false;
+       bool uniform = false;
+       Widget *uniform_ref = 0;
+       int next_spacing = -1;
 
        LinearArrangement(Layout &, Side);
 
index 5dd6d3ead5619927d7f31ed1747c2c72d221c885..897ea39ebadb972decb3e7fe8dd8a876ac58089d 100644 (file)
@@ -21,39 +21,17 @@ incompatible_data::incompatible_data(const type_info &ti):
 
 
 List::List():
-       data(new BasicListData<string>),
-       own_data(true)
+       List(*new BasicListData<string>)
 {
-       init();
+       own_data = true;
 }
 
 List::List(ListData &d):
        data(&d),
-       own_data(false)
-{
-       init();
-}
-
-void List::init()
+       observer(new DataObserver(*this))
 {
        input_type = INPUT_NAVIGATION;
 
-       item_factory = 0;
-       view_mode = LIST;
-       sel_index = -1;
-       focus_index = -1;
-       first_row = 0;
-       max_scroll = 0;
-       view_rows = 5;
-       view_columns = 5;
-       items_part = 0;
-       ignore_slider_change = false;
-       dragging = false;
-       drag_start_x = 0;
-       drag_start_y = 0;
-
-       observer = new DataObserver(*this);
-
        add(slider);
        slider.set_step(1);
        slider.signal_value_changed.connect(sigc::mem_fun(this, &List::slider_value_changed));
index 68a96bf36cb65fb0c9361a0b1a156984cc1cd12f..9bc30c685d146a88d9d3b0fc8b886037f7ffa724 100644 (file)
@@ -81,7 +81,7 @@ public:
        class SimpleItem: public Item
        {
        protected:
-               SimpleItem() { }
+               SimpleItem() = default;
 
                virtual void on_style_change();
        };
@@ -89,7 +89,7 @@ public:
        class MultiColumnItem: public Item
        {
        protected:
-               MultiColumnItem() { }
+               MultiColumnItem() = default;
 
                virtual void check_widths(std::vector<unsigned> &) const;
                virtual void set_widths(const std::vector<unsigned> &);
@@ -110,9 +110,9 @@ private:
        class ItemFactory
        {
        protected:
-               ItemFactory() { }
+               ItemFactory() = default;
        public:
-               virtual ~ItemFactory() { }
+               virtual ~ItemFactory() = default;
 
                virtual void set_data(const ListData &) = 0;
                virtual Item *create_item(unsigned) const = 0;
@@ -157,22 +157,22 @@ public:
        sigc::signal<void> signal_selection_cleared;
 
 private:
-       ListData *data;
-       bool own_data;
-       DataObserver *observer;
-       ItemFactory *item_factory;
-       ViewMode view_mode;
-       int sel_index;
-       int focus_index;
-       unsigned first_row;
-       unsigned max_scroll;
-       unsigned view_rows;
-       unsigned view_columns;
-       const Part *items_part;
-       bool ignore_slider_change;
-       bool dragging;
-       int drag_start_x;
-       int drag_start_y;
+       ListData *data = 0;
+       bool own_data = false;
+       DataObserver *observer = 0;
+       ItemFactory *item_factory = 0;
+       ViewMode view_mode = LIST;
+       int sel_index = -1;
+       int focus_index = -1;
+       unsigned first_row = 0;
+       unsigned max_scroll = 0;
+       unsigned view_rows = 5;
+       unsigned view_columns = 5;
+       const Part *items_part = 0;
+       bool ignore_slider_change = false;
+       bool dragging = false;
+       int drag_start_x = 0;
+       int drag_start_y = 0;
 
        VSlider slider;
        std::vector<Item *> items;
@@ -181,9 +181,6 @@ private:
 public:
        List();
        List(ListData &);
-private:
-       void init();
-public:
        virtual ~List();
 
        virtual const char *get_class() const { return "list"; }
index 9f7d8ba850c7476e857dc911d60de5cd7e7e329c..00d2b9b65a154e587789b7ffaf18af1ad2334007 100644 (file)
@@ -20,9 +20,9 @@ public:
        sigc::signal<void, unsigned> signal_refresh_item;
 
 protected:
-       ListData() { }
+       ListData() = default;
 public:
-       virtual ~ListData() { }
+       virtual ~ListData() = default;
 
        virtual unsigned size() const = 0;
        virtual std::string get_string(unsigned) const = 0;
@@ -40,7 +40,7 @@ class ListDataStore: public ListData
 protected:
        std::vector<T> items;
 
-       ListDataStore() { }
+       ListDataStore() = default;
 
 public:
        void append(const T &v) { insert(items.size(), v); }
@@ -111,7 +111,7 @@ public:
        typedef std::string Func(const T &);
 
 private:
-       Func *func;
+       Func *func = 0;
 
 public:
        FunctionListData(Func f): func(f) { }
index fa16ec7de2826733d04a876f7ec445953bc76a8d..871d7a2d9ebffb211d1bdc3f389a4fd6374e31e6 100644 (file)
@@ -27,8 +27,7 @@ namespace GLtk {
 TypeRegistry<Panel::Loader::AddChildType, Panel::Loader &> Panel::widget_registry;
 bool Panel::widget_registry_init_done = false;
 
-Panel::Panel():
-       layout(0)
+Panel::Panel()
 {
        input_type = INPUT_NAVIGATION;
 }
index 22f03a22a7174cd32838e6eb7fed6b8f95d6bd5b..4b013a8b469eb363ac0a79a35c60b757aecee267 100644 (file)
@@ -67,7 +67,7 @@ private:
 
 protected:
        std::vector<Widget *> nav_order;
-       Layout *layout;
+       Layout *layout = 0;
 
        static TypeRegistry<Loader::AddChildType, Loader &> widget_registry;
        static bool widget_registry_init_done;
index 22aa378f3f41d52146c473243b821938031ffc0c..21dacc64da547123209388128b0f246b4d6f8014 100644 (file)
@@ -11,9 +11,7 @@ namespace GLtk {
 
 Part::Part(const string &n):
        name(n)
-{
-       fill(graphic, graphic+N_STATES_, static_cast<Graphic *>(0));
-}
+{ }
 
 const Graphic *Part::get_graphic(State state) const
 {
index a8776c2924b8d03308e0c109a8fa6531ec3ca8e2..35b8f7d52d820333f74d9f44a0aa23e26dfd313c 100644 (file)
@@ -36,7 +36,7 @@ public:
 
 private:
        std::string name;
-       const Graphic *graphic[N_STATES_];
+       const Graphic *graphic[N_STATES_] = { };
        Geometry geom;
        Sides margin;
        Alignment align;
index 3b944572a45abb8874b06a7f4313e569fab123dd..f4c085e5baa47c4230786eba92a2feb50ac8cf50 100644 (file)
@@ -6,22 +6,12 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-CachedPart::CachedPart():
-       part(0),
-       texture(0),
-       mesh(0)
-{ }
-
 CachedPart::~CachedPart()
 {
        delete mesh;
 }
 
 
-PartCache::PartCache():
-       rebuilding(false)
-{ }
-
 void PartCache::begin_rebuild()
 {
        if(rebuilding)
index 9dc71bf184c8652de6b5e4939a8bab9224a2f512..af697339efcfa0ed5e46cb998235e0c156ac13c0 100644 (file)
@@ -12,11 +12,10 @@ class Part;
 
 struct CachedPart
 {
-       const Part *part;
-       const GL::Texture2D *texture;
-       GL::Mesh *mesh;
+       const Part *part = 0;
+       const GL::Texture2D *texture = 0;
+       GL::Mesh *mesh = 0;
 
-       CachedPart();
        ~CachedPart();
 };
 
@@ -36,14 +35,12 @@ public:
        typedef std::list<CachedPart> PartList;
 
 private:
-       bool rebuilding;
+       bool rebuilding = false;
        PartList parts;
        PartList::iterator next;
        PartList::iterator current;
 
 public:
-       PartCache();
-
        void begin_rebuild();
        void insert_special(const Part &);
        GL::Mesh &create_mesh(const Part &, const GL::Texture2D &);
index 9c7bcea0fec9fbedc631f7263f13b4ce5bfca2a2..7c6def7c37e2c14c9bf8390d3dd6cd0d206e50fb 100644 (file)
@@ -8,11 +8,6 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-ProgressBar::ProgressBar():
-       range(1),
-       fraction(0)
-{ }
-
 void ProgressBar::set_range(float r)
 {
        if(r<=0)
index d167410028ac18716706f5a7bff92b81e06e0c2a..6e44e731dff4a3355371aa04eb69376d66eaeffd 100644 (file)
@@ -10,12 +10,10 @@ namespace GLtk {
 class MSPGLTK_API ProgressBar: public Widget
 {
 private:
-       float range;
-       float fraction;
+       float range = 1.0f;
+       float fraction = 0.0f;
 
 public:
-       ProgressBar();
-
        virtual const char *get_class() const { return "progressbar"; }
 
        void set_range(float);
index 06fa44cf0c502867a1ecb255bea5de9251cc6314..3cfd8306275cb5e0ae47268e4dd013749531d310 100644 (file)
@@ -10,13 +10,18 @@ namespace GLtk {
 
 Resources::Resources()
 {
-       init();
+       add_type<Graphic>().keyword("graphic");
+       add_type<GL::Module>().creator([this](const string &n){ return create_module(n); });
+       add_type<GL::Sampler>().creator([this](const string &n){ return create_sampler(n); });
+       add_type<GL::Program>().creator([this](const string &n){ return create_program(n); });
+       add_type<GL::Texture2D>().keyword("texture").creator([this](const string &n){ return create_texture(n); });
+       add_type<GL::Font>().keyword("font");
+       add_type<Style>().keyword("style");
 }
 
-Resources::Resources(const FS::Path &fn)
+Resources::Resources(const FS::Path &fn):
+       Resources()
 {
-       init();
-
        dir_src = new DataFile::DirectorySource;
        dir_src->add_directory(FS::dirname(fn));
        add_source(*dir_src);
@@ -24,19 +29,6 @@ Resources::Resources(const FS::Path &fn)
        DataFile::load(*this, fn.str());
 }
 
-void Resources::init()
-{
-       default_font = 0;
-       dir_src = 0;
-       add_type<Graphic>().keyword("graphic");
-       add_type<GL::Module>().creator([this](const string &n){ return create_module(n); });
-       add_type<GL::Sampler>().creator([this](const string &n){ return create_sampler(n); });
-       add_type<GL::Program>().creator([this](const string &n){ return create_program(n); });
-       add_type<GL::Texture2D>().keyword("texture").creator([this](const string &n){ return create_texture(n); });
-       add_type<GL::Font>().keyword("font");
-       add_type<Style>().keyword("style");
-}
-
 Resources::~Resources()
 {
        delete dir_src;
index ce85b972aec6ecae2003054dc7cd8fa5a29176c0..1fd030d03438674510ac66e7cb6c49e13cfca5df 100644 (file)
@@ -37,15 +37,12 @@ public:
 
 private:
        FS::Path path;
-       GL::Font *default_font;
-       DataFile::DirectorySource *dir_src;
+       GL::Font *default_font = 0;
+       DataFile::DirectorySource *dir_src = 0;
 
 public:
        Resources();
        Resources(const FS::Path &);
-private:
-       void init();
-public:
        ~Resources();
 
        const GL::Font &get_default_font() const;
index ef83bb9de3af842b8fe37878d1f4eb2185d36c12..5ea447fecdf46d48f0013aa3f832e5aef9fe8348 100644 (file)
@@ -11,35 +11,20 @@ namespace Msp {
 namespace GLtk {
 
 Root::Root(Resources &r, Graphics::Window &window):
-       resources(r),
-       keyboard(new Input::Keyboard(window)),
-       input_method(0),
-       mouse(new Input::Mouse(window)),
-       touchscreen(0),
-       own_input(true)
+       Root(r, &window, new Input::Keyboard(window), new Input::Mouse(window), 0)
 {
-       init(&window);
+       own_input = true;
 }
 
 Root::Root(Resources &r, Graphics::Window *window, Input::Keyboard *k, Input::Mouse *m, Input::Touchscreen *t):
        resources(r),
        keyboard(k),
-       input_method(0),
        mouse(m),
-       touchscreen(t),
-       own_input(false)
-{
-       init(window);
-}
-
-void Root::init(Graphics::Window *window)
+       touchscreen(t)
 {
        if(window)
                set_geometry(Geometry(0, 0, window->get_width(), window->get_height()));
 
-       lbl_tooltip = 0;
-       tooltip_target = 0;
-
        camera.set_orthographic(geom.w, geom.h);
        update_camera();
 
index 52e23cae677ee6f03df4ee48a8f25d35400954d9..9ebe7cf57d823fdf59cf63d25829251f51b0b806 100644 (file)
@@ -32,19 +32,19 @@ public:
 
 private:
        Resources &resources;
-       Input::Keyboard *keyboard;
-       InputMethod *input_method;
-       Input::Mouse *mouse;
-       Input::Touchscreen *touchscreen;
-       bool own_input;
-       Label *lbl_tooltip;
-       int pointer_x;
-       int pointer_y;
+       Input::Keyboard *keyboard = 0;
+       InputMethod *input_method = 0;
+       Input::Mouse *mouse = 0;
+       Input::Touchscreen *touchscreen = 0;
+       bool own_input = false;
+       Label *lbl_tooltip = 0;
+       int pointer_x = 0;
+       int pointer_y = 0;
        Time::TimeStamp tooltip_timeout;
        Time::TimeStamp last_tick;
-       Widget *tooltip_target;
+       Widget *tooltip_target = 0;
        Msp::GL::Camera camera;
-       Msp::GL::Program *shprog;
+       Msp::GL::Program *shprog = 0;
        Msp::GL::Blend blend;
 
 public:
@@ -55,9 +55,6 @@ public:
        /** Creates a Root widget with custom input devices.  If window is not null,
        it is used to set the widget's initial geometry. */
        Root(Resources &, Graphics::Window *, Input::Keyboard *, Input::Mouse *, Input::Touchscreen * = 0);
-private:
-       void init(Graphics::Window *);
-public:
        virtual ~Root();
 
        virtual const char *get_class() const { return "root"; }
index aaaa8519ebcd7b1bf1afa48b21789fb803735720..cca717f6309c7b1f8b2f39040a3b0b6915432f9a 100644 (file)
@@ -9,18 +9,7 @@ namespace Msp {
 namespace GLtk {
 
 Slider::Slider(Direction d):
-       dir(d),
-       min(0),
-       max(1),
-       value(0),
-       step(0.1),
-       page_size(0.25),
-       dragging(false),
-       drag_area_size(0),
-       drag_area_offset(0),
-       slider_min_size(1),
-       slider_size(1),
-       total_margin(0)
+       dir(d)
 { }
 
 void Slider::set_value(double v)
index 7b878d21fb2f1f6a32be486d4154c05e273c65ed..70c5fc59b2882d948f7ceb543465bde4127e0895 100644 (file)
@@ -34,19 +34,20 @@ public:
 
 protected:
        Direction dir;
-       double min, max;
-       double value;
-       double step;
-       double page_size;
-
-       bool dragging;
-       double drag_start_pos;
-       double drag_start_value;
-       unsigned drag_area_size;
-       unsigned drag_area_offset;
-       unsigned slider_min_size;
-       unsigned slider_size;
-       unsigned total_margin;
+       double min = 0.0;
+       double max = 1.0;
+       double value = 0.0;
+       double step = 0.1;
+       double page_size = 0.25;
+
+       bool dragging = false;
+       double drag_start_pos = 0.0;
+       double drag_start_value = 0.0;
+       unsigned drag_area_size = 0;
+       unsigned drag_area_offset = 0;
+       unsigned slider_min_size = 1;
+       unsigned slider_size = 1;
+       unsigned total_margin = 0;
 
        Slider(Direction);
 
index acbdff54febbda18dce5df7a7cc265fb16e2a647..d1dea041dca0e010dcfa294c9252259c5fea2d60 100644 (file)
@@ -7,12 +7,6 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-Style::Style():
-       font(0),
-       font_size(0),
-       sampler(0)
-{ }
-
 const GL::Font &Style::get_font() const
 {
        if(!font)
index 8a3e3a9958c1a3a86c9b0ba08c1316d7458999bb..ee25b251dcb50ba932efe40d368f465ab78719c9 100644 (file)
@@ -36,14 +36,13 @@ public:
        typedef std::list<Part> PartSeq;
 
 private:
-       const GL::Font *font;
-       unsigned font_size;
+       const GL::Font *font = 0;
+       unsigned font_size = 0;
        GL::Color font_color[N_STATES_];
-       const GL::Sampler *sampler;
+       const GL::Sampler *sampler = 0;
        PartSeq parts;
 
 public:
-       Style();
        const GL::Font &get_font() const;
        unsigned get_font_size() const { return font_size; }
        const GL::Color &get_font_color(State) const;
index 862dd2926d88a5b0538cfdb5fb1d41201ec4b3e9..3c4439856944f71becb1414a05c7541ef44f1995 100644 (file)
@@ -7,8 +7,7 @@ namespace GLtk {
 
 SystemKeyboardInput::SystemKeyboardInput(Root &r, Input::Keyboard &k):
        InputMethod(r),
-       keyboard(k),
-       modifier_state(0)
+       keyboard(k)
 {
        keyboard.signal_button_press.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_press));
        keyboard.signal_button_release.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_release));
index 999c7ce7363439f8465d1669cf0c176125ff3fa7..9e4b3625701f824a19285c945fc0b7463389d99f 100644 (file)
@@ -12,7 +12,7 @@ class MSPGLTK_API SystemKeyboardInput: public InputMethod, public sigc::trackabl
 {
 private:
        Input::Keyboard &keyboard;
-       unsigned modifier_state;
+       unsigned modifier_state = 0;
 
 public:
        SystemKeyboardInput(Root &, Input::Keyboard &);
index bffb6e6a86cc0b33f6b35285d6a22338cfb7c8ae..166bbb5212c7145fbc1c39bbfccf44cf7441354f 100644 (file)
@@ -25,15 +25,8 @@ struct Text::CoordsToGeomData
 
 
 Text::Text():
-       style(0)
-{
-       Line line;
-       line.start = 0;
-       line.bytes = 0;
-       line.length = 0;
-       line.width = 0;
-       lines.push_back(line);
-}
+       lines(1)
+{ }
 
 Text::Text(const Style &s, const string &t):
        style(&s)
index 708380ab60f68734e126485f166bbb5ad0b93058..cdde08c2b081aa42804ec16bf6d0656c343c8d3c 100644 (file)
@@ -22,16 +22,16 @@ class MSPGLTK_API Text
 private:
        struct Line
        {
-               unsigned start;
-               unsigned bytes;
-               unsigned length;
-               unsigned width;
+               unsigned start = 0;
+               unsigned bytes = 0;
+               unsigned length = 0;
+               unsigned width = 0;
        };
 
        struct RenderData;
        struct CoordsToGeomData;
 
-       const Style *style;
+       const Style *style = 0;
        std::string text;
        std::vector<Line> lines;
 
index bc40276baf6f1b35c5e6d769b1730eed93f3d4e0..cde3f24b0fd81254bd643aeeca592a8ac55db787 100644 (file)
@@ -8,11 +8,7 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-Toggle::Toggle(const string &t):
-       text(),
-       pressed(false),
-       value(false),
-       exclusive(false)
+Toggle::Toggle(const string &t)
 {
        input_type = INPUT_NAVIGATION;
        set_text(t);
index 0f6c610b00ffdd69a08b4fdd1bdf2e902711e7c8..7c572c51e98c74d18cbf5860e56d6460224afb23 100644 (file)
@@ -28,9 +28,9 @@ public:
 
 private:
        Text text;
-       bool pressed;
-       bool value;
-       bool exclusive;
+       bool pressed = false;
+       bool value = false;
+       bool exclusive = false;
 
 public:
        Toggle(const std::string & = std::string());
index 6ac4d2aa7d7679bc39512614ff32705f835891b6..0181e451e95163f40d67c06fda793dceb554e55b 100644 (file)
@@ -10,15 +10,6 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-Widget::Widget():
-       style(0),
-       state(NORMAL),
-       visible(true),
-       input_type(INPUT_NONE),
-       parent(0),
-       rebuild_needed(false)
-{ }
-
 Widget::~Widget()
 {
        if(parent)
index 19db87985780223df3a85b51e6f1b5eae77aac72..9b86691e48343344b723af0ad2d90726d82ff6b6 100644 (file)
@@ -47,17 +47,17 @@ public:
 protected:
        Geometry geom;
        std::string style_name;
-       const Style *style;
-       State state;
-       bool visible;
-       InputType input_type;
-       Container *parent;
+       const Style *style = 0;
+       State state = NORMAL;
+       bool visible = true;
+       InputType input_type = INPUT_NONE;
+       Container *parent = 0;
        std::string tooltip;
        PartCache part_cache;
-       bool rebuild_needed;
+       bool rebuild_needed = false;
        Time::TimeDelta anim_interval;
 
-       Widget();
+       Widget() = default;
 private:
        Widget(const Widget &);
        Widget &operator=(const Widget &);