summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/glfont.h3
-rw-r--r--include/glshape.h38
-rw-r--r--lib/glfont.cc8
-rw-r--r--lib/glshape.cc84
-rw-r--r--src/font.binbin66823 -> 66823 bytes
-rw-r--r--src/test.cc6
6 files changed, 106 insertions, 33 deletions
diff --git a/include/glfont.h b/include/glfont.h
index 991024e..87efd12 100644
--- a/include/glfont.h
+++ b/include/glfont.h
@@ -23,6 +23,7 @@ namespace mogltk {
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;
@@ -35,7 +36,7 @@ namespace mogltk {
void Bind(int);
int cx, cy, ox;
ColorP textcolor;
- int shadow;
+ int shadow, wspace;
};
extern font * SystemFont;
};
diff --git a/include/glshape.h b/include/glshape.h
index 10c5145..b65c21e 100644
--- a/include/glshape.h
+++ b/include/glshape.h
@@ -14,34 +14,48 @@ namespace mogltk {
} align_t;
class shape : public Base {
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, int = 0);
+ 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, int = 0);
+ 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, int = 0);
+ 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, int = 0);
+ 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, 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,
+ 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,
- int bevel = 0);
+ 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);
private:
static bool in2D(bool);
static void out2D(bool);
diff --git a/lib/glfont.cc b/lib/glfont.cc
index d8dbb5b..9b77c8c 100644
--- a/lib/glfont.cc
+++ b/lib/glfont.cc
@@ -77,7 +77,7 @@ nbT = number of textures
*/
-mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255) {
+mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255), shadow(0), wspace(0) {
int i;
nbentries = ffont->readU16();
@@ -210,7 +210,7 @@ void mogltk::font::putcursor(int x, int y) {
void mogltk::font::putentry(Uint16 entry, ColorP c) {
drawentry(entry, cx, cy, c);
- cx += sizes[entry];
+ cx += sizes[entry] + wspace;
}
void mogltk::font::putchar(char ch, ColorP c) {
@@ -298,6 +298,10 @@ 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;
diff --git a/lib/glshape.cc b/lib/glshape.cc
index 55a02cf..6c314fb 100644
--- a/lib/glshape.cc
+++ b/lib/glshape.cc
@@ -39,7 +39,7 @@ 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) {
+void mogltk::shape::hline3d(int x1, int x2, int y, ColorP shade1, ColorP shade2, bool bevel) {
ENTER;
if (!bevel) {
@@ -57,7 +57,7 @@ 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) {
+void mogltk::shape::vline3d(int x, int y1, int y2, ColorP shade1, ColorP shade2, bool bevel) {
ENTER;
if (!bevel) {
@@ -79,6 +79,10 @@ 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;
@@ -102,11 +106,11 @@ void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, C
}
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 + (x2 - x1) * f, ty + (y2 - y1) * f, 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 + (x2 - x1) * f, ty + (y2 - y1) * 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) {
@@ -138,7 +142,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, int bevel) {
+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) {
@@ -178,7 +182,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, int bevel) {
+void mogltk::shape::obox3d(int x1, int y1, int x2, int y2, ColorP shade1, ColorP shade2, bool bevel) {
ENTER;
if (!bevel) {
@@ -192,27 +196,75 @@ void mogltk::shape::obox3d(int x1, int y1, int x2, int y2, ColorP shade1, ColorP
LEAVE;
}
-void mogltk::shape::window(int x1, int y1, int x2, int y2, String title,
+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 + 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);
+ 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::text3d(int x, int y, String text, ColorP textcolor,
+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, int bevel) {
+ 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) {
diff --git a/src/font.bin b/src/font.bin
index 7a4f427..c0dfd31 100644
--- a/src/font.bin
+++ b/src/font.bin
Binary files differ
diff --git a/src/test.cc b/src/test.cc
index a9f7716..1057033 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -16,7 +16,7 @@ CODE_BEGINS
virtual int startup() throw (GeneralException) {
int sx1, sx2, sy1, sy2;
double t = 0;
-// verbosity = M_INFO;
+ verbosity = M_INFO;
mogltk::glbase::setup();
new Archive("datas.paq");
mogltk::font font(&Input("font-2.bin"));
@@ -53,7 +53,9 @@ virtual int startup() throw (GeneralException) {
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::window(50, 350, 150, 400, "Titre plus beau ;)");
+ mogltk::shape::box3d(180, 130, 320, 220);
+ mogltk::shape::button(200, 150, 300, 200, "Bouton");
mogltk::shape::box(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue);