summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--include/Makefile.am3
-rw-r--r--include/base.h25
-rw-r--r--include/engine.h4
-rw-r--r--include/font.h43
-rw-r--r--include/glbase.h20
-rw-r--r--include/glcolor.h10
-rw-r--r--include/glfont.h35
-rw-r--r--include/glshape.h60
-rw-r--r--include/mcolor.h18
-rw-r--r--include/shape.h65
-rw-r--r--include/texture.h39
-rw-r--r--lib/Makefile.am3
-rw-r--r--lib/base.cc77
-rw-r--r--lib/engine.cc10
-rw-r--r--lib/font.cc318
-rw-r--r--lib/glbase.cc37
-rw-r--r--lib/glcolor.cc8
-rw-r--r--lib/glfont.cc281
-rw-r--r--lib/glshape.cc187
-rw-r--r--lib/mcolor.cc10
-rw-r--r--lib/shape.cc287
22 files changed, 961 insertions, 581 deletions
diff --git a/Makefile.am b/Makefile.am
index e4353cb..e34e9ff 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
-SUBDIRS = intl m4 po include lib src
+SUBDIRS = lib intl m4 po include src
ACLOCAL_AMFLAGS = -I m4
diff --git a/include/Makefile.am b/include/Makefile.am
index 283156d..948adba 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,4 +1,5 @@
pkginclude_HEADERS = \
-engine.h glbase.h glcolor.h glfont.h gltexture.h glshape.h glwidgets.h sprite.h
+engine.h glbase.h glcolor.h glfont.h gltexture.h glshape.h glwidgets.h sprite.h \
+base.h font.h shape.h mcolor.h
noinst_HEADERS = gettext.h
diff --git a/include/base.h b/include/base.h
new file mode 100644
index 0000000..65326bc
--- /dev/null
+++ b/include/base.h
@@ -0,0 +1,25 @@
+#ifndef __BASE_H__
+#define __BASE_H__
+
+#include <SDL.h>
+#include <SDL_opengl.h>
+#include <Exceptions.h>
+
+namespace mogltk {
+ class base : public Base {
+ public:
+ base(int w = 640, int h = 480, int flags = 0) throw(GeneralException);
+ virtual ~base();
+ int GetWidth(void);
+ int GetHeight(void);
+ virtual void Flip(void);
+ protected:
+ base(int, int, int, int);
+ void setsurface(SDL_Surface *) throw (GeneralException);
+ private:
+ int width, height;
+ SDL_Surface * surface;
+ };
+};
+
+#endif
diff --git a/include/engine.h b/include/engine.h
index 56c9279..a72e7b1 100644
--- a/include/engine.h
+++ b/include/engine.h
@@ -4,6 +4,8 @@
#include <SDL.h>
#include <Handle.h>
#include <Exceptions.h>
+#include "base.h"
+#include "glbase.h"
namespace mogltk {
class engine : public Base {
@@ -24,6 +26,8 @@ namespace mogltk {
static double FPS();
static void lockmouse();
static void unlockmouse();
+ static glbase * glbase_o;
+ static base * base_o;
private:
static bool inited;
static bool postsetuped;
diff --git a/include/font.h b/include/font.h
new file mode 100644
index 0000000..a6f4a16
--- /dev/null
+++ b/include/font.h
@@ -0,0 +1,43 @@
+#ifndef __FONT_H__
+#define __FONT_H__
+
+#include <SDL.h>
+#include <stdarg.h>
+#include <BString.h>
+#include <Handle.h>
+#include <gltexture.h>
+#include <glcolor.h>
+
+namespace mogltk {
+ class font : public Base {
+ public:
+ font(Handle *);
+ virtual ~font();
+ virtual void drawentry(Uint16, int, int, ColorP = WHITE);
+ void putcursor(int, int);
+ void putentry(Uint16, ColorP = WHITE);
+ void putchar(char, ColorP = WHITE);
+ void newline(void);
+ int printf(const ugly_string &, ...);
+ int printf(const char *, ...);
+ int printf(const ugly_string &, va_list);
+ void setcolor(ColorP);
+ void setshadow(int);
+ void setwspace(int);
+ int getchar(char) const;
+ int singletextsize(const String &) const;
+
+ protected:
+ Uint8 * sizes;
+ Uint16 nbentries, nbcT, nbT;
+ Uint8 flags, maxX, maxY, nbcU, nbcV, base, inter;
+ texture ** fonttex;
+ Uint16 * corresp;
+ int cx, cy, ox;
+ ColorP textcolor;
+ int shadow, wspace;
+ };
+ extern font * SystemFont;
+};
+
+#endif
diff --git a/include/glbase.h b/include/glbase.h
index b83f044..90732ef 100644
--- a/include/glbase.h
+++ b/include/glbase.h
@@ -4,25 +4,23 @@
#include <SDL.h>
#include <SDL_opengl.h>
#include <Exceptions.h>
+#include "base.h"
namespace mogltk {
- class glbase : public Base {
+ class glbase : public base {
public:
- static int setup(int w = 640, int h = 480, int flags = 0) throw(GeneralException);
- static int GetWidth(void);
- static int GetHeight(void);
- static int GetInited(void);
- static void Enter2DMode(void);
- static void Leave2DMode(void);
- static void Flip(void);
- static bool is2D(void);
+ glbase(int w = 640, int h = 480, int flags = 0) throw(GeneralException);
+ virtual ~glbase();
+ void Enter2DMode(void);
+ void Leave2DMode(void);
+ virtual void Flip(void);
+ bool is2D(void);
static void glVertex(GLshort, GLshort, GLshort = 0, GLshort = 1);
static void glVertex(GLint, GLint, GLint = 0, GLint = 1);
static void glVertex(GLfloat, GLfloat, GLfloat = 0.0, GLfloat = 1.0);
static void glVertex(GLdouble, GLdouble, GLdouble = 0.0, GLdouble = 1.0);
private:
- static int width, height, inited, twoD;
- static SDL_Surface * surface;
+ int twoD;
};
};
diff --git a/include/glcolor.h b/include/glcolor.h
index 28ce1f7..f62334b 100644
--- a/include/glcolor.h
+++ b/include/glcolor.h
@@ -3,16 +3,14 @@
#include <Exceptions.h>
#include <Color.h>
+#include "mcolor.h"
namespace mogltk {
- class ColorP : public Base {
+ class glColorP : public ColorP {
public:
- ColorP(const Color &);
- ColorP(Uint8, Uint8, Uint8, Uint8);
+ glColorP(const Color &);
+ glColorP(Uint8, Uint8, Uint8, Uint8);
void Bind();
- static Color Min;
- static Color Max;
- Color c;
};
};
diff --git a/include/glfont.h b/include/glfont.h
index 87efd12..b8663d7 100644
--- a/include/glfont.h
+++ b/include/glfont.h
@@ -2,43 +2,18 @@
#define __GLFONT_H__
#include <SDL.h>
-#include <stdarg.h>
-#include <BString.h>
-#include <Handle.h>
-#include <gltexture.h>
-#include <glcolor.h>
+#include "font.h"
namespace mogltk {
- class font : public Base {
+ class glfont : public font {
public:
- font(Handle *);
- virtual ~font();
- void drawentry(Uint16, int, int, ColorP = WHITE);
- void putcursor(int, int);
- void putentry(Uint16, ColorP = WHITE);
- void putchar(char, ColorP = WHITE);
- void newline(void);
- int printf(const ugly_string &, ...);
- int printf(const char *, ...);
- int printf(const ugly_string &, va_list);
- void setcolor(ColorP);
- void setshadow(int);
- void setwspace(int);
- int getchar(char) const;
- int singletextsize(const String &) const;
+ glfont(Handle *);
+ virtual ~glfont();
+ void drawentry(Uint16, int, int, glColorP = WHITE);
private:
- Uint8 * sizes;
- Uint16 nbentries, nbcT, nbT;
- Uint8 flags, maxX, maxY, nbcU, nbcV, base, inter;
- texture ** fonttex;
- Uint16 * corresp;
void Bind(int);
- int cx, cy, ox;
- ColorP textcolor;
- int shadow, wspace;
};
- extern font * SystemFont;
};
#endif
diff --git a/include/glshape.h b/include/glshape.h
index b65c21e..81439ad 100644
--- a/include/glshape.h
+++ b/include/glshape.h
@@ -5,60 +5,20 @@
#include <BString.h>
#include <glcolor.h>
#include <gltexture.h>
+#include <shape.h>
namespace mogltk {
- typedef enum {
- LEFT,
- CENTER,
- RIGHT
- } align_t;
- class shape : public Base {
+ class glshape : public shape {
public:
- static void pixel(int x, int y, ColorP = WHITE);
- static void box(int x1, int y1, int x2, int y2, ColorP = WHITE);
- static void box3d(int x1, int y1, int x2, int y2, ColorP = DOS_WHITE, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, int = 2, bool = false);
- static void box(int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP);
- static void obox(int x1, int y1, int x2, int y2, ColorP = WHITE);
- static void obox3d(int x1, int y1, int x2, int y2, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, bool = false);
- static void obox(int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP);
- static void tbox(texture *, int x1, int y1, int x2, int y2, int tx = 0, int ty = 0, double = 1.0, ColorP = WHITE);
- static void tbox(texture *, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP = WHITE);
- static void tbox(texture *, int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP, int tx = 0, int ty = 0, double = 1.0);
- static void tbox(texture *, int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP, int tx1, int ty1, int tx2, int ty2);
- static void hline(int x1, int x2, int y, ColorP = WHITE);
- static void hline3d(int x1, int x2, int y, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, bool = false);
- static void hline(int x1, int x2, int y, ColorP, ColorP);
- static void vline(int x, int y1, int y2, ColorP = WHITE);
- static void vline3d(int x, int y1, int y2, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, bool = false);
- static void vline(int x, int y1, int y2, ColorP, ColorP);
- static void window(int x1, int y1, int x2, int y2,
- const String & title = "",
- ColorP titlecolor = DOS_HIGH_WHITE,
- ColorP titlebackcolor = DOS_MAGENTA,
- ColorP front = DOS_WHITE,
- ColorP shade1 = DOS_HIGH_WHITE,
- ColorP shade2 = DOS_GRAY);
- static void text(int x, int y, const String &,
- ColorP textcolor = DOS_HIGH_WHITE,
- align_t align = LEFT);
- static void text3d(int x, int y, const String &,
- ColorP textcolor = DOS_BLACK,
- ColorP shade1 = DOS_HIGH_WHITE,
- ColorP shade2 = DOS_GRAY,
- align_t align = LEFT,
- bool bevel = false);
- static void button(int x1, int y1, int x2, int y2, const String &,
- bool bevel = false,
- ColorP front = DOS_WHITE,
- ColorP shade1 = DOS_HIGH_WHITE,
- ColorP shade2 = DOS_GRAY,
- ColorP round = DOS_BLACK,
- ColorP textcolor = DOS_BLACK,
- ColorP tshade1 = DOS_HIGH_WHITE,
- ColorP tshade2 = DOS_GRAY);
+ virtual void box(int x1, int y1, int x2, int y2, glColorP = WHITE);
+ virtual void box3d(int x1, int y1, int x2, int y2, glColorP = DOS_WHITE, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, int = 2, bool = false);
+ virtual void box(int x1, int y1, int x2, int y2, glColorP, glColorP, glColorP, glColorP);
+ virtual void tbox(texture *, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP = WHITE);
+ virtual void tbox(texture *, int x1, int y1, int x2, int y2, glColorP, glColorP, glColorP, glColorP, int tx1, int ty1, int tx2, int ty2);
private:
- static bool in2D(bool);
- static void out2D(bool);
+ bool Enter(bool);
+ virtual bool Enter();
+ virtual void Leave(bool);
};
};
diff --git a/include/mcolor.h b/include/mcolor.h
new file mode 100644
index 0000000..cd91923
--- /dev/null
+++ b/include/mcolor.h
@@ -0,0 +1,18 @@
+#ifndef __MCOLOR_H__
+#define __MCOLOR_H__
+
+#include <Exceptions.h>
+#include <Color.h>
+
+namespace mogltk {
+ class ColorP : public Base {
+ public:
+ ColorP(const Color &);
+ ColorP(Uint8, Uint8, Uint8, Uint8);
+ static Color Min;
+ static Color Max;
+ Color c;
+ };
+};
+
+#endif
diff --git a/include/shape.h b/include/shape.h
new file mode 100644
index 0000000..1aa8168
--- /dev/null
+++ b/include/shape.h
@@ -0,0 +1,65 @@
+#ifndef __SHAPE_H__
+#define __SHAPE_H__
+
+#include <Exceptions.h>
+#include <BString.h>
+#include <mcolor.h>
+#include <texture.h>
+
+namespace mogltk {
+ typedef enum {
+ LEFT,
+ CENTER,
+ RIGHT
+ } align_t;
+ class shape : public Base {
+ public:
+ virtual void pixel(int x, int y, ColorP = WHITE);
+ virtual void box(int x1, int y1, int x2, int y2, ColorP = WHITE);
+ virtual void box3d(int x1, int y1, int x2, int y2, ColorP = DOS_WHITE, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, int = 2, bool = false);
+ virtual void box(int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP);
+ virtual void obox(int x1, int y1, int x2, int y2, ColorP = WHITE);
+ virtual void obox3d(int x1, int y1, int x2, int y2, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, bool = false);
+ virtual void obox(int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP);
+ virtual void tbox(texture *, int x1, int y1, int x2, int y2, int tx = 0, int ty = 0, double = 1.0, ColorP = WHITE);
+ virtual void tbox(texture *, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP = WHITE);
+ virtual void tbox(texture *, int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP, int tx = 0, int ty = 0, double = 1.0);
+ virtual void tbox(texture *, int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP, int tx1, int ty1, int tx2, int ty2);
+ virtual void hline(int x1, int x2, int y, ColorP = WHITE);
+ virtual void hline3d(int x1, int x2, int y, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, bool = false);
+ virtual void hline(int x1, int x2, int y, ColorP, ColorP);
+ virtual void vline(int x, int y1, int y2, ColorP = WHITE);
+ virtual void vline3d(int x, int y1, int y2, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, bool = false);
+ virtual void vline(int x, int y1, int y2, ColorP, ColorP);
+ virtual void window(int x1, int y1, int x2, int y2,
+ const String & title = "",
+ ColorP titlecolor = DOS_HIGH_WHITE,
+ ColorP titlebackcolor = DOS_MAGENTA,
+ ColorP front = DOS_WHITE,
+ ColorP shade1 = DOS_HIGH_WHITE,
+ ColorP shade2 = DOS_GRAY);
+ virtual void text(int x, int y, const String &,
+ ColorP textcolor = DOS_HIGH_WHITE,
+ align_t align = LEFT);
+ virtual void text3d(int x, int y, const String &,
+ ColorP textcolor = DOS_BLACK,
+ ColorP shade1 = DOS_HIGH_WHITE,
+ ColorP shade2 = DOS_GRAY,
+ align_t align = LEFT,
+ bool bevel = false);
+ virtual void button(int x1, int y1, int x2, int y2, const String &,
+ bool bevel = false,
+ ColorP front = DOS_WHITE,
+ ColorP shade1 = DOS_HIGH_WHITE,
+ ColorP shade2 = DOS_GRAY,
+ ColorP round = DOS_BLACK,
+ ColorP textcolor = DOS_BLACK,
+ ColorP tshade1 = DOS_HIGH_WHITE,
+ ColorP tshade2 = DOS_GRAY);
+ private:
+ virtual bool Enter();
+ virtual void Leave(bool);
+ };
+};
+
+#endif
diff --git a/include/texture.h b/include/texture.h
new file mode 100644
index 0000000..4f5e162
--- /dev/null
+++ b/include/texture.h
@@ -0,0 +1,39 @@
+#ifndef __GLTEXTURE_H__
+#define __GLTEXTURE_H__
+
+#include <SDL.h>
+#include <SDL_opengl.h>
+#include <Handle.h>
+#include <Exceptions.h>
+#include <generic.h>
+
+namespace mogltk {
+ class texture : public Base {
+ public:
+ texture(int = 256, int = 256, bool = false) throw (GeneralException);
+ texture(Handle *, bool = false) throw (GeneralException);
+ virtual ~texture();
+ SDL_Surface * GetSurface();
+ Uint32 * GetPixels();
+ static SDL_Surface * LoadNTEX(Handle * h) throw (GeneralException) ;
+ void Generate();
+ void Bind(bool = true);
+ GLuint GetWidth();
+ GLuint GetHeight();
+ static void Unbind(void);
+ void Taint(void);
+ private:
+ GLuint width, height, tex;
+ bool texture_allocated;
+ SDL_Surface * surface;
+ bool planar, tainted;
+#ifdef TRACE_TEXTURES
+ static texture * header;
+ static texture * footer;
+ texture * next, * prev;
+#endif
+ static texture * active;
+ };
+};
+
+#endif
diff --git a/lib/Makefile.am b/lib/Makefile.am
index a13b4c3..bbb603c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -6,5 +6,4 @@ INCLUDES = -I.. -I../include -I$(includedir)
lib_LTLIBRARIES = libmogltk.la
libmogltk_la_SOURCES = engine.cc glbase.cc glcolor.cc glfont.cc gltexture.cc \
-glshape.cc glwidgets.cc sprite.cc
-
+glshape.cc glwidgets.cc sprite.cc base.cc font.cc shape.cc mcolor.cc
diff --git a/lib/base.cc b/lib/base.cc
new file mode 100644
index 0000000..049f53c
--- /dev/null
+++ b/lib/base.cc
@@ -0,0 +1,77 @@
+#include <stdio.h>
+#include <SDL.h>
+#include "base.h"
+#include "engine.h"
+#include "generic.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "gettext.h"
+
+int mogltk::base::setup(int w, int h, int flags) : surface(0) throw(GeneralException) {
+ if (inited) {
+ printm(M_WARNING, "mogltk::base::setup called twice, ignoring second call...\n");
+ return -1;
+ }
+
+ width = w;
+ height = h;
+
+ mogltk::engine::setup();
+ if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
+ throw GeneralException(String("Couldn't initialise Video SubSystem: ") + SDL_GetError());
+ }
+
+ if (!(surface = SDL_SetVideoMode(width, height, 0, flags))) {
+ throw GeneralException(String("Couldn't set GL mode: ") + SDL_GetError());
+ }
+
+ mogltk::engine::base_o = this;
+
+ float ratio = surface->w;
+ ratio /= surface->h;
+
+ printm(M_INFO, "Video resolution: %dx%dx%d (ratio = %3.2f)\n", surface->w, surface->h, surface->format->BitsPerPixel, ratio);
+
+ inited = 1;
+
+ SDL_ShowCursor(0);
+ SDL_FillRect(surface, NULL, 0);
+ SDL_SwapBuffers();
+ SDL_FillRect(surface, NULL, 0);
+ mogltk::engine::postsetup();
+}
+
+int mogltk::base::GetWidth(void) {
+ return width;
+}
+
+int mogltk::base::GetHeight(void) {
+ return height;
+}
+
+int mogltk::base::GetInited(void) {
+ return inited;
+}
+
+void mogltk::base::Flip() {
+ printm(M_INFO, "Flipping\n");
+ mogltk::engine::pollevents();
+ SDL_SwapBuffers();
+ SDL_FillRect(surface, NULL, 0);
+}
+
+int mogltk::base::setup(int w, int h, int flags) : surface(0) {
+ width = w;
+ height = h;
+
+ inited = 1;
+
+ SDL_ShowCursor(0);
+}
+
+void mogltk::base::setsurface(SDL_Surface * _surface) throw (GeneralException) {
+ if (surface)
+ throw GeneralException("Can't set video surface twice");
+ surface = _surface;
+}
diff --git a/lib/engine.cc b/lib/engine.cc
index 7ccc995..99843c0 100644
--- a/lib/engine.cc
+++ b/lib/engine.cc
@@ -18,6 +18,9 @@ int mogltk::engine::frames, mogltk::engine::locked = 0;
double mogltk::engine::curfps = -1;
Uint32 mogltk::engine::curticks;
+mogltk::glbase * mogltk::engine::glbase_o = 0;
+mogltk::base * mogltk::engine::base_o = 0;
+
#define UPDATERATE 1000
int mogltk::engine::setup() throw(GeneralException) {
@@ -32,8 +35,6 @@ int mogltk::engine::setup() throw(GeneralException) {
inited = true;
- mogltk::SystemFont = new mogltk::font(&Input("font.bin"));
-
return 0;
}
@@ -48,6 +49,11 @@ int mogltk::engine::postsetup() throw(GeneralException) {
postsetuped = true;
+ if (glbase_o)
+ mogltk::SystemFont = new mogltk::glfont(&Input("font.bin"));
+ else
+ mogltk::SystemFont = new mogltk::font(&Input("font.bin"));
+
return 0;
}
diff --git a/lib/font.cc b/lib/font.cc
new file mode 100644
index 0000000..7cc57f6
--- /dev/null
+++ b/lib/font.cc
@@ -0,0 +1,318 @@
+#include <stdarg.h>
+#include "base.h"
+#include "font.h"
+#include "Input.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+Uint8 prescale2[4] = { 0, 85, 170, 255 }, prescale3[8] = { 0, 36, 72, 109, 145, 182, 218, 255 };
+
+#define STRBUFSIZ 512
+
+/*
+
+font file format
+================
+
+off|siz|description
+---+---+-------------------------------
+ 0 | 2 | Number of entries = nbentries
+ 2 | 1 | Flags
+ 3 | 1 | maxX (maximum width)
+ 4 | 1 | maxY (maximum height)
+ 5 | 1 | base (bottom line from top)
+ 6 | 1 | inter (size of the interline)
+ 7 | X | char entries
+7+X| Y | char map
+
+X = (maxX * maxY + 1) * nbentries
+Y = nbentries * 4
+
+
+Flags:
+=====
+
+0000000R
+
+R = RGBA (=1) or Alpha (=0)
+
+RGBA in 1232 format:
+ABBGGGRR
+
+
+Each entries:
+============
+
+off|siz|description
+---+---+-------------------------------
+ 0 | 1 | True size of the entry
+ 1 | Z | Datas
+
+Z = maxX * maxY
+Datas are stored in order X first, then Y.
+
+Char map:
+========
+
+nbentries entries, each entry = 4 bytes = 2 uint16
+
+off|siz|description
+---+---+-------------------------------
+ 0 | 2 | Unicode (?)
+ 2 | 2 | Corresponding char entry
+
+I'm not sure about my word 'Unicode'. I write this only to say it's an attempt
+to make the fonts "internationals". If the "unicode" is < 255, then it should
+match only one byte in the string. Otherwise, it should match two bytes.
+
+
+Variables comments
+==================
+
+nbcU = number of chars on X by texture
+nbcV = number of chars on Y by texture
+nbcT = number of char by texture
+nbT = number of textures
+
+*/
+
+mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255), shadow(0), wspace(0) {
+ int i;
+
+ nbentries = ffont->readU16();
+ flags = ffont->readU8();
+ maxX = ffont->readU8();
+ maxY = ffont->readU8();
+ base = ffont->readU8();
+ inter = ffont->readU8();
+
+ nbcU = 256 / maxX;
+ nbcV = 256 / maxY;
+
+ nbcT = nbcU * nbcV;
+
+ nbT = nbentries / nbcT;
+
+ if (nbentries % nbcT) {
+ nbT++;
+ }
+
+ printm(M_INFO, "Creating font texture: %i entries, flags = 0x%02x, maxX = %i, maxY = %i\n", nbentries, flags, maxX, maxY);
+ printm(M_INFO, "Which makes %i texture(s), with %i char by texture, %i on X, and %i on Y\n", nbT, nbcT, nbcU, nbcV);
+
+ fonttex = (texture **) malloc(nbT * sizeof(texture *));
+
+ for (i = 0; i < nbT; i++) {
+ fonttex[i] = new texture(256, 256, true);
+ }
+
+ sizes = (Uint8 *) malloc(nbentries * sizeof(Uint8));
+
+ Uint8 * curtex = (Uint8 *) fonttex[0]->GetSurface()->pixels;
+ Uint32 curU = 0, curV = 0, curT = 0;
+ for (i = 0; i < nbentries; i++) {
+ sizes[i] = ffont->readU8();
+ for (int v = 0; v < maxY; v++) {
+ for (int u = 0; u < maxX; u++) {
+ Uint8 f;
+ f = ffont->readU8();
+ if (flags & 1) {
+ Uint8 r, g, b, a;
+ r = f & 3;
+ g = (f >> 2) & 7;
+ b = (f >> 5) & 3;
+ a = (f >> 7) & 1;
+ curtex[(curU + u + (curV + v) * 256) * 4 + 0] = prescale2[r];
+ curtex[(curU + u + (curV + v) * 256) * 4 + 1] = prescale3[g];
+ curtex[(curU + u + (curV + v) * 256) * 4 + 2] = prescale2[b];
+ curtex[(curU + u + (curV + v) * 256) * 4 + 3] = a ? 255 : 0;
+ } else {
+ curtex[(curU + u + (curV + v) * 256) * 4 + 0] = 255;
+ curtex[(curU + u + (curV + v) * 256) * 4 + 1] = 255;
+ curtex[(curU + u + (curV + v) * 256) * 4 + 2] = 255;
+ curtex[(curU + u + (curV + v) * 256) * 4 + 3] = f;
+ }
+ }
+ }
+ if (((curU += maxX) + maxX) > 256) {
+ curU = 0;
+ if (((curV += maxY) + maxY) > 256) {
+ curV = 0;
+ if ((curT + 1) != nbT)
+ curtex = (Uint8 *) fonttex[++curT]->GetSurface()->pixels;
+ }
+ }
+ }
+
+ corresp = (Uint16 *) malloc(nbentries * 2 * sizeof(Uint16));
+
+ for (i = 0; i < 2 * nbentries; i++) {
+ corresp[i] = ffont->readU16();
+ }
+}
+
+mogltk::font::~font() {
+ int i;
+ for (i = 0; i < nbT; i++) {
+ delete fonttex[i];
+ }
+
+ free((void *&) fonttex);
+ free(sizes);
+}
+
+void mogltk::font::drawentry(Uint16 entry, int x, int y, ColorP c) {
+ bool was2D;
+ int trueentry, cx, cy, px, py;
+
+ return;
+
+ was2D = mogltk::glbase::is2D();
+
+ if (!was2D)
+ mogltk::glbase::Enter2DMode();
+
+ if (shadow) {
+ int os = shadow;
+ shadow = 0;
+
+ drawentry(entry, x + os, y + os, BLACK);
+
+ shadow = os;
+ }
+
+ y -= base;
+
+ Bind(entry / nbcT);
+ c.Bind();
+ trueentry = entry % nbcT;
+ cx = trueentry % nbcU;
+ cy = trueentry / nbcU;
+ px = cx * maxX;
+ py = cy * maxY;
+
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2i(px , py ); glVertex2i(x , y );
+ glTexCoord2i(px + maxX - 1, py ); glVertex2i(x + maxX - 1, y );
+ glTexCoord2i(px , py + maxY - 1); glVertex2i(x , y + maxY - 1);
+ glTexCoord2i(px + maxX - 1, py + maxY - 1); glVertex2i(x + maxX - 1, y + maxY - 1);
+ glEnd();
+
+ if (!was2D)
+ mogltk::glbase::Leave2DMode();
+}
+
+void mogltk::font::putcursor(int x, int y) {
+ cx = ox = x;
+ cy = y;
+}
+
+void mogltk::font::putentry(Uint16 entry, ColorP c) {
+ drawentry(entry, cx, cy, c);
+ cx += sizes[entry] + wspace;
+}
+
+void mogltk::font::putchar(char ch, ColorP c) {
+ Uint16 * p;
+ int i;
+
+ for (i = 0, p = corresp; i < nbentries; i++, p++) {
+ if (*(p++) == ch) {
+ putentry(*p, c);
+ return;
+ }
+ }
+}
+
+int mogltk::font::getchar(char ch) const {
+ Uint16 * p;
+ int i;
+
+ for (i = 0, p = corresp; i < nbentries; i++, p++) {
+ if (*(p++) == ch) {
+ return *p;
+ }
+ }
+
+ return -1;
+}
+
+void mogltk::font::newline(void) {
+ cx = ox;
+ cy += inter;
+}
+
+int mogltk::font::printf(const ugly_string & m, va_list ap) {
+ char * p;
+ static char buffer[STRBUFSIZ + 1];
+ int r;
+
+#ifdef HAVE_VSNPRINTF
+ r = vsnprintf(buffer, STRBUFSIZ, m.p, ap);
+#else
+ r = vsprintf(buffer, m.p, ap);
+#endif
+
+ for (p = buffer; *p; p++) {
+ if (*p == '\n') {
+ newline();
+ } else {
+ putchar(*p, textcolor);
+ }
+ }
+
+ return r;
+}
+
+int mogltk::font::printf(const ugly_string & m, ...) {
+ va_list ap;
+ int r;
+
+ va_start(ap, m);
+ r = printf(m, ap);
+ va_end(ap);
+
+ return r;
+}
+
+int mogltk::font::printf(const char * p, ...) {
+ ugly_string m;
+ va_list ap;
+ int r;
+
+ m.p = p;
+
+ va_start(ap, p);
+ r = printf(m, ap);
+ va_end(ap);
+
+ return r;
+}
+
+void mogltk::font::setcolor(ColorP c) {
+ textcolor = c;
+}
+
+void mogltk::font::setshadow(int s) {
+ shadow = s;
+}
+
+void mogltk::font::setwspace(int w) {
+ wspace = w;
+}
+
+int mogltk::font::singletextsize(const String & s) const {
+ unsigned int i;
+ int r = 0;
+
+ for (i = 0; i < s.strlen(); i++) {
+ r += sizes[getchar(s[i])];
+ }
+
+ return r;
+}
+
+mogltk::font * mogltk::SystemFont;
+
+
diff --git a/lib/glbase.cc b/lib/glbase.cc
index 86d0774..df093dd 100644
--- a/lib/glbase.cc
+++ b/lib/glbase.cc
@@ -8,26 +8,20 @@
#include "config.h"
#endif
-int mogltk::glbase::width, mogltk::glbase::height, mogltk::glbase::inited = 0, mogltk::glbase::twoD = 0;
-SDL_Surface * mogltk::glbase::surface = 0;
+mogltk::glbase::glbase(int w, int h, int flags) throw (GeneralException) : mogltk::base(w, h, flags, 0), twoD(0) {
+ SDL_Surface * surface;
-int mogltk::glbase::setup(int w, int h, int flags) throw(GeneralException) {
- if (inited) {
- printm(M_WARNING, "mogltk::glbase::setup called twice, ignoring second call...\n");
- return -1;
- }
-
- width = w;
- height = h;
-
mogltk::engine::setup();
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
throw GeneralException(String("Couldn't initialise Video SubSystem: ") + SDL_GetError());
}
- if (!(surface = SDL_SetVideoMode(width, height, 0, flags | SDL_OPENGL))) {
+ if (!(surface = SDL_SetVideoMode(w, h, 0, flags | SDL_OPENGL))) {
throw GeneralException(String("Couldn't set GL mode: ") + SDL_GetError());
}
+
+ mogltk::engine::glbase_o = this;
+ mogltk::engine::base_o = this;
float ratio = surface->w;
ratio /= surface->h;
@@ -41,8 +35,6 @@ int mogltk::glbase::setup(int w, int h, int flags) throw(GeneralException) {
printm(M_INFO, String("Version : ") + (char *) glGetString(GL_VERSION) + "\n");
printm(M_INFO, String("Extensions: ") + (char *) glGetString(GL_EXTENSIONS) + "\n");
- inited = 1;
-
glViewport(0, 0, surface->w, surface->h);
glCullFace(GL_BACK);
@@ -67,23 +59,14 @@ int mogltk::glbase::setup(int w, int h, int flags) throw(GeneralException) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- SDL_ShowCursor(0);
SDL_GL_SwapBuffers();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- return 0;
-}
-
-int mogltk::glbase::GetWidth(void) {
- return width;
-}
-
-int mogltk::glbase::GetHeight(void) {
- return height;
+ setsurface(surface);
+ mogltk::engine::postsetup();
}
-int mogltk::glbase::GetInited(void) {
- return inited;
+mogltk::glbase::~glbase() {
}
void mogltk::glbase::Enter2DMode(void) {
@@ -99,7 +82,7 @@ void mogltk::glbase::Enter2DMode(void) {
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
- glOrtho(0.0, width, height, 0.0, 0.0, 1.0);
+ glOrtho(0.0, GetWidth(), GetHeight(), 0.0, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
diff --git a/lib/glcolor.cc b/lib/glcolor.cc
index c274620..c38b4e5 100644
--- a/lib/glcolor.cc
+++ b/lib/glcolor.cc
@@ -1,15 +1,13 @@
#include <SDL_opengl.h>
#include "glcolor.h"
-Color mogltk::ColorP::Min(0, 0, 0, 0), mogltk::ColorP::Max = WHITE;
-
-mogltk::ColorP::ColorP(const Color & ac) : c(ac) {
+mogltk::glColorP::glColorP(const Color & ac) : ColorP(ac) {
}
-mogltk::ColorP::ColorP(Uint8 ar, Uint8 ag, Uint8 ab, Uint8 aa) : c(ar, ag, ab, aa) {
+mogltk::glColorP::glColorP(Uint8 ar, Uint8 ag, Uint8 ab, Uint8 aa) : ColorP(ar, ag, ab, aa) {
}
-void mogltk::ColorP::Bind() {
+void mogltk::glColorP::Bind() {
glColor4d((double) MIN(MAX(c.R, Min.R), Max.R) / 255, (double) MIN(MAX(c.G, Min.G), Max.G) / 255, (double) MIN(MAX(c.B, Min.B), Max.B) / 255, (double) MIN(MAX(c.A, Min.A), Max.A) / 255);
}
diff --git a/lib/glfont.cc b/lib/glfont.cc
index 80a8b1d..66e36c4 100644
--- a/lib/glfont.cc
+++ b/lib/glfont.cc
@@ -1,175 +1,24 @@
-#include <stdarg.h>
+#include "engine.h"
#include "glbase.h"
#include "glfont.h"
-#include "Input.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-Uint8 prescale2[4] = { 0, 85, 170, 255 }, prescale3[8] = { 0, 36, 72, 109, 145, 182, 218, 255 };
-
-#define STRBUFSIZ 512
-
-/*
-
-font file format
-================
-
-off|siz|description
----+---+-------------------------------
- 0 | 2 | Number of entries = nbentries
- 2 | 1 | Flags
- 3 | 1 | maxX (maximum width)
- 4 | 1 | maxY (maximum height)
- 5 | 1 | base (bottom line from top)
- 6 | 1 | inter (size of the interline)
- 7 | X | char entries
-7+X| Y | char map
-
-X = (maxX * maxY + 1) * nbentries
-Y = nbentries * 4
-
-
-Flags:
-=====
-
-0000000R
-
-R = RGBA (=1) or Alpha (=0)
-
-RGBA in 1232 format:
-ABBGGGRR
-
-
-Each entries:
-============
-
-off|siz|description
----+---+-------------------------------
- 0 | 1 | True size of the entry
- 1 | Z | Datas
-
-Z = maxX * maxY
-Datas are stored in order X first, then Y.
-
-Char map:
-========
-
-nbentries entries, each entry = 4 bytes = 2 uint16
-
-off|siz|description
----+---+-------------------------------
- 0 | 2 | Unicode (?)
- 2 | 2 | Corresponding char entry
-
-I'm not sure about my word 'Unicode'. I write this only to say it's an attempt
-to make the fonts "internationals". If the "unicode" is < 255, then it should
-match only one byte in the string. Otherwise, it should match two bytes.
-
-
-Variables comments
-==================
-
-nbcU = number of chars on X by texture
-nbcV = number of chars on Y by texture
-nbcT = number of char by texture
-nbT = number of textures
-
-*/
-
-mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255), shadow(0), wspace(0) {
- int i;
-
- nbentries = ffont->readU16();
- flags = ffont->readU8();
- maxX = ffont->readU8();
- maxY = ffont->readU8();
- base = ffont->readU8();
- inter = ffont->readU8();
-
- nbcU = 256 / maxX;
- nbcV = 256 / maxY;
-
- nbcT = nbcU * nbcV;
-
- nbT = nbentries / nbcT;
-
- if (nbentries % nbcT) {
- nbT++;
- }
-
- printm(M_INFO, "Creating font texture: %i entries, flags = 0x%02x, maxX = %i, maxY = %i\n", nbentries, flags, maxX, maxY);
- printm(M_INFO, "Which makes %i texture(s), with %i char by texture, %i on X, and %i on Y\n", nbT, nbcT, nbcU, nbcV);
-
- fonttex = (texture **) malloc(nbT * sizeof(texture *));
-
- for (i = 0; i < nbT; i++) {
- fonttex[i] = new texture(256, 256, true);
- }
-
- sizes = (Uint8 *) malloc(nbentries * sizeof(Uint8));
-
- Uint8 * curtex = (Uint8 *) fonttex[0]->GetSurface()->pixels;
- Uint32 curU = 0, curV = 0, curT = 0;
- for (i = 0; i < nbentries; i++) {
- sizes[i] = ffont->readU8();
- for (int v = 0; v < maxY; v++) {
- for (int u = 0; u < maxX; u++) {
- Uint8 f;
- f = ffont->readU8();
- if (flags & 1) {
- Uint8 r, g, b, a;
- r = f & 3;
- g = (f >> 2) & 7;
- b = (f >> 5) & 3;
- a = (f >> 7) & 1;
- curtex[(curU + u + (curV + v) * 256) * 4 + 0] = prescale2[r];
- curtex[(curU + u + (curV + v) * 256) * 4 + 1] = prescale3[g];
- curtex[(curU + u + (curV + v) * 256) * 4 + 2] = prescale2[b];
- curtex[(curU + u + (curV + v) * 256) * 4 + 3] = a ? 255 : 0;
- } else {
- curtex[(curU + u + (curV + v) * 256) * 4 + 0] = 255;
- curtex[(curU + u + (curV + v) * 256) * 4 + 1] = 255;
- curtex[(curU + u + (curV + v) * 256) * 4 + 2] = 255;
- curtex[(curU + u + (curV + v) * 256) * 4 + 3] = f;
- }
- }
- }
- if (((curU += maxX) + maxX) > 256) {
- curU = 0;
- if (((curV += maxY) + maxY) > 256) {
- curV = 0;
- if ((curT + 1) != nbT)
- curtex = (Uint8 *) fonttex[++curT]->GetSurface()->pixels;
- }
- }
- }
-
- corresp = (Uint16 *) malloc(nbentries * 2 * sizeof(Uint16));
-
- for (i = 0; i < 2 * nbentries; i++) {
- corresp[i] = ffont->readU16();
- }
+mogltk::glfont::glfont(Handle * ffont) : font(ffont) {
}
-mogltk::font::~font() {
- int i;
- for (i = 0; i < nbT; i++) {
- delete fonttex[i];
- }
-
- free((void *&) fonttex);
- free(sizes);
+mogltk::glfont::~glfont() {
}
-void mogltk::font::drawentry(Uint16 entry, int x, int y, ColorP c) {
+void mogltk::glfont::drawentry(Uint16 entry, int x, int y, glColorP c) {
bool was2D;
int trueentry, cx, cy, px, py;
- was2D = mogltk::glbase::is2D();
+ was2D = mogltk::engine::glbase_o->is2D();
if (!was2D)
- mogltk::glbase::Enter2DMode();
+ mogltk::engine::glbase_o->Enter2DMode();
if (shadow) {
int os = shadow;
@@ -198,123 +47,9 @@ void mogltk::font::drawentry(Uint16 entry, int x, int y, ColorP c) {
glEnd();
if (!was2D)
- mogltk::glbase::Leave2DMode();
+ mogltk::engine::glbase_o->Leave2DMode();
}
-void mogltk::font::Bind(int index) {
+void mogltk::glfont::Bind(int index) {
fonttex[index]->Bind();
}
-
-void mogltk::font::putcursor(int x, int y) {
- cx = ox = x;
- cy = y;
-}
-
-void mogltk::font::putentry(Uint16 entry, ColorP c) {
- drawentry(entry, cx, cy, c);
- cx += sizes[entry] + wspace;
-}
-
-void mogltk::font::putchar(char ch, ColorP c) {
- Uint16 * p;
- int i;
-
- for (i = 0, p = corresp; i < nbentries; i++, p++) {
- if (*(p++) == ch) {
- putentry(*p, c);
- return;
- }
- }
-}
-
-int mogltk::font::getchar(char ch) const {
- Uint16 * p;
- int i;
-
- for (i = 0, p = corresp; i < nbentries; i++, p++) {
- if (*(p++) == ch) {
- return *p;
- }
- }
-
- return -1;
-}
-
-void mogltk::font::newline(void) {
- cx = ox;
- cy += inter;
-}
-
-int mogltk::font::printf(const ugly_string & m, va_list ap) {
- char * p;
- static char buffer[STRBUFSIZ + 1];
- int r;
-
-#ifdef HAVE_VSNPRINTF
- r = vsnprintf(buffer, STRBUFSIZ, m.p, ap);
-#else
- r = vsprintf(buffer, m.p, ap);
-#endif
-
- for (p = buffer; *p; p++) {
- if (*p == '\n') {
- newline();
- } else {
- putchar(*p, textcolor);
- }
- }
-
- return r;
-}
-
-int mogltk::font::printf(const ugly_string & m, ...) {
- va_list ap;
- int r;
-
- va_start(ap, m);
- r = printf(m, ap);
- va_end(ap);
-
- return r;
-}
-
-int mogltk::font::printf(const char * p, ...) {
- ugly_string m;
- va_list ap;
- int r;
-
- m.p = p;
-
- va_start(ap, p);
- r = printf(m, ap);
- va_end(ap);
-
- return r;
-}
-
-void mogltk::font::setcolor(ColorP c) {
- textcolor = c;
-}
-
-void mogltk::font::setshadow(int s) {
- shadow = s;
-}
-
-void mogltk::font::setwspace(int w) {
- wspace = w;
-}
-
-int mogltk::font::singletextsize(const String & s) const {
- unsigned int i;
- int r = 0;
-
- for (i = 0; i < s.strlen(); i++) {
- r += sizes[getchar(s[i])];
- }
-
- return r;
-}
-
-mogltk::font * mogltk::SystemFont;
-
-
diff --git a/lib/glshape.cc b/lib/glshape.cc
index 6c314fb..7b93dfb 100644
--- a/lib/glshape.cc
+++ b/lib/glshape.cc
@@ -4,11 +4,11 @@
#include "gltexture.h"
#include "glfont.h"
-#define ENTER bool was2d = in2D(true)
-#define ENTERT bool was2d = in2D(false)
-#define LEAVE out2D(was2d)
+#define ENTER bool was2d = Enter(true)
+#define ENTERT bool was2d = Enter(false)
+#define LEAVE Leave(was2d)
-void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) {
+void mogltk::glshape::box(int x1, int y1, int x2, int y2, glColorP c) {
ENTER;
c.Bind();
@@ -22,7 +22,7 @@ void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) {
LEAVE;
}
-void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) {
+void mogltk::glshape::box(int x1, int y1, int x2, int y2, glColorP c1, glColorP c2, glColorP c3, glColorP c4) {
ENTER;
glBegin(GL_TRIANGLE_STRIP);
@@ -35,85 +35,7 @@ void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, Co
LEAVE;
}
-void mogltk::shape::hline(int x1, int x2, int y, ColorP c) {
- box(x1, y, x2, y, c);
-}
-
-void mogltk::shape::hline3d(int x1, int x2, int y, ColorP shade1, ColorP shade2, bool bevel) {
- ENTER;
-
- if (!bevel) {
- hline(x1, x2, y, shade2);
- hline(x1, x2, y + 1, shade1);
- } else {
- hline(x1, x2, y, shade1);
- hline(x1, x2, y + 1, shade2);
- }
-
- LEAVE;
-}
-
-void mogltk::shape::vline(int x, int y1, int y2, ColorP c) {
- box(x, y1, x, y2, c);
-}
-
-void mogltk::shape::vline3d(int x, int y1, int y2, ColorP shade1, ColorP shade2, bool bevel) {
- ENTER;
-
- if (!bevel) {
- vline(x, y1, y2, shade2);
- vline(x + 1, y1, y2, shade1);
- } else {
- vline(x, y1, y2, shade1);
- vline(x + 1, y1, y2, shade2);
- }
-
- LEAVE;
-}
-
-void mogltk::shape::hline(int x1, int x2, int y, ColorP c1, ColorP c2) {
- box(x1, y, x2, y, c1, c2, c1, c2);
-}
-
-void mogltk::shape::vline(int x, int y1, int y2, ColorP c1, ColorP c2) {
- box(x, y1, x, y2, c1, c1, c2, c2);
-}
-
-void mogltk::shape::pixel(int x, int y, ColorP c) {
- box(x, y, x, y, c);
-}
-
-void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c) {
- ENTER;
-
- hline(x1, x2, y1, c);
- hline(x1, x2, y2, c);
- vline(x1, y1, y2, c);
- vline(x2, y1, y2, c);
-
- LEAVE;
-}
-
-void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) {
- ENTER;
-
- hline(x1, x2, y1, c1, c2);
- hline(x1, x2, y2, c3, c4);
- vline(x1, y1, y2, c1, c3);
- vline(x2, y1, y2, c2, c4);
-
- LEAVE;
-}
-
-void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx, int ty, double f, ColorP c) {
- tbox(t, x1, y1, x2, y2, tx, ty, tx + (int) ((x2 - x1) * f), ty + (int) ((y2 - y1) * f), c);
-}
-
-void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4, int tx, int ty, double f) {
- tbox(t, x1, y1, x2, y2, c1, c2, c3, c4, tx, ty, tx + (int) ((x2 - x1) * f), ty + (int) ((y2 - y1) * f));
-}
-
-void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP c) {
+void mogltk::glshape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, glColorP c) {
ENTERT;
c.Bind();
@@ -128,7 +50,7 @@ void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, in
LEAVE;
}
-void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4, int tx1, int ty1, int tx2, int ty2) {
+void mogltk::glshape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, glColorP c1, glColorP c2, glColorP c3, glColorP c4, int tx1, int ty1, int tx2, int ty2) {
ENTERT;
t->Bind();
@@ -142,7 +64,7 @@ void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, Co
LEAVE;
}
-void mogltk::shape::box3d(int x1, int y1, int x2, int y2, ColorP face, ColorP shade1, ColorP shade2, int depth, bool bevel) {
+void mogltk::glshape::box3d(int x1, int y1, int x2, int y2, glColorP face, glColorP shade1, glColorP shade2, int depth, bool bevel) {
ENTER;
if (!bevel) {
@@ -182,92 +104,7 @@ void mogltk::shape::box3d(int x1, int y1, int x2, int y2, ColorP face, ColorP sh
LEAVE;
}
-void mogltk::shape::obox3d(int x1, int y1, int x2, int y2, ColorP shade1, ColorP shade2, bool bevel) {
- ENTER;
-
- if (!bevel) {
- obox(x1 + 1, y1 + 1, x2, y2, shade1);
- obox(x1, y1, x2 - 1, y2 - 1, shade2);
- } else {
- obox(x1, y1, x2 - 1, y2 - 1, shade1);
- obox(x1 + 1, y1 + 1, x2, y2, shade2);
- }
-
- LEAVE;
-}
-
-void mogltk::shape::window(int x1, int y1, int x2, int y2, const String & title,
- ColorP titlecolor, ColorP titlebackcolor,
- ColorP front, ColorP shade1, ColorP shade2) {
- ENTER;
-
- box3d(x1, y1, x2, y2, front, shade1, shade2);
- hline3d(x1 + 2, x2 - 2, y1 + 19, shade1, shade2, 1);
- box(x1 + 2, y1 + 2, x2 - 2, y1 + 18, titlebackcolor);
- text((x1 + x2) / 2, y1 + 2, title, titlecolor, CENTER);
-
- LEAVE;
-}
-
-void mogltk::shape::text(int x, int y, const String & text, ColorP textcolor, align_t align) {
- int tsize = SystemFont->singletextsize(text);
- switch (align) {
- case LEFT:
- SystemFont->putcursor(x, y);
- break;
- case CENTER:
- SystemFont->putcursor(x - (tsize / 2), y);
- break;
- case RIGHT:
- SystemFont->putcursor(x - tsize, y);
- break;
- }
- SystemFont->setcolor(textcolor);
- SystemFont->setshadow(0);
- SystemFont->printf(text);
-}
-
-void mogltk::shape::text3d(int x, int y, const String & atext, ColorP textcolor,
- ColorP shade1, ColorP shade2,
- align_t align, bool bevel) {
- ENTER;
-
- SystemFont->setwspace(1);
- if (!bevel) {
- text(x - 1, y - 1, atext, shade2, align);
- text(x + 1, y + 1, atext, shade1, align);
- } else {
- text(x - 1, y - 1, atext, shade1, align);
- text(x + 1, y + 1, atext, shade2, align);
- }
- text(x, y, atext, textcolor, align);
- SystemFont->setwspace(0);
-
- LEAVE;
-}
-
-void mogltk::shape::button(int x1, int y1, int x2, int y2,
- const String & atext, bool bevel,
- ColorP front, ColorP shade1, ColorP shade2,
- ColorP round, ColorP textcolor,
- ColorP tshade1, ColorP tshade2) {
- ENTER;
-
- box3d(x1, y1, x2, y2, front, shade1, shade2, 2, bevel);
- hline(x1, x2, y1 - 1, round);
- hline(x1, x2, y2 + 1, round);
- vline(x1 - 1, y1, y2, round);
- vline(x2 + 1, y1, y2, round);
- pixel(x1, y1, round);
- pixel(x1, y2, round);
- pixel(x2, y1, round);
- pixel(x2, y2, round);
- text3d((x1 + x2) / 2, (y1 + y2) / 2 - 8, atext, textcolor, tshade1, tshade2, CENTER, bevel);
-
- LEAVE;
-}
-
-bool mogltk::shape::in2D(bool unbind) {
+bool mogltk::glshape::Enter(bool unbind) {
bool was2D = mogltk::glbase::is2D();
if (!was2D)
@@ -278,7 +115,11 @@ bool mogltk::shape::in2D(bool unbind) {
return was2D;
}
-void mogltk::shape::out2D(bool was2D) {
+bool mogltk::glshape::Enter() {
+ return Enter(true);
+}
+
+void mogltk::glshape::Leave(bool was2D) {
if (!was2D)
mogltk::glbase::Leave2DMode();
}
diff --git a/lib/mcolor.cc b/lib/mcolor.cc
new file mode 100644
index 0000000..91c8a1d
--- /dev/null
+++ b/lib/mcolor.cc
@@ -0,0 +1,10 @@
+#include <SDL.h>
+#include "mcolor.h"
+
+Color mogltk::ColorP::Min(0, 0, 0, 0), mogltk::ColorP::Max = WHITE;
+
+mogltk::ColorP::ColorP(const Color & ac) : c(ac) {
+}
+
+mogltk::ColorP::ColorP(Uint8 ar, Uint8 ag, Uint8 ab, Uint8 aa) : c(ar, ag, ab, aa) {
+}
diff --git a/lib/shape.cc b/lib/shape.cc
new file mode 100644
index 0000000..088deb7
--- /dev/null
+++ b/lib/shape.cc
@@ -0,0 +1,287 @@
+#include <SDL.h>
+#include "base.h"
+#include "shape.h"
+#include "texture.h"
+#include "font.h"
+
+#define ENTER bool flag = Enter()
+#define LEAVE Leave(flag)
+
+void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) {
+ ENTER;
+
+ c.Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glVertex2i(x1, y1);
+ glVertex2i(x2 + 1, y1);
+ glVertex2i(x1, y2 + 1);
+ glVertex2i(x2 + 1, y2 + 1);
+ glEnd();
+
+ LEAVE;
+}
+
+void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) {
+ ENTER;
+
+ glBegin(GL_TRIANGLE_STRIP);
+ c1.Bind(); glVertex2i(x1, y1);
+ c2.Bind(); glVertex2i(x2 + 1, y1);
+ c3.Bind(); glVertex2i(x1, y2 + 1);
+ c4.Bind(); glVertex2i(x2 + 1, y2 + 1);
+ glEnd();
+
+ LEAVE;
+}
+
+void mogltk::shape::hline(int x1, int x2, int y, ColorP c) {
+ box(x1, y, x2, y, c);
+}
+
+void mogltk::shape::hline3d(int x1, int x2, int y, ColorP shade1, ColorP shade2, bool bevel) {
+ ENTER;
+
+ if (!bevel) {
+ hline(x1, x2, y, shade2);
+ hline(x1, x2, y + 1, shade1);
+ } else {
+ hline(x1, x2, y, shade1);
+ hline(x1, x2, y + 1, shade2);
+ }
+
+ LEAVE;
+}
+
+void mogltk::shape::vline(int x, int y1, int y2, ColorP c) {
+ box(x, y1, x, y2, c);
+}
+
+void mogltk::shape::vline3d(int x, int y1, int y2, ColorP shade1, ColorP shade2, bool bevel) {
+ ENTER;
+
+ if (!bevel) {
+ vline(x, y1, y2, shade2);
+ vline(x + 1, y1, y2, shade1);
+ } else {
+ vline(x, y1, y2, shade1);
+ vline(x + 1, y1, y2, shade2);
+ }
+
+ LEAVE;
+}
+
+void mogltk::shape::hline(int x1, int x2, int y, ColorP c1, ColorP c2) {
+ box(x1, y, x2, y, c1, c2, c1, c2);
+}
+
+void mogltk::shape::vline(int x, int y1, int y2, ColorP c1, ColorP c2) {
+ box(x, y1, x, y2, c1, c1, c2, c2);
+}
+
+void mogltk::shape::pixel(int x, int y, ColorP c) {
+ box(x, y, x, y, c);
+}
+
+void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c) {
+ ENTER;
+
+ hline(x1, x2, y1, c);
+ hline(x1, x2, y2, c);
+ vline(x1, y1, y2, c);
+ vline(x2, y1, y2, c);
+
+ LEAVE;
+}
+
+void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) {
+ ENTER;
+
+ hline(x1, x2, y1, c1, c2);
+ hline(x1, x2, y2, c3, c4);
+ vline(x1, y1, y2, c1, c3);
+ vline(x2, y1, y2, c2, c4);
+
+ LEAVE;
+}
+
+void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx, int ty, double f, ColorP c) {
+ tbox(t, x1, y1, x2, y2, tx, ty, tx + (int) ((x2 - x1) * f), ty + (int) ((y2 - y1) * f), c);
+}
+
+void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4, int tx, int ty, double f) {
+ tbox(t, x1, y1, x2, y2, c1, c2, c3, c4, tx, ty, tx + (int) ((x2 - x1) * f), ty + (int) ((y2 - y1) * f));
+}
+
+void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP c) {
+ ENTERT;
+
+ c.Bind();
+ t->Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2i(tx1, ty1); glVertex2i(x1, y1);
+ glTexCoord2i(tx2 + 1, ty1); glVertex2i(x2 + 1, y1);
+ glTexCoord2i(tx1, ty2 + 1); glVertex2i(x1, y2 + 1);
+ glTexCoord2i(tx2 + 1, ty2 + 1); glVertex2i(x2 + 1, y2 + 1);
+ glEnd();
+
+ LEAVE;
+}
+
+void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4, int tx1, int ty1, int tx2, int ty2) {
+ ENTERT;
+
+ t->Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ c1.Bind(); glTexCoord2i(tx1, ty1); glVertex2i(x1, y1);
+ c2.Bind(); glTexCoord2i(tx2 + 1, ty1); glVertex2i(x2 + 1, y1);
+ c3.Bind(); glTexCoord2i(tx1, ty2 + 1); glVertex2i(x1, y2 + 1);
+ c4.Bind(); glTexCoord2i(tx2 + 1, ty2 + 1); glVertex2i(x2 + 1, y2 + 1);
+ glEnd();
+
+ LEAVE;
+}
+
+void mogltk::shape::box3d(int x1, int y1, int x2, int y2, ColorP face, ColorP shade1, ColorP shade2, int depth, bool bevel) {
+ ENTER;
+
+ if (!bevel) {
+ shade1.Bind();
+ } else {
+ shade2.Bind();
+ }
+ glBegin(GL_TRIANGLE_FAN);
+ glVertex2i(x1, y1);
+ glVertex2i(x2 + 1, y1);
+ glVertex2i(x2 + 1 - depth, y1 + depth);
+ glVertex2i(x1 + depth, y2 + 1 - depth);
+ glVertex2i(x1, y2 + 1);
+ glEnd();
+
+ if (!bevel) {
+ shade2.Bind();
+ } else {
+ shade1.Bind();
+ }
+ glBegin(GL_TRIANGLE_FAN);
+ glVertex2i(x2 + 1, y2 + 1);
+ glVertex2i(x1, y2 + 1);
+ glVertex2i(x1 + depth, y2 + 1 - depth);
+ glVertex2i(x2 + 1 - depth, y1 + depth);
+ glVertex2i(x2 + 1, y1);
+ glEnd();
+
+ face.Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glVertex2i(x1 + depth, y1 + depth);
+ glVertex2i(x2 + 1 - depth, y1 + depth);
+ glVertex2i(x1 + depth, y2 + 1 - depth);
+ glVertex2i(x2 + 1 - depth, y2 + 1 - depth);
+ glEnd();
+
+ LEAVE;
+}
+
+void mogltk::shape::obox3d(int x1, int y1, int x2, int y2, ColorP shade1, ColorP shade2, bool bevel) {
+ ENTER;
+
+ if (!bevel) {
+ obox(x1 + 1, y1 + 1, x2, y2, shade1);
+ obox(x1, y1, x2 - 1, y2 - 1, shade2);
+ } else {
+ obox(x1, y1, x2 - 1, y2 - 1, shade1);
+ obox(x1 + 1, y1 + 1, x2, y2, shade2);
+ }
+
+ LEAVE;
+}
+
+void mogltk::shape::window(int x1, int y1, int x2, int y2, const String & title,
+ ColorP titlecolor, ColorP titlebackcolor,
+ ColorP front, ColorP shade1, ColorP shade2) {
+ ENTER;
+
+ box3d(x1, y1, x2, y2, front, shade1, shade2);
+ hline3d(x1 + 2, x2 - 2, y1 + 19, shade1, shade2, 1);
+ box(x1 + 2, y1 + 2, x2 - 2, y1 + 18, titlebackcolor);
+ text((x1 + x2) / 2, y1 + 2, title, titlecolor, CENTER);
+
+ LEAVE;
+}
+
+void mogltk::shape::text(int x, int y, const String & text, ColorP textcolor, align_t align) {
+ int tsize = SystemFont->singletextsize(text);
+ switch (align) {
+ case LEFT:
+ SystemFont->putcursor(x, y);
+ break;
+ case CENTER:
+ SystemFont->putcursor(x - (tsize / 2), y);
+ break;
+ case RIGHT:
+ SystemFont->putcursor(x - tsize, y);
+ break;
+ }
+ SystemFont->setcolor(textcolor);
+ SystemFont->setshadow(0);
+ SystemFont->printf(text);
+}
+
+void mogltk::shape::text3d(int x, int y, const String & atext, ColorP textcolor,
+ ColorP shade1, ColorP shade2,
+ align_t align, bool bevel) {
+ ENTER;
+
+ SystemFont->setwspace(1);
+ if (!bevel) {
+ text(x - 1, y - 1, atext, shade2, align);
+ text(x + 1, y + 1, atext, shade1, align);
+ } else {
+ text(x - 1, y - 1, atext, shade1, align);
+ text(x + 1, y + 1, atext, shade2, align);
+ }
+ text(x, y, atext, textcolor, align);
+ SystemFont->setwspace(0);
+
+ LEAVE;
+}
+
+void mogltk::shape::button(int x1, int y1, int x2, int y2,
+ const String & atext, bool bevel,
+ ColorP front, ColorP shade1, ColorP shade2,
+ ColorP round, ColorP textcolor,
+ ColorP tshade1, ColorP tshade2) {
+ ENTER;
+
+ box3d(x1, y1, x2, y2, front, shade1, shade2, 2, bevel);
+ hline(x1, x2, y1 - 1, round);
+ hline(x1, x2, y2 + 1, round);
+ vline(x1 - 1, y1, y2, round);
+ vline(x2 + 1, y1, y2, round);
+ pixel(x1, y1, round);
+ pixel(x1, y2, round);
+ pixel(x2, y1, round);
+ pixel(x2, y2, round);
+ text3d((x1 + x2) / 2, (y1 + y2) / 2 - 8, atext, textcolor, tshade1, tshade2, CENTER, bevel);
+
+ LEAVE;
+}
+
+bool mogltk::shape::Enter(bool unbind) {
+ bool was2D = mogltk::glbase::is2D();
+
+ if (!was2D)
+ mogltk::glbase::Enter2DMode();
+
+ if (unbind) mogltk::texture::Unbind();
+
+ return was2D;
+}
+
+bool mogltk::shape::Enter() {
+ return Enter(false);
+}
+
+void mogltk::shape::Leave(bool was2D) {
+ if (!was2D)
+ mogltk::glbase::Leave2DMode();
+}