From 97b4a5904a989e216b1fbb4d0a55b7340bd7f88a Mon Sep 17 00:00:00 2001
From: pixel <pixel>
Date: Tue, 31 Jan 2006 17:02:39 +0000
Subject: Way too much changes - all over.

---
 lib/inputtext.cc | 28 +++++++-------------------
 lib/mcolor.cc    | 23 +++++++++++++++++++++-
 lib/texture.cc   | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/widgets.cc   | 26 +++++++++++-------------
 4 files changed, 99 insertions(+), 38 deletions(-)

(limited to 'lib')

diff --git a/lib/inputtext.cc b/lib/inputtext.cc
index 20aa34c..a73a8cd 100644
--- a/lib/inputtext.cc
+++ b/lib/inputtext.cc
@@ -17,7 +17,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-/* $Id: inputtext.cc,v 1.1 2005-12-02 16:21:59 pixel Exp $ */
+/* $Id: inputtext.cc,v 1.2 2006-01-31 17:02:39 pixel Exp $ */
 
 #include <SDL.h>
 #include <vector>
@@ -111,29 +111,20 @@ void mogltk::widgets::InputText::draw() {
 * The InputDialog child *
 ************************/
 
-class InputDialogAction : public mogltk::widgets::action {
-  public:
-      InputDialogAction(mogltk::widgets::InputDialog * _parent) : parent(_parent) { }
-    virtual void do_action(mogltk::widget *) {
-        parent->do_action();
-        delete parent;
-        delete this;
-    }
-  private:
-    mogltk::widgets::InputDialog * parent;
-};
-
-mogltk::widgets::InputDialog::InputDialog(mogltk::widgets::action * _a, shape * sh, mogltk::widget * father, const String & caption, const String & text, mogltk::font * _font) : SmartBox(sh, father, 0, 0, 0, 0, caption), a(_a), InputDialog_font(_font) {
+mogltk::widgets::InputDialog::InputDialog(mogltk::widgets::action * a, shape * sh, mogltk::widget * father, const String & caption, const String & text, mogltk::font * _font) : SmartBox(sh, father, 0, 0, 0, 0, caption), InputDialog_font(_font) {
     rect size = InputDialog_font->size(text);
     rect lsize = size;
 
+    Button * b;
+
     size.w += 12;
     size.h += 90;
     
     resize(size.w, size.h);
     center();
-
-    (it = new InputText((new Button(new InputDialogAction(this), sh, this, size.w / 2 - 25, size.h - 30, 50, 24, "Ok"))->cascade_action(), sh, this, 10, size.h - 60))->resize(size.w - 20, 20);
+    b = new Button(new ActionAndDelete(this, a), sh, this, size.w / 2 - 25, size.h - 30, 50, 24, "Ok");
+    it = new InputText(b->cascade_action(), sh, this, 10, size.h - 60);
+    it->resize(size.w - 20, 20);
     new Label(sh, this, 6, 24, lsize.w, lsize.h, text, BLACK, InputDialog_font);
 
     set_exclusive(father);
@@ -146,8 +137,3 @@ mogltk::widgets::InputDialog::~InputDialog() {
 String mogltk::widgets::InputDialog::GetText() {
     return it->GetText();
 }
-
-void mogltk::widgets::InputDialog::do_action() {
-    if (a)
-        a->do_action(this);
-}
diff --git a/lib/mcolor.cc b/lib/mcolor.cc
index e2a921d..618ae4f 100644
--- a/lib/mcolor.cc
+++ b/lib/mcolor.cc
@@ -17,7 +17,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-/* $Id: mcolor.cc,v 1.8 2004-11-27 21:48:03 pixel Exp $ */
+/* $Id: mcolor.cc,v 1.9 2006-01-31 17:02:39 pixel Exp $ */
 
 #include <SDL.h>
 #include <SDL_opengl.h>
@@ -50,6 +50,27 @@ void mogltk::ColorP::fromSDL(Uint32 p, SDL_PixelFormat * f) {
     SDL_GetRGBA(p, f, &c.R, &c.G, &c.B, &c.A);    
 }
 
+void mogltk::ColorP::fromHSV(double H, double S, double V) {
+    H = H / 60.0;
+    int Hi = ((int) H) % 6;
+    double f = H - Hi;
+    double p = V * (1 - S);
+    double q = V * (1 - f * S);
+    double t = V * (1 - (1 - f) * S);
+    double R, G, B;
+
+    switch (Hi) {
+        case 0: R = V; G = t; B = p; break;
+        case 1: R = q; G = V; B = p; break;
+        case 2: R = p; G = V; B = t; break;
+        case 3: R = p; G = q; B = V; break;
+        case 4: R = t; G = p; B = V; break;
+        case 5: R = V; G = p; B = q; break;
+    }
+
+    c.R = R * 255; c.G = G * 255; c.B = B * 255;
+}
+
 void mogltk::ColorP::Norm() {
     c.R = MIN(MAX(c.R, Min.R), Max.R);
     c.G = MIN(MAX(c.R, Min.G), Max.G);
diff --git a/lib/texture.cc b/lib/texture.cc
index a06c345..b94882a 100644
--- a/lib/texture.cc
+++ b/lib/texture.cc
@@ -17,7 +17,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-/* $Id: texture.cc,v 1.11 2004-11-27 21:48:03 pixel Exp $ */
+/* $Id: texture.cc,v 1.12 2006-01-31 17:02:39 pixel Exp $ */
 
 #include <sys/types.h>
 #include <SDL.h>
@@ -135,6 +135,64 @@ mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) :
     }
 }
 
+mogltk::texture::texture(SDL_Surface * temp, bool plane) throw (GeneralException) :
+    texture_allocated(false), planar(plane), tainted(true), taintable(true) {
+
+    width = temp->w;
+    height = temp->h;
+
+#ifdef DEBUG
+    printm(M_INFO, "Creating texture from file: size %ix%i\n", height, width);
+#endif
+
+    if ((!ISPOT(width)) || (!ISPOT(height))) {
+	throw GeneralException(_("Size of the texture not a power of 2!"));
+    }
+
+    SDL_PixelFormat f;
+
+    f.palette = 0;
+    f.BitsPerPixel = 32;
+    f.BytesPerPixel = 4;
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+    f.Amask = 0x000000ff;
+    f.Bmask = 0x0000ff00;
+    f.Gmask = 0x00ff0000;
+    f.Rmask = 0xff000000;
+    f.Ashift = 0;
+    f.Bshift = 8;
+    f.Gshift = 16;
+    f.Rshift = 24;
+#else
+    f.Rmask = 0x000000ff;
+    f.Gmask = 0x0000ff00;
+    f.Bmask = 0x00ff0000;
+    f.Amask = 0xff000000;
+    f.Rshift = 0;
+    f.Gshift = 8;
+    f.Bshift = 16;
+    f.Ashift = 24;
+#endif
+    f.Rloss = 0;
+    f.Gloss = 0;
+    f.Bloss = 0;
+    f.Aloss = 0;
+
+    if (!(surface = SDL_ConvertSurface(temp, &f, 0))) {
+	throw GeneralException("Could not convert texture to OpenGL format");
+    }
+    
+    next = 0;
+    prev = footer;
+    footer = this;
+    if (!header) {
+	header = this;
+    }
+    if (prev) {
+	prev->next = this;
+    }
+}
+
 inline static unsigned int nextpower(unsigned int n) {
     unsigned int i;
 
diff --git a/lib/widgets.cc b/lib/widgets.cc
index 0bc1d2e..1f98597 100644
--- a/lib/widgets.cc
+++ b/lib/widgets.cc
@@ -17,7 +17,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-/* $Id: widgets.cc,v 1.16 2005-12-02 16:21:59 pixel Exp $ */
+/* $Id: widgets.cc,v 1.17 2006-01-31 17:02:39 pixel Exp $ */
 
 #include <SDL.h>
 #include <vector>
@@ -54,7 +54,8 @@ class widget_mouse_event : public mogltk::engine::mouseevent {
     Uint32 old_click;
 };
 
-widget_mouse_event::widget_mouse_event(mogltk::widget * _root) : root(_root), mouse_down(false), mouse_drag(false) {
+widget_mouse_event::widget_mouse_event(mogltk::widget * _root) :
+  root(_root), mouse_down(false), mouse_drag(false) {
 }
 
 void widget_mouse_event::move(SDL_MouseMotionEvent m) {
@@ -210,6 +211,7 @@ mogltk::widget * mogltk::widget::focused = 0;
 
 mogltk::widget::widget(widget * _father, int _x, int _y, int _sx, int _sy, int _type, String _name, mogltk::shape * _sh) :
     x(_x), y(_y), sx(_sx), sy(_sy), father(_father), prev(0), child(0), last(0), panel(0), type(_type), name(_name), sh(_sh), exclusive(0), visible(true), enabled(true) {
+    LOCK;
     if (!father) {
 	root = this;
 	father = this;
@@ -227,6 +229,7 @@ mogltk::widget::widget(widget * _father, int _x, int _y, int _sx, int _sy, int _
 	father->child = this;
 	root = father->root;
     }
+    UNLOCK;
 
     computeabs();
 }
@@ -235,6 +238,7 @@ mogltk::widget::~widget() {
     while(child)
 	delete child;
     
+    LOCK;
     if (prev)
 	prev->next = next;
     else
@@ -262,12 +266,14 @@ mogltk::widget::~widget() {
         }
     }
 
+#if 0
     for (iw = to_delete.begin(); iw != to_delete.end(); iw++) {
         if (*iw == this) {
             to_delete.erase(iw);
             iw = to_delete.begin();
         }
     }
+#endif
 
     for (it = timed_events.begin(); it != timed_events.end(); it++) {
         if (it->w == this) {
@@ -275,6 +281,7 @@ mogltk::widget::~widget() {
             it = timed_events.begin();
         }
     }
+    UNLOCK;
 }
 
 void mogltk::widget::computeabs() {
@@ -815,18 +822,7 @@ mogltk::widgets::SmartBoxClose::SmartBoxClose(mogltk::shape * sh, mogltk::widget
 * The MessageBox child *
 ***********************/
 
-class MessageBoxAction : public mogltk::widgets::action {
-  public:
-      MessageBoxAction(mogltk::widget * _parent) : parent(_parent) { }
-    virtual void do_action(mogltk::widget *) {
-        delete parent;
-        delete this;
-    }
-  private:
-    mogltk::widget * parent;
-};
-
-mogltk::widgets::MsgBox::MsgBox(shape * sh, mogltk::widget * father, const String & caption, const String & text, mogltk::font * _font) : SmartBox(sh, father, 0, 0, 0, 0, caption), msgbox_font(_font) {
+mogltk::widgets::MsgBox::MsgBox(action * a, shape * sh, mogltk::widget * father, const String & caption, const String & text, mogltk::font * _font) : SmartBox(sh, father, 0, 0, 0, 0, caption), msgbox_font(_font) {
     rect size = msgbox_font->size(text);
     rect lsize = size;
 
@@ -836,7 +832,7 @@ mogltk::widgets::MsgBox::MsgBox(shape * sh, mogltk::widget * father, const Strin
     resize(size.w, size.h);
     center();
 
-    new Button(new MessageBoxAction(this), sh, this, size.w / 2 - 25, size.h - 30, 50, 24, "Ok");
+    new Button(new ActionAndDelete(this, a), sh, this, size.w / 2 - 25, size.h - 30, 50, 24, "Ok");
     new Label(sh, this, 6, 24, lsize.w, lsize.h, text, BLACK, msgbox_font);
 
     set_exclusive(father);
-- 
cgit v1.2.3