]> git.tdb.fi Git - libs/gltk.git/commitdiff
Change mspparser -> mspdatafile
authorMikko Rasa <tdb@tdb.fi>
Tue, 28 Aug 2007 20:18:12 +0000 (20:18 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 28 Aug 2007 20:18:12 +0000 (20:18 +0000)
Window is now in gbase
Add Root widget

14 files changed:
Build
source/entry.cpp
source/entry.h
source/geometry.h
source/graphic.h
source/part.h
source/resources.cpp
source/resources.h
source/root.cpp [new file with mode: 0644]
source/root.h [new file with mode: 0644]
source/state.h
source/style.h
source/window.cpp [deleted file]
source/window.h [deleted file]

diff --git a/Build b/Build
index 45a22cb627e87d33ee99119c8034f4328d597d1a..b7bffe45fbee37e52760c9de3b138d27b2ad79e5 100644 (file)
--- a/Build
+++ b/Build
@@ -1,6 +1,7 @@
 package "mspgltk"
 {
        require "mspgl";
+       require "mspgbase";
 
        library "mspgltk"
        {
index 6daa8ef1b1083c1361522d64bc3e845df228c2ad..65bae7214001e842929aab8618982dfbf11cdc84 100644 (file)
@@ -1,5 +1,6 @@
 #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"
@@ -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<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);
 }
index b09ecb1f024d131161d76771d6b1a5ff7dd33059..2c9c31448cd4f2c6c3b6403297956109427b412e 100644 (file)
@@ -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;
index 85e28161930841dfa1bb358b4489c16e888935f7..fdef8ace97d45557d9450f4fca535c3fc2446e01 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef MSP_GLTK_GEOMETRY_H_
 #define MSP_GLTK_GEOMETRY_H_
 
-#include <msp/parser/loader.h>
+#include <msp/datafile/loader.h>
 
 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 &);
index f4cc907223a3ea6fd9a009fefb0f4b0013bbd6f9..912786ce380f195fd173460d3406ed8087eec4ee 100644 (file)
@@ -2,7 +2,7 @@
 #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 {
@@ -13,7 +13,7 @@ class Resources;
 class Graphic
 {
 public:
-       class Loader: public Parser::Loader
+       class Loader: public DataFile::Loader
        {
        public:
                Loader(Graphic &);
index 08803dc5a7074b5d2ff71f8797f785603dc42d88..29085c2a4d5d81b87cd6669dd6e04f07f1a6e4c5 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <map>
 #include <string>
-#include <msp/parser/loader.h>
+#include <msp/datafile/loader.h>
 #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 &);
index a61566ae2e8556e0bb5327a498fa08dbef183dae..aad671c393729adc4608d3d6024378bcf44bbe35 100644 (file)
@@ -75,7 +75,7 @@ Resources::Loader::Loader(Resources &r):
 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)
index 001fa632b2a2a275776199d5795fa7451cf2d4b6..40e44220a5b7de1b53011a14cb16d2ebe67ee6ee 100644 (file)
@@ -3,7 +3,7 @@
 
 #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"
 
@@ -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 (file)
index 0000000..f8a4d9f
--- /dev/null
@@ -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 (file)
index 0000000..01153f5
--- /dev/null
@@ -0,0 +1,28 @@
+#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
index 6cbe152ead5fdbd41a230b1cf668b2c5f9c9bad8..1f07c5cf21b4a0d8796d939062041caaa6978993 100644 (file)
@@ -2,7 +2,7 @@
 #define MSP_GLTK_STATE_H_
 
 #include <istream>
-#include <msp/parser/value.h>
+#include <msp/datafile/value.h>
 
 namespace Msp {
 namespace GLtk {
@@ -20,7 +20,7 @@ extern std::istream &operator>>(std::istream &, State &);
 
 } // namespace GLtk
 
-namespace Parser {
+namespace DataFile {
 
 template<>
 struct TypeResolver<GLtk::State> { static const Value::Type type=Value::ENUM; };
index a757abc820d1e1c08c4724e284ef84050ec2d284..47cdabba88b74ec254e5df4d45ff48fa4abdf324 100644 (file)
@@ -2,7 +2,7 @@
 #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"
 
@@ -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 (file)
index 2ec55b9..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-#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
diff --git a/source/window.h b/source/window.h
deleted file mode 100644 (file)
index 2b2b064..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#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