summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2006-01-31 17:02:39 +0000
committerpixel <pixel>2006-01-31 17:02:39 +0000
commit97b4a5904a989e216b1fbb4d0a55b7340bd7f88a (patch)
tree2a40bfc8ae9f4fce9bf9a30bfc7fef7a6bb1f074
parentedd5fe68be2a2a9e23a87f65f6a89807c34b7c3f (diff)
Way too much changes - all over.
-rw-r--r--include/mcolor.h3
-rw-r--r--include/texture.h3
-rw-r--r--include/widgets.h24
-rw-r--r--lib/inputtext.cc28
-rw-r--r--lib/mcolor.cc23
-rw-r--r--lib/texture.cc60
-rw-r--r--lib/widgets.cc26
7 files changed, 123 insertions, 44 deletions
diff --git a/include/mcolor.h b/include/mcolor.h
index b383fee..9592bbe 100644
--- a/include/mcolor.h
+++ b/include/mcolor.h
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: mcolor.h,v 1.9 2004-11-27 21:48:01 pixel Exp $ */
+/* $Id: mcolor.h,v 1.10 2006-01-31 17:02:39 pixel Exp $ */
#ifndef __MCOLOR_H__
#define __MCOLOR_H__
@@ -37,6 +37,7 @@ namespace mogltk {
void Norm();
Uint32 toSDL(SDL_PixelFormat * = 0);
void fromSDL(Uint32, SDL_PixelFormat * = 0);
+ void fromHSV(double H, double S, double V); // H in degrees
static Color Min;
static Color Max;
Color c;
diff --git a/include/texture.h b/include/texture.h
index 3143b02..879adce 100644
--- a/include/texture.h
+++ b/include/texture.h
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: texture.h,v 1.9 2004-11-27 21:48:01 pixel Exp $ */
+/* $Id: texture.h,v 1.10 2006-01-31 17:02:39 pixel Exp $ */
#ifndef __TEXTURE_H__
#define __TEXTURE_H__
@@ -34,6 +34,7 @@ namespace mogltk {
texture(int, int, bool = false) throw (GeneralException);
texture(Handle *, bool = false) throw (GeneralException);
texture(int, int, int, int);
+ texture(SDL_Surface *, bool = false) throw (GeneralException);
virtual ~texture();
SDL_Surface * GetSurface();
Uint32 * GetPixels();
diff --git a/include/widgets.h b/include/widgets.h
index 66a6191..109f623 100644
--- a/include/widgets.h
+++ b/include/widgets.h
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: widgets.h,v 1.13 2005-12-02 16:21:59 pixel Exp $ */
+/* $Id: widgets.h,v 1.14 2006-01-31 17:02:39 pixel Exp $ */
#ifndef __WIDGETS_H__
#define __WIDGETS_H__
@@ -222,7 +222,7 @@ namespace mogltk {
*/
class MsgBox : public SmartBox {
public:
- MsgBox(shape *, widget * father, const String & caption, const String & text, mogltk::font * = mogltk::SystemFont);
+ MsgBox(action *, shape *, widget * father, const String & caption, const String & text, mogltk::font * = mogltk::SystemFont);
virtual ~MsgBox();
private:
mogltk::font * msgbox_font;
@@ -370,12 +370,28 @@ namespace mogltk {
InputDialog(action *, shape *, widget * father, const String & caption, const String & text, mogltk::font * = mogltk::SystemFont);
virtual ~InputDialog();
String GetText();
- void do_action();
private:
InputText * it;
- action * a;
mogltk::font * InputDialog_font;
};
+
+ /*!
+ The ActionAndDelete provides a mechanism for a widget to run an action then self-destruct.
+ Used for example by the MsgBox and InputDialog.
+ */
+ class ActionAndDelete : public mogltk::widgets::action {
+ public:
+ ActionAndDelete(mogltk::widget * _parent, mogltk::widgets::action * _a) : parent(_parent), a(_a) { }
+ virtual void do_action(mogltk::widget *) {
+ if (a)
+ a->do_action(parent);
+ delete parent;
+ delete this;
+ }
+ private:
+ mogltk::widget * parent;
+ mogltk::widgets::action * a;
+ };
};
};
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);