From: Mikko Rasa Date: Tue, 28 Aug 2007 20:18:12 +0000 (+0000) Subject: Change mspparser -> mspdatafile X-Git-Tag: 0.9~32 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=131ac8ff2c06f94d40f4bf98d4a6ec0d113cdffc;p=libs%2Fgltk.git Change mspparser -> mspdatafile Window is now in gbase Add Root widget --- diff --git a/Build b/Build index 45a22cb..b7bffe4 100644 --- a/Build +++ b/Build @@ -1,6 +1,7 @@ package "mspgltk" { require "mspgl"; + require "mspgbase"; library "mspgltk" { diff --git a/source/entry.cpp b/source/entry.cpp index 6daa8ef..65bae72 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "entry.h" #include "part.h" @@ -13,9 +14,9 @@ namespace GLtk { 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) @@ -50,18 +51,21 @@ void Entry::key_press(unsigned key, unsigned, wchar_t ch) 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(); @@ -74,9 +78,11 @@ void Entry::render_part(const Part &part) const 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); @@ -89,7 +95,21 @@ void Entry::render_part(const Part &part) const 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(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); } diff --git a/source/entry.h b/source/entry.h index b09ecb1..2c9c314 100644 --- a/source/entry.h +++ b/source/entry.h @@ -11,13 +11,13 @@ class Entry: public Widget 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; diff --git a/source/geometry.h b/source/geometry.h index 85e2816..fdef8ac 100644 --- a/source/geometry.h +++ b/source/geometry.h @@ -1,7 +1,7 @@ #ifndef MSP_GLTK_GEOMETRY_H_ #define MSP_GLTK_GEOMETRY_H_ -#include +#include namespace Msp { namespace GLtk { @@ -24,7 +24,7 @@ Specifies margins on the sides of an element. */ struct Sides { - class Loader: public Parser::Loader + class Loader: public DataFile::Loader { public: Loader(Sides &); diff --git a/source/graphic.h b/source/graphic.h index f4cc907..912786c 100644 --- a/source/graphic.h +++ b/source/graphic.h @@ -2,7 +2,7 @@ #define MSP_GLTK_GRAPHIC_H_ #include -#include +#include #include "geometry.h" namespace Msp { @@ -13,7 +13,7 @@ class Resources; class Graphic { public: - class Loader: public Parser::Loader + class Loader: public DataFile::Loader { public: Loader(Graphic &); diff --git a/source/part.h b/source/part.h index 08803dc..29085c2 100644 --- a/source/part.h +++ b/source/part.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include "alignment.h" #include "state.h" @@ -16,7 +16,7 @@ class Resources; class Part { public: - class Loader: public Parser::Loader + class Loader: public DataFile::Loader { public: Loader(Part &); diff --git a/source/resources.cpp b/source/resources.cpp index a61566a..aad671c 100644 --- a/source/resources.cpp +++ b/source/resources.cpp @@ -75,7 +75,7 @@ Resources::Loader::Loader(Resources &r): void Resources::Loader::font(const string &fn) { RefPtr 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) diff --git a/source/resources.h b/source/resources.h index 001fa63..40e4422 100644 --- a/source/resources.h +++ b/source/resources.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include "graphic.h" #include "style.h" @@ -14,7 +14,7 @@ class Resources { public: - class Loader: public Msp::Parser::Loader + class Loader: public Msp::DataFile::Loader { public: Loader(Resources &); diff --git a/source/root.cpp b/source/root.cpp new file mode 100644 index 0000000..f8a4d9f --- /dev/null +++ b/source/root.cpp @@ -0,0 +1,18 @@ +#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 diff --git a/source/root.h b/source/root.h new file mode 100644 index 0000000..01153f5 --- /dev/null +++ b/source/root.h @@ -0,0 +1,28 @@ +#ifndef MSP_GLTK_ROOT_H_ +#define MSP_GLTK_ROOT_H_ + +#include +#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 diff --git a/source/state.h b/source/state.h index 6cbe152..1f07c5c 100644 --- a/source/state.h +++ b/source/state.h @@ -2,7 +2,7 @@ #define MSP_GLTK_STATE_H_ #include -#include +#include namespace Msp { namespace GLtk { @@ -20,7 +20,7 @@ extern std::istream &operator>>(std::istream &, State &); } // namespace GLtk -namespace Parser { +namespace DataFile { template<> struct TypeResolver { static const Value::Type type=Value::ENUM; }; diff --git a/source/style.h b/source/style.h index a757abc..47cdabb 100644 --- a/source/style.h +++ b/source/style.h @@ -2,7 +2,7 @@ #define MSP_GLTK_STYLE_H_ #include -#include +#include #include "color.h" #include "part.h" @@ -14,7 +14,7 @@ class Resources; class Style { public: - class Loader: public Parser::Loader + class Loader: public DataFile::Loader { public: Loader(Style &); diff --git a/source/window.cpp b/source/window.cpp deleted file mode 100644 index 2ec55b9..0000000 --- a/source/window.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include -#include -#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 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 diff --git a/source/window.h b/source/window.h deleted file mode 100644 index 2b2b064..0000000 --- a/source/window.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef MSP_GLTK_WINDOW_H_ -#define MSP_GLTK_WINDOW_H_ - -#include - -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 signal_button_press; - sigc::signal signal_button_release; - sigc::signal signal_pointer_motion; - sigc::signal signal_key_press; - sigc::signal 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