]> git.tdb.fi Git - libs/gltk.git/commitdiff
Clear focus in Panel if focused child is removed
authorMikko Rasa <tdb@tdb.fi>
Sun, 1 Jun 2008 18:24:32 +0000 (18:24 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sun, 1 Jun 2008 18:24:32 +0000 (18:24 +0000)
Translate keys from system to internal codes in Root
Some GL coloring tweaks

source/entry.cpp
source/graphic.cpp
source/panel.cpp
source/root.cpp
source/widget.cpp

index 9f7c761802f5de84af3e77a764788f929865cf7c..efb4b45c57d354ca4f11b453ff567fe58d108421 100644 (file)
@@ -8,6 +8,7 @@ Distributed under the LGPL
 #include <msp/gl/matrix.h>
 #include <msp/gl/texture.h>
 #include <msp/gl/transform.h>
+#include <msp/input/keys.h>
 #include "entry.h"
 #include "graphic.h"
 #include "part.h"
@@ -15,13 +16,15 @@ Distributed under the LGPL
 
 using namespace std;
 
+#include <iostream>
+
 namespace Msp {
 namespace GLtk {
 
 Entry::Entry(const Resources &r, const string &t):
        Widget(r),
        text(t),
-       edit_pos(0)
+       edit_pos(text.size())
 {
        update_style();
 }
@@ -29,30 +32,29 @@ Entry::Entry(const Resources &r, const string &t):
 void Entry::set_text(const string &t)
 {
        text=t;
-       if(edit_pos>text.size())
-               edit_pos=text.size();
+       edit_pos=text.size();
 }
 
 void Entry::key_press(unsigned key, unsigned, wchar_t ch)
 {
-       if(key==100)
+       if(key==Input::KEY_LEFT)
        {
                if(edit_pos>0)
                        --edit_pos;
        }
-       else if(key==102)
+       else if(key==Input::KEY_RIGHT)
        {
                if(edit_pos<text.size())
                        ++edit_pos;
        }
-       else if(key==22)
+       else if(key==Input::KEY_BACKSPACE)
        {
                if(edit_pos>0)
                        text.erase(--edit_pos, 1);
        }
        else
        {
-               text+=ch;
+               text.insert(edit_pos, Codecs::encode<Codecs::Utf8>(Codecs::ustring(1, ch)));
                ++edit_pos;
        }
 }
index 0c874c8d1c0dd785e4bfe024822a35139c1fa801..9b613a74bf0a83381f2c7cf02aacf5326844a377 100644 (file)
@@ -21,9 +21,6 @@ Graphic::Graphic():
 
 void Graphic::render(unsigned wd, unsigned ht) const
 {
-       GL::VertexArray varr((GL::TEXCOORD2, GL::VERTEX2));
-       RefPtr<GL::VertexArrayBuilder> vab=varr.modify();
-
        vector<float> x, y;
        create_coords(0.0f-shadow.left, wd+shadow.right, border.left, border.right, slice.w-border.left-border.right, x);
        create_coords(0.0f-shadow.bottom, ht+shadow.top, border.bottom, border.top, slice.h-border.bottom-border.top, y);
@@ -38,7 +35,8 @@ void Graphic::render(unsigned wd, unsigned ht) const
        unsigned ymax=y.size()-(border.top ? 2 : 3);
 
        texture->bind();
-       GL::Immediate imm((GL::TEXCOORD2,GL::VERTEX2));
+       GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
+       imm.color(1.0f, 1.0f, 1.0f);
        imm.begin(GL::QUADS);
        for(unsigned i=ymin; i<=ymax; ++i)
        {
index 4d0d5d1359ef71cb0ea770c43bb6011daa839ad5..a4b27699f693c71ff7f01a62b939ce60377d96d3 100644 (file)
@@ -50,6 +50,11 @@ void Panel::remove(Widget &wdg)
        ChildSeq::iterator i=find(children.begin(), children.end(), &wdg);
        if(i!=children.end())
        {
+               if(&wdg==pointer_focus)
+                       set_pointer_focus(0, 0);
+               if(&wdg==input_focus)
+                       set_input_focus(0);
+
                set_parent(wdg, 0);
                children.erase(i);
        }
index 224e5bc30ef3a975fb022da83a6ba19e4be64779..1c030e82c8c38f103fa5234bde231163fceb3706 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2007  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include <msp/input/keys.h>
 #include "root.h"
 
 namespace Msp {
@@ -55,13 +56,13 @@ void Root::pointer_motion_event(int x, int y)
 void Root::key_press_event(unsigned key, unsigned mod, wchar_t ch)
 {
        if(visible)
-               key_press(key, mod, ch);
+               key_press(Input::key_from_sys(key), mod, ch);
 }
 
 void Root::key_release_event(unsigned key, unsigned mod)
 {
        if(visible)
-               key_release(key, mod);
+               key_release(Input::key_from_sys(key), mod);
 }
 
 void Root::translate_coords(int &x, int &y)
index be1f0a0cc90fb981bc0ea1a121e3f3f92d95030e..efb6155ef4a51d8fb4e69bde95323ea4e10c250d 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2007  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include <msp/gl/immediate.h>
 #include <msp/gl/matrix.h>
 #include <msp/gl/transform.h>
 #include <msp/strings/formatter.h>
@@ -108,9 +109,9 @@ void Widget::render_text(const Part &part, const string &text) const
        GL::scale_uniform(font_size);
 
        const GL::Color &color=style->get_font_color();
-       glColor3f(color.r, color.g, color.b);
-       font->draw_string(text);
-       glColor3f(1, 1, 1);
+       GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
+       imm.color(color.r, color.g, color.b);
+       font->draw_string(text, imm);
 
        GL::pop_matrix();
 }