+/* $Id$ */
+
package "mspgltk"
{
require "mspgl";
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include <msp/gl/transform.h>
#include "alignment.h"
#include "geometry.h"
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_ALIGNMENT_H_
#define MSP_GLTK_ALIGNMENT_H_
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include "button.h"
#include "part.h"
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_BUTTON_H_
#define MSP_GLTK_BUTTON_H_
namespace Msp {
namespace GLtk {
+/**
+A clickable button widget. Buttons can have a text label, which is displayed
+in a spacial part "text".
+*/
class Button: public Widget
{
public:
Button &get_object() const;
};
+private
+ std::string text;
+ bool pressed;
+
+public:
sigc::signal<void> signal_clicked;
Button(const Resources &, const std::string & =std::string());
void pointer_enter();
void pointer_leave();
private:
- std::string text;
- bool pressed;
-
const char *get_class() const { return "button"; }
void render_part(const Part &) const;
};
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include <SDL/SDL_keysym.h>
#include <msp/gl/matrix.h>
#include <msp/gl/texture.h>
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_ENTRY_H_
#define MSP_GLTK_ENTRY_H_
namespace Msp {
namespace GLtk {
+/**
+Text entry field.
+
+Special parts:
+
+ text The current text of the widget. Graphics are ignored.
+ cursor Indicates the current input position. Fill_x is ignored.
+*/
class Entry: public Widget
{
+private:
+ std::string text;
+ unsigned edit_pos;
+
public:
Entry(const Resources &, const std::string & =std::string());
+
void set_text(const std::string &);
const std::string &get_text() const { return text; }
+
void key_press(unsigned, unsigned, wchar_t);
void focus_in();
void focus_out();
private:
- std::string text;
- unsigned edit_pos;
-
const char *get_class() const { return "entry"; }
void render_part(const Part &) const;
};
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include "geometry.h"
namespace Msp {
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_GEOMETRY_H_
#define MSP_GLTK_GEOMETRY_H_
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include <msp/gl/immediate.h>
#include "graphic.h"
#include "resources.h"
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_GRAPHIC_H_
#define MSP_GLTK_GRAPHIC_H_
class Resources;
+/**
+Stores a single graphical element. Graphics are used as parts of widgets.
+*/
class Graphic
{
public:
void shadow();
};
+private:
+ Sides border;
+ Sides shadow;
+ const GL::Texture2D *texture;
+ Geometry slice;
+ bool repeat;
+
+public:
Graphic();
const Sides &get_border() const { return border; }
const Sides &get_shadow() const { return shadow; }
unsigned get_height() const { return slice.h; }
void render(unsigned, unsigned) const;
private:
- Sides border;
- Sides shadow;
- const GL::Texture2D *texture;
- Geometry slice;
- bool repeat;
-
void create_coords(float, float, float, float, float, std::vector<float> &) const;
void create_texcoords(float, float, float, float, float, std::vector<float> &) const;
};
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include <msp/gl/matrix.h>
#include <msp/gl/transform.h>
#include "graphic.h"
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_HSLIDER_H_
#define MSP_GLTK_HSLIDER_H_
namespace Msp {
namespace GLtk {
+/**
+Horizontal slider widget. A special part named "slider" will be positioned at
+the current value of the widget. The fill_x attribute is ignored.
+*/
class HSlider: public Slider
{
+private:
+ bool dragging;
+ int drag_start_x;
+ double drag_start_value;
+
public:
HSlider(const Resources &);
void button_press(int, int, unsigned);
void button_release(int, int, unsigned);
void pointer_motion(int, int);
private:
- bool dragging;
- int drag_start_x;
- double drag_start_value;
-
const char *get_class() const { return "hslider"; }
void render_part(const Part &) const;
unsigned get_slider_width() const;
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include "indicator.h"
namespace Msp {
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_INDICATOR_H_
#define MSP_GLTK_INDICATOR_H_
namespace Msp {
namespace GLtk {
+/**
+An Indicator visualizes a boolean state. It can be either active or inactive.
+*/
class Indicator: public Widget
{
public:
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include "label.h"
#include "part.h"
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_LABEL_H_
#define MSP_GLTK_LABEL_H_
namespace Msp {
namespace GLtk {
+/**
+Labels display static text. There is one special part: "text".
+*/
class Label: public Widget
{
public:
Label &get_object();
};
- Label(const Resources &, const std::string & =std::string());
- void set_text(const std::string &);
private:
std::string text;
+public:
+ Label(const Resources &, const std::string & =std::string());
+ void set_text(const std::string &);
+
+private:
const char *get_class() const { return "label"; }
void render_part(const Part &) const;
};
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include <msp/core/refptr.h>
#include "button.h"
#include "label.h"
delete *i;
}
+void Panel::add(Widget &wdg)
+{
+ children.push_back(&wdg);
+}
+
void Panel::button_press(int x, int y, unsigned btn)
{
if(pointer_grab>0)
set_input_focus(0);
}
-void Panel::add(Widget &wdg)
-{
- children.push_back(&wdg);
-}
-
void Panel::render_part(const Part &part) const
{
if(part.get_name()=="children")
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_PANEL_H_
#define MSP_GLTK_PANEL_H_
namespace Msp {
namespace GLtk {
+/**
+Panels are containers for other widgets. Panel styles should have a special
+part "children" to render the child widgets. All properties of this part are
+ignored.
+*/
class Panel: public Widget
{
public:
void panel(const std::string &);
};
+private:
+ typedef std::list<Widget *> ChildSeq;
+
+ ChildSeq children;
+ Widget *pointer_focus;
+ unsigned pointer_grab;
+ Widget *input_focus;
+
+ Panel(const Panel &);
+ Panel &operator=(const Panel &);
+public:
Panel(const Resources &);
~Panel();
void add(Widget &);
+
void button_press(int, int, unsigned);
void button_release(int, int, unsigned);
void pointer_motion(int, int);
void key_release(unsigned, unsigned);
void focus_out();
private:
- typedef std::list<Widget *> ChildSeq;
-
- ChildSeq children;
- Widget *pointer_focus;
- unsigned pointer_grab;
- Widget *input_focus;
-
- Panel(const Panel &);
- Panel &operator=(const Panel &);
const char *get_class() const { return "panel"; }
void render_part(const Part &) const;
void set_pointer_focus(Widget *);
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include "geometry.h"
#include "part.h"
#include "resources.h"
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_PART_H_
#define MSP_GLTK_PART_H_
class Graphic;
class Resources;
+/**
+Defines a single graphical element of a widget style.
+*/
class Part
{
public:
void fill(bool, bool);
};
+private:
+ std::string name;
+ const Graphic *graphic[N_STATES_];
+ unsigned width;
+ unsigned height;
+ Alignment align;
+ bool fill_x;
+ bool fill_y;
+
+public:
Part(const std::string &);
const std::string &get_name() const { return name; }
const Graphic *get_graphic(State) const;
bool get_fill_x() const { return fill_x; }
bool get_fill_y() const { return fill_y; }
void render(const Geometry &, State) const;
-private:
- std::string name;
- const Graphic *graphic[N_STATES_];
- unsigned width;
- unsigned height;
- Alignment align;
- bool fill_x;
- bool fill_y;
};
typedef std::list<Part> PartSeq;
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include <msp/core/except.h>
#include "resources.h"
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_RESOURCES_H_
#define MSP_GLTK_RESOURCES_H_
namespace Msp {
namespace GLtk {
+/**
+Stores resources such as styles and graphics. All widgets require a Resources
+instance in constructor.
+*/
class Resources: public DataFile::Collection
{
private:
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include "root.h"
namespace Msp {
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_ROOT_H_
#define MSP_GLTK_ROOT_H_
namespace Msp {
namespace GLtk {
+/**
+A Root is a special type of Panel that covers and entire Window and accepts
+input from it. When created, a Root widget will take its size from the window
+it is created for. The size can be changed, but a Root should always be
+rendered to fill the window in order to get coordinates mapped correctly.
+*/
class Root: public Panel
{
-public:
- Root(Resources &, Window &);
private:
Window &window;
+public:
+ Root(Resources &, Window &);
+private:
const char *get_class() const { return "root"; }
void button_press_event(int, int, unsigned, unsigned);
void button_release_event(int, int, unsigned, unsigned);
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include "slider.h"
namespace Msp {
step(0.1)
{ }
-void Slider::set_range(double a, double b)
-{
- min=a;
- max=b;
- set_value(value);
-}
-
-void Slider::set_step(double s)
-{
- step=s;
- set_value(value);
-}
-
void Slider::set_value(double v)
{
double old_value=value;
signal_value_changed.emit(value);
}
+void Slider::set_range(double a, double b)
+{
+ min=a;
+ max=b;
+ set_value(value);
+}
+
+void Slider::set_step(double s)
+{
+ step=s;
+ set_value(value);
+}
+
} // namespace GLtk
} // namespace Msp
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_SLIDER_H_
#define MSP_GLTK_SLIDER_H_
namespace Msp {
namespace GLtk {
+/**
+Sliders are used to adjust numeric values visually. This class provides the
+common interface for sliders - see classes HSlider and VSlider (NYI) for
+concrete variations.
+*/
class Slider: public Widget
{
+protected:
+ double min, max;
+ double value;
+ double step;
+
public:
sigc::signal<void, double> signal_value_changed;
+protected:
+ Slider(const Resources &);
+public:
void set_value(double);
void set_range(double, double);
void set_step(double);
double get_value() const { return value; }
-protected:
- double min, max;
- double value;
- double step;
-
- Slider(const Resources &);
};
} // namespace GLtk
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include "state.h"
using namespace std;
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_STATE_H_
#define MSP_GLTK_STATE_H_
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include "resources.h"
#include "style.h"
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_STYLE_H_
#define MSP_GLTK_STYLE_H_
class Resources;
+/**
+Styles define what wigets look like. They are made up of Parts and some
+generic properties.
+*/
class Style
{
public:
void part(const std::string &);
};
- Style();
- const GL::Font *get_font() const { return font; }
- const GL::Color &get_font_color() const { return font_color; }
- const PartSeq &get_parts() const { return parts; }
private:
const GL::Font *font;
GL::Color font_color;
PartSeq parts;
+
+public:
+ Style();
+ const GL::Font *get_font() const { return font; }
+ const GL::Color &get_font_color() const { return font_color; }
+ const PartSeq &get_parts() const { return parts; }
};
} // namespace GLtk
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include <msp/gl/matrix.h>
#include <msp/gl/transform.h>
#include "resources.h"
#include "widget.h"
-#include <iostream>
using namespace std;
namespace Msp {
namespace GLtk {
+Widget::Widget(const Resources &r):
+ res(r),
+ style(0),
+ state(NORMAL),
+ visible(true)
+{ }
+
void Widget::set_position(int x, int y)
{
geom.x=x;
GL::pop_matrix();
}
-Widget::Widget(const Resources &r):
- res(r),
- style(0),
- state(NORMAL),
- visible(true)
-{ }
-
-void Widget::update_style()
-{
- string sname=get_class();
- if(!style_name.empty())
- {
- sname+='-';
- sname+=style_name;
- }
- style=res.get<Style>(sname);
-}
-
void Widget::render_part(const Part &part) const
{
render_graphic(part);
GL::pop_matrix();
}
+void Widget::update_style()
+{
+ string sname=get_class();
+ if(!style_name.empty())
+ {
+ sname+='-';
+ sname+=style_name;
+ }
+ style=res.get<Style>(sname);
+}
+
Widget::Loader::Loader(Widget &w):
wdg(w)
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#ifndef MSP_GLTK_WIDGET_H_
#define MSP_GLTK_WIDGET_H_
class Resources;
class Style;
+/**
+Base class for all widgets. Derived classes should call update_style in
+constructor, because it can't be done correctly in the Widget constructor.
+*/
class Widget
{
public:
void style(const std::string &);
};
+protected:
+ const Resources &res;
+ Geometry geom;
+ std::string style_name;
+ const Style *style;
+ State state;
+ bool visible;
+
+ Widget(const Resources &);
+public:
virtual ~Widget() { }
void set_position(int, int);
void set_size(unsigned, unsigned);
void set_geometry(const Geometry &);
+
+ /**
+ Sets the widget style. The final style name is constructed by concatenating
+ the widget class and the style name with a dash.
+ */
void set_style(const std::string &);
+
const Geometry &get_geometry() const { return geom; }
bool is_visible() const { return visible; }
+
void render() const;
+protected:
+ virtual void render_part(const Part &) const;
+ void render_graphic(const Part &) const;
+ void render_text(const Part &, const std::string &) const;
+
+public:
+ // Events
virtual void button_press(int, int, unsigned) { }
virtual void button_release(int, int, unsigned) { }
virtual void pointer_motion(int, int) { }
virtual void key_release(unsigned, unsigned) { }
virtual void focus_in() { }
virtual void focus_out() { }
-protected:
- const Resources &res;
- Geometry geom;
- std::string style_name;
- const Style *style;
- State state;
- bool visible;
- Widget(const Resources &);
+protected:
+ /**
+ Returns the name of the widget class. Used for style lookup.
+ */
virtual const char *get_class() const { return "widget"; }
+
void update_style();
- virtual void render_part(const Part &) const;
- void render_graphic(const Part &) const;
- void render_text(const Part &, const std::string &) const;
};
} // namespace GLtk