diff options
-rw-r--r-- | include/glcolor.h | 3 | ||||
-rw-r--r-- | include/glshape.h | 22 | ||||
-rw-r--r-- | lib/glcolor.cc | 4 | ||||
-rw-r--r-- | lib/glshape.cc | 110 | ||||
-rw-r--r-- | src/font.bin | bin | 66823 -> 66823 bytes | |||
-rw-r--r-- | src/test.cc | 4 |
6 files changed, 141 insertions, 2 deletions
diff --git a/include/glcolor.h b/include/glcolor.h index 8296451..28ce1f7 100644 --- a/include/glcolor.h +++ b/include/glcolor.h @@ -10,7 +10,8 @@ namespace mogltk { ColorP(const Color &); ColorP(Uint8, Uint8, Uint8, Uint8); void Bind(); - private: + static Color Min; + static Color Max; Color c; }; }; diff --git a/include/glshape.h b/include/glshape.h index a0c7bf2..10c5145 100644 --- a/include/glshape.h +++ b/include/glshape.h @@ -2,24 +2,46 @@ #define __GLSHAPE_H__ #include <Exceptions.h> +#include <BString.h> #include <glcolor.h> #include <gltexture.h> namespace mogltk { + typedef enum { + LEFT, + CENTER, + RIGHT + } align_t; class shape : public Base { public: 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, int = 0); 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, int = 0); 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, int = 0); 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, int = 0); static void vline(int x, int y1, int y2, ColorP, ColorP); + static void window(int x1, int y1, int x2, int y2, 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 text3d(int x, int y, String, + ColorP textcolor = DOS_BLACK, + ColorP shade1 = DOS_HIGH_WHITE, + ColorP shade2 = DOS_GRAY, + align_t align = LEFT, + int bevel = 0); private: static bool in2D(bool); static void out2D(bool); diff --git a/lib/glcolor.cc b/lib/glcolor.cc index 23ade75..c274620 100644 --- a/lib/glcolor.cc +++ b/lib/glcolor.cc @@ -1,6 +1,8 @@ #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) { } @@ -8,6 +10,6 @@ mogltk::ColorP::ColorP(Uint8 ar, Uint8 ag, Uint8 ab, Uint8 aa) : c(ar, ag, ab, a } void mogltk::ColorP::Bind() { - glColor4d((double) c.R / 255, (double) c.G / 255, (double) c.B / 255, (double) c.A / 255); + 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/glshape.cc b/lib/glshape.cc index 6d88a15..55a02cf 100644 --- a/lib/glshape.cc +++ b/lib/glshape.cc @@ -2,6 +2,7 @@ #include "glbase.h" #include "glshape.h" #include "gltexture.h" +#include "glfont.h" #define ENTER bool was2d = in2D(true) #define ENTERT bool was2d = in2D(false) @@ -38,10 +39,38 @@ 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, int 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, int 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); } @@ -52,19 +81,23 @@ void mogltk::shape::vline(int x, int y1, int y2, ColorP c1, ColorP c2) { 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; } @@ -105,6 +138,83 @@ 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, int 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, int 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, 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 + 18, shade1, shade2, 1); + box(x1 + 2, y1 + 2, x2 - 2, y1 + 17, titlebackcolor); + int tsize = SystemFont->singletextsize(title); + SystemFont->putcursor((x2 + x1 - tsize) / 2, y1 + 2); + SystemFont->setcolor(titlecolor); + SystemFont->setshadow(0); + SystemFont->printf(title); + + LEAVE; +} + +void mogltk::shape::text3d(int x, int y, String text, ColorP textcolor, + ColorP shade1, ColorP shade2, + align_t align, int bevel) { + +} + bool mogltk::shape::in2D(bool unbind) { bool was2D = mogltk::glbase::is2D(); diff --git a/src/font.bin b/src/font.bin Binary files differindex 10e1b48..7a4f427 100644 --- a/src/font.bin +++ b/src/font.bin diff --git a/src/test.cc b/src/test.cc index a3a4230..a9f7716 100644 --- a/src/test.cc +++ b/src/test.cc @@ -51,6 +51,10 @@ virtual int startup() throw (GeneralException) { "I can't believe it!\n" ); + mogltk::shape::box3d(50, 150, 150, 200); + mogltk::shape::obox3d(50, 250, 150, 300); + mogltk::shape::window(50, 350, 150, 400, "Titre pas beau"); + mogltk::shape::box(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); font.putcursor(550, 400); |