summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/base.cc16
-rw-r--r--lib/engine.cc7
-rw-r--r--lib/glbase.cc24
-rw-r--r--lib/glwidgets.cc51
-rw-r--r--lib/shape.cc2
-rw-r--r--lib/widgets.cc173
6 files changed, 222 insertions, 51 deletions
diff --git a/lib/base.cc b/lib/base.cc
index 49e883e..5282617 100644
--- a/lib/base.cc
+++ b/lib/base.cc
@@ -78,3 +78,19 @@ void mogltk::base::Leave2DMode() {
bool mogltk::base::is2D() {
return true;
}
+
+void mogltk::base::changeviewport(int x, int y, unsigned int w, unsigned int h) {
+ SDL_Rect r;
+
+ if ((w == 0) && (h == 0)) {
+ w = GetWidth() - x;
+ h = GetHeight() - y;
+ }
+
+ r.x = x;
+ r.y = y;
+ r.w = w;
+ r.h = h;
+
+ SDL_SetClipRect(surface, &r);
+}
diff --git a/lib/engine.cc b/lib/engine.cc
index 40426c1..6e899e2 100644
--- a/lib/engine.cc
+++ b/lib/engine.cc
@@ -14,6 +14,7 @@ int mogltk::engine::mx, mogltk::engine::my, mogltk::engine::mz = 0, mogltk::engi
int mogltk::engine::frames, mogltk::engine::locked = 0;
double mogltk::engine::curfps = -1;
Uint32 mogltk::engine::curticks;
+mogltk::widget * mogltk::engine::root = 0;
mogltk::glbase * mogltk::engine::glbase_o = 0;
mogltk::base * mogltk::engine::base_o = 0;
@@ -32,11 +33,11 @@ void mogltk::engine::keyevent::down(SDL_keysym) {
int mogltk::engine::setup() throw(GeneralException) {
if (inited) {
- printm(M_WARNING, _("mogltk::engine::setup() called twice, ignoring second call.\n"));
+ printm(M_WARNING, FUNCNAME + _(" called twice, ignoring second call.\n"));
return -1;
}
if (SDL_Init(0) < 0) {
- throw GeneralException(_("Unable to start SDL base system"));
+ throw GeneralException(FUNCNAME + _(": Unable to start SDL base system"));
}
atexit(SDL_Quit);
@@ -47,7 +48,7 @@ int mogltk::engine::setup() throw(GeneralException) {
int mogltk::engine::postsetup() throw(GeneralException) {
if (postsetuped) {
- printm(M_WARNING, _("mogltk::engine::postsetup() called twice, ignoring second call.\n"));
+ printm(M_WARNING, FUNCNAME + _(" called twice, ignoring second call.\n"));
return -1;
}
diff --git a/lib/glbase.cc b/lib/glbase.cc
index b6d41ef..ebbfe08 100644
--- a/lib/glbase.cc
+++ b/lib/glbase.cc
@@ -8,7 +8,7 @@
#include "config.h"
#endif
-mogltk::glbase::glbase(int w, int h, int flags) throw (GeneralException) : mogltk::base(w, h, flags, 0), twoD(0) {
+mogltk::glbase::glbase(int w, int h, int flags) throw (GeneralException) : mogltk::base(w, h, flags, 0), twoD(0), fovy(60.0) {
SDL_Surface * surface;
mogltk::engine::setup();
@@ -23,8 +23,7 @@ mogltk::glbase::glbase(int w, int h, int flags) throw (GeneralException) : moglt
mogltk::engine::glbase_o = this;
mogltk::engine::base_o = this;
- float ratio = surface->w;
- ratio /= surface->h;
+ ratio = (GLdouble) surface->w / surface->h;
printm(M_INFO, "Video resolution: %dx%dx%d (ratio = %3.2f)\n", surface->w, surface->h, surface->format->BitsPerPixel, ratio);
printm(M_INFO, "\n");
@@ -50,7 +49,7 @@ mogltk::glbase::glbase(int w, int h, int flags) throw (GeneralException) : moglt
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- gluPerspective(60.0, ratio, 1.0, 1024.0);
+ gluPerspective(fovy, ratio, 1.0, 1024.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -145,3 +144,20 @@ void mogltk::glbase::glVertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w) {
glVertex4d(x, y, z, w);
}
+void mogltk::glbase::changeviewport(int x, int y, unsigned int w, unsigned int h) {
+ if ((w == 0) && (h == 0)) {
+ w = GetWidth() - x;
+ h = GetHeight() - y;
+ }
+
+ ratio = (GLdouble) w / h;
+ glViewport(x, y, w, h);
+ if (!engine::base_o->is2D())
+ gluPerspective(fovy, ratio, 1.0, 1024.0);
+}
+
+void mogltk::glbase::changefovy(GLdouble nfoyv) {
+ fovy = nfoyv;
+ if (!engine::base_o->is2D())
+ gluPerspective(fovy, ratio, 1.0, 1024.0);
+}
diff --git a/lib/glwidgets.cc b/lib/glwidgets.cc
index f8e0389..511cdc4 100644
--- a/lib/glwidgets.cc
+++ b/lib/glwidgets.cc
@@ -1,43 +1,8 @@
-#include <SDL.h>
-#include <Input.h>
-#include "glfont.h"
-#include "glwidgets.h"
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "gettext.h"
-
-mogltk::widget * mogltk::widget::cur_root = 0;
-
-mogltk::widget::widget(widget * _father, int _x, int _y, int _sx, int _sy) throw (GeneralException) :
- x(_x), y(_y), sx(_sx), sy(_sy), father(_father) {
-
- if (!father)
- father = cur_root;
-
- if (father) {
- next = father->child;
- father->child = this;
- root = father->root;
- } else {
- next = 0;
- cur_root = root = this;
- }
- prev = 0;
- child = 0;
-}
-
-mogltk::widget::~widget() {
- while(child)
- delete child;
-
- if (prev)
- prev->next = next;
- else if (father)
- father->child = next;
-
- if (next)
- next->prev = prev;
-}
+#include <SDL.h>
+#include <SDL_opengl.h>
+#include "mcolor.h"
+#include "glwidgets.h"
+
+void mogltk::glRoot::draw() {
+ Shaper()->box(GetAX(), GetAY(), GetAX2(), GetAY2());
+}
diff --git a/lib/shape.cc b/lib/shape.cc
index f566f3d..60e9522 100644
--- a/lib/shape.cc
+++ b/lib/shape.cc
@@ -104,7 +104,7 @@ void mogltk::fill::insert(int x1, int y1, int x2, int y2) {
SWAP(x1, x2);
SWAP(y1, y2);
}
-
+
dx = x1 - x2;
dy = y1 - y2;
diff --git a/lib/widgets.cc b/lib/widgets.cc
new file mode 100644
index 0000000..1f540f2
--- /dev/null
+++ b/lib/widgets.cc
@@ -0,0 +1,173 @@
+#include <SDL.h>
+#include <Input.h>
+#include "font.h"
+#include "widgets.h"
+#include "engine.h"
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gettext.h"
+
+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), type(_type), name(_name), sh(_sh) {
+
+ if (!father) {
+ root = this;
+ father = this;
+ next = 0;
+ x = 0;
+ y = 0;
+ sx = engine::base_o->GetWidth();
+ sy = engine::base_o->GetHeight();
+ } else {
+ next = father->child;
+ if (next)
+ next->prev = this;
+ father->child = this;
+ root = father->root;
+ }
+ prev = 0;
+ child = 0;
+
+ computeabs();
+}
+
+mogltk::widget::~widget() {
+ while(child)
+ delete child;
+
+ if (prev)
+ prev->next = next;
+ else
+ father->child = next;
+
+ if (next)
+ next->prev = prev;
+}
+
+void mogltk::widget::computeabs() {
+ if (father != this) {
+ ax = father->ax + x;
+ ay = father->ay + y;
+ } else {
+ ax = x;
+ ay = y;
+ }
+ ax2 = ax + sx;
+ ay2 = ay + sy;
+}
+
+void mogltk::widget::move(int nx, int ny) {
+ x = nx;
+ y = ny;
+
+ computeabs();
+}
+
+void mogltk::widget::resize(int nsx, int nsy) {
+ sx = nsx;
+ sy = nsy;
+
+ ax2 = ax + sx;
+ ay2 = ay + sy;
+}
+
+int mogltk::widget::GetX() {
+ return x;
+}
+
+int mogltk::widget::GetY() {
+ return y;
+}
+
+int mogltk::widget::GetH() {
+ return sx;
+}
+
+int mogltk::widget::GetW() {
+ return sy;
+}
+
+int mogltk::widget::GetAX() {
+ return ax;
+}
+
+int mogltk::widget::GetAY() {
+ return ay;
+}
+
+int mogltk::widget::GetAX2() {
+ return ax2;
+}
+
+int mogltk::widget::GetAY2() {
+ return ay2;
+}
+
+mogltk::shape * mogltk::widget::Shaper() {
+ return sh;
+}
+
+void mogltk::widget::fulldraw() {
+ bool was2D;
+
+ if (!(was2D = mogltk::engine::glbase_o->is2D()))
+ mogltk::engine::glbase_o->Enter2DMode();
+
+ texture::Unbind();
+ mogltk::ColorP::Max = WHITE;
+ mogltk::ColorP::Min = BLACK;
+ mogltk::ColorP::Min.A = 0;
+
+ root->idraw();
+
+ if (!was2D)
+ mogltk::engine::glbase_o->Leave2DMode();
+}
+
+void mogltk::widget::idraw() {
+ int x1, y1, x2, y2;
+
+ if (next)
+ next->idraw();
+
+ x1 = MAX(GetAX(), father->GetAX());
+ y1 = MAX(GetAY(), father->GetAY());
+
+ x2 = MIN(GetAX2(), father->GetAX2());
+ y2 = MIN(GetAY2(), father->GetAY2());
+
+ engine::base_o->changeviewport(x1, y1, x2 - x1, y2 - y1);
+
+ draw();
+
+ if (child)
+ child->idraw();
+}
+
+/*
+ * Predefined widgets.
+ */
+
+/* Here is Root */
+
+mogltk::Root::Root(mogltk::shape * sh, mogltk::drawer * _dr) : widget(0, 0, 0, 0, 0, 0, "Root", sh), dr(_dr) {
+ if (engine::root)
+ delete engine::root;
+ engine::root = this;
+}
+
+void mogltk::Root::draw() {
+ if (dr)
+ dr->draw(this);
+ else
+ Shaper()->box(GetAX(), GetAY(), GetAX2(), GetAY2());
+}
+
+void mogltk::Root::setdrawer(drawer * _dr) {
+ dr = _dr;
+}