package "mspgltk"
{
require "mspgl";
+ require "mspgbase";
library "mspgltk"
{
#include <SDL/SDL_keysym.h>
#include <msp/gl/matrix.h>
+#include <msp/gl/texture.h>
#include <msp/gl/transform.h>
#include "entry.h"
#include "part.h"
Entry::Entry(const Resources &r, const string &t):
Widget(r),
text(t),
- edit_pos(0),
- active(false)
+ edit_pos(0)
{
+ update_style();
}
void Entry::set_text(const string &t)
void Entry::focus_in()
{
- active=true;
+ if(state!=DISABLED)
+ state=ACTIVE;
}
void Entry::focus_out()
{
- active=false;
+ if(state==ACTIVE)
+ state=NORMAL;
}
void Entry::render_part(const Part &part) const
{
if(part.get_name()=="text")
- {
+ render_text(part, text);
+ /*{
const GL::Font *const font=style->get_font();
const float font_size=font->get_default_size();
const Color &color=style->get_font_color();
glColor3f(color.r, color.g, color.b);
- if(active)
+ if(state==ACTIVE)
{
+ cout<<"foo\n";
font->draw_string(text.substr(0, edit_pos));
+ GL::Texture::unbind();
glBegin(GL_LINES);
glVertex2f(0, 0);
glVertex2f(0, 1);
GL::pop_matrix();
render_text(part, text);
- }
+ }*/
+ /*else if(part.get_name()=="cursor")
+ {
+ unsigned gw=part.get_width();
+ unsigned gh=(part.get_fill_y() ? geom.h : part.get_height());
+
+ const float font_size=font->get_default_size();
+ unsigned text_w=static_cast<unsigned>(font->get_string_width(text)*font_size);
+
+ GL::push_matrix();
+ GL::translate((geom.w-gw)*(value-min)/(max-min), (geom.h-gh)*(part.get_alignment().y+1)/2, 0);
+ const Graphic *graphic=part.get_graphic(state);
+ graphic->render(gw, gh);
+ GL::pop_matrix();
+ }*/
else
Widget::render_part(part);
}
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;
- bool active;
const char *get_class() const { return "entry"; }
void render_part(const Part &) const;
#ifndef MSP_GLTK_GEOMETRY_H_
#define MSP_GLTK_GEOMETRY_H_
-#include <msp/parser/loader.h>
+#include <msp/datafile/loader.h>
namespace Msp {
namespace GLtk {
*/
struct Sides
{
- class Loader: public Parser::Loader
+ class Loader: public DataFile::Loader
{
public:
Loader(Sides &);
#define MSP_GLTK_GRAPHIC_H_
#include <msp/gl/texture2d.h>
-#include <msp/parser/loader.h>
+#include <msp/datafile/loader.h>
#include "geometry.h"
namespace Msp {
class Graphic
{
public:
- class Loader: public Parser::Loader
+ class Loader: public DataFile::Loader
{
public:
Loader(Graphic &);
#include <map>
#include <string>
-#include <msp/parser/loader.h>
+#include <msp/datafile/loader.h>
#include "alignment.h"
#include "state.h"
class Part
{
public:
- class Loader: public Parser::Loader
+ class Loader: public DataFile::Loader
{
public:
Loader(Part &);
void Resources::Loader::font(const string &fn)
{
RefPtr<GL::Font> fnt=new GL::Font;
- Parser::load(*fnt, fn);
+ DataFile::load(*fnt, fn);
res.fonts.insert(FontMap::value_type(fn.substr(0, fn.rfind('.')), fnt.get()));
if(!res.default_font)
#include <msp/gl/font.h>
#include <msp/gl/texture.h>
-#include <msp/parser/loader.h>
+#include <msp/datafile/loader.h>
#include "graphic.h"
#include "style.h"
{
public:
- class Loader: public Msp::Parser::Loader
+ class Loader: public Msp::DataFile::Loader
{
public:
Loader(Resources &);
--- /dev/null
+#include "root.h"
+
+namespace Msp {
+namespace GLtk {
+
+Root::Root(Resources &r, Window &w):
+ Panel(r),
+ window(w)
+{
+ set_geometry(Geometry(0, 0, window.get_width(), window.get_height()));
+
+ window.signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
+ window.signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
+ window.signal_pointer_motion.connect(sigc::mem_fun(this, &Root::pointer_motion_event));
+}
+
+} // namespace GLtk
+} // namespace Msp
--- /dev/null
+#ifndef MSP_GLTK_ROOT_H_
+#define MSP_GLTK_ROOT_H_
+
+#include <msp/gbase/window.h>
+#include "panel.h"
+
+namespace Msp {
+namespace GLtk {
+
+class Root: public Panel
+{
+public:
+ Root(Resources &, Window &);
+private:
+ Window &window;
+
+ const char *get_class() const { return "root"; }
+ void button_press_event(int, int, unsigned, unsigned);
+ void button_release_event(int, int, unsigned, unsigned);
+ void pointer_motion_event(int, int);
+ void key_press_event(unsigned, unsigned, wchar_t);
+ void key_release_event(unsigned, unsigned);
+};
+
+} // namespace GLtk
+} // namespace Msp
+
+#endif
#define MSP_GLTK_STATE_H_
#include <istream>
-#include <msp/parser/value.h>
+#include <msp/datafile/value.h>
namespace Msp {
namespace GLtk {
} // namespace GLtk
-namespace Parser {
+namespace DataFile {
template<>
struct TypeResolver<GLtk::State> { static const Value::Type type=Value::ENUM; };
#define MSP_GLTK_STYLE_H_
#include <msp/gl/font.h>
-#include <msp/parser/loader.h>
+#include <msp/datafile/loader.h>
#include "color.h"
#include "part.h"
class Style
{
public:
- class Loader: public Parser::Loader
+ class Loader: public DataFile::Loader
{
public:
Loader(Style &);
+++ /dev/null
-#include <vector>
-#include <GL/glx.h>
-#include <msp/core/error.h>
-#include "window.h"
-
-using namespace std;
-
-namespace Msp {
-namespace GLtk {
-
-DisplayOptions::DisplayOptions():
- width(640),
- height(480),
- depth(24),
- alpha(false),
- doublebuffer(false),
- multisample(0),
- fullscreen(false)
-{ }
-
-
-Window::Window(unsigned w, unsigned h)
-{
- DisplayOptions dopt;
- dopt.width=w;
- dopt.height=h;
-
- init(dopt);
-}
-
-Window::Window(const DisplayOptions &dopt)
-{
- init(dopt);
-}
-
-Window::~Window()
-{
- XCloseDisplay(display);
-}
-
-void Window::show()
-{
- XMapWindow(display, window);
-}
-
-void Window::tick()
-{
- while(1)
- {
- int pending=XPending(display);
- if(pending==0)
- break;
-
- for(int i=0; i<pending; ++i)
- {
- XEvent event;
- XNextEvent(display, &event);
- process_event(event);
- }
- }
-}
-
-void Window::init(const DisplayOptions &dopt)
-{
- options=dopt;
-
- display=XOpenDisplay(0);
- if(!display)
- throw Exception("Couldn't open X display");
-
- vector<int> attribs;
- attribs.push_back(GLX_BUFFER_SIZE);
- attribs.push_back(dopt.depth);
- attribs.push_back(GLX_DOUBLEBUFFER);
- attribs.push_back(1);
- if(dopt.multisample>0)
- {
- attribs.push_back(GLX_SAMPLE_BUFFERS_ARB);
- attribs.push_back(dopt.multisample);
- }
-
- XVisualInfo *visual=glXChooseVisual(display, DefaultScreen(display), &attribs.front());
- if(!visual)
- throw Exception("Couldn't get a matching visual");
-
- window=XCreateWindow(display, DefaultRootWindow(display), 0, 0, dopt.width, dopt.height, 0, CopyFromParent, InputOutput, visual->visual, 0, 0);
-
- XSelectInput(display, window, ButtonPressMask|ButtonReleaseMask|MotionMask|KeyPressMask|KeyReleaseMask);
-}
-
-void Window::process_event(const XEvent &event)
-{
- switch(event.type)
- {
- case ButtonPress:
- signal_button_press.emit(event.button.x, event.button.y, event.button.button, event.button.state);
- break;
- case ButtonRelease:
- signal_button_release.emit(event.button.x, event.button.y, event.button.button, event.button.state);
- break;
- case PointerMotion:
- signal_pointer_motion.emit(event.motion.x, event.motion.y);
- break;
- case KeyPress:
- {
- char buf[16];
- XLookupString(event.key, buf, sizeof(buf), 0, 0);
- // XXX Handle the result according to locale
- signal_key_press.emit(event.key.keycode, event.key.state, buf[0]);
- }
- break;
- case KeyRelease:
- signal_key_release.emit(event.key.keycode, event.key.state);
- break;
- default:;
- }
-}
-
-} // namespace GLtk
-} // namespace Msp
+++ /dev/null
-#ifndef MSP_GLTK_WINDOW_H_
-#define MSP_GLTK_WINDOW_H_
-
-#include <X11/X.h>
-
-namespace Msp {
-namespace GLtk {
-
-struct DisplayOptions
-{
- unsigned width;
- unsigned height;
- unsigned depth;
- bool alpha;
- bool doublebuffer;
- unsigned multisample;
- bool fullscreen;
-
- DisplayOptions();
-};
-
-class Window
-{
-public:
- sigc::signal<int, int, unsigned, unsigned> signal_button_press;
- sigc::signal<int, int, unsigned, unsigned> signal_button_release;
- sigc::signal<int, int> signal_pointer_motion;
- sigc::signal<unsigned, unsigned, wchar_t> signal_key_press;
- sigc::signal<unsigned, unsigned> signal_key_release;
-
- Window(unsigned, unsigned);
- Window(const DisplayOptions &);
- ~Window();
-
- unsigned get_width() const { return options.width; }
- unsigned get_height() const { return options.height; }
- void show();
- void add(Widget &);
- void tick();
-private:
- Display *display;
- DisplayOptions options;
- ::Window window;
-
- void init(const DisplayOptions &);
- void process_event(const XEvent &);
-};
-
-} // namespace GLtk
-} // namespace Msp
-
-#endif