diff options
-rw-r--r-- | include/base.h | 4 | ||||
-rw-r--r-- | include/engine.h | 23 | ||||
-rw-r--r-- | include/font.h | 13 | ||||
-rw-r--r-- | include/sprite.h | 2 | ||||
-rw-r--r-- | include/texture.h | 4 | ||||
-rw-r--r-- | lib/base.cc | 16 | ||||
-rw-r--r-- | lib/engine.cc | 90 | ||||
-rw-r--r-- | lib/font.cc | 307 | ||||
-rw-r--r-- | lib/glbase.cc | 2 | ||||
-rw-r--r-- | lib/glsprite.cc | 6 | ||||
-rw-r--r-- | lib/sprite.cc | 6 | ||||
-rw-r--r-- | lib/texture.cc | 23 | ||||
-rw-r--r-- | lib/widgets.cc | 9 | ||||
-rw-r--r-- | src/test.cc | 247 |
14 files changed, 632 insertions, 120 deletions
diff --git a/include/base.h b/include/base.h index 2607cf5..66e3172 100644 --- a/include/base.h +++ b/include/base.h @@ -5,6 +5,9 @@ #include <Exceptions.h> namespace mogltk { + struct rect { + int x, y, w, h; + }; class base : public Base { public: base(int w = 640, int h = 480, int flags = 0) throw(GeneralException); @@ -17,6 +20,7 @@ namespace mogltk { virtual void Leave2DMode(); virtual bool is2D(); virtual void changeviewport(int x = 0, int y = 0, unsigned int w = 0, unsigned int h = 0); + void ToggleFullscreen(); protected: base(int, int, int, int); void setsurface(SDL_Surface *) throw (GeneralException); diff --git a/include/engine.h b/include/engine.h index 8634f6a..6a88154 100644 --- a/include/engine.h +++ b/include/engine.h @@ -13,9 +13,24 @@ namespace mogltk { public: class keyevent : public Base { public: + keyevent(); + virtual ~keyevent(); virtual void down(SDL_keysym); virtual void up(SDL_keysym); + protected: + void passdown(SDL_keysym); + keyevent * old_handler, * new_handler; }; + class mouseevent : public Base { + public: + mouseevent(); + virtual ~mouseevent(); + virtual void move(SDL_MouseMotionEvent); + virtual void action(SDL_MouseButtonEvent); + protected: + void passdown(SDL_MouseMotionEvent); + mouseevent * old_handler, * new_handler; + }; static int setup() throw(GeneralException); static int postsetup() throw(GeneralException); static int GetInited(); @@ -25,15 +40,22 @@ namespace mogltk { static bool getappactive(); static void setcursorvisible(bool); static bool getcursorvisible(); + static void quit(); static bool quitrequested(); static int mouseX(); static int mouseY(); static int mouseZ(); + static void setmouseX(int); + static void setmouseY(int); + static void setmouseZ(int); static int mousebuttons(); static double FPS(); static void lockmouse(); static void unlockmouse(); static void setkeyevent(keyevent *); + static void setmouseevent(mouseevent *); + static keyevent * getkeyevent(); + static mouseevent * getmouseevent(); static glbase * glbase_o; static base * base_o; static widget * root; @@ -52,6 +74,7 @@ namespace mogltk { static Uint32 curticks; static int locked; static keyevent * keyevent_h; + static mouseevent * mouseevent_h; static void updatemouse(); }; }; diff --git a/include/font.h b/include/font.h index a557f6e..07f7c03 100644 --- a/include/font.h +++ b/include/font.h @@ -7,6 +7,7 @@ #include <Handle.h> #include <texture.h> #include <mcolor.h> +#include <base.h> namespace mogltk { class font : public Base { @@ -14,13 +15,25 @@ namespace mogltk { font(Handle *); virtual ~font(); virtual void drawentry(Uint16, int, int, ColorP = WHITE); + void drawtotex(texture *, Uint16, int, int, ColorP = WHITE); void putcursor(int, int); void putentry(Uint16, ColorP = WHITE); + void putentryontex(texture *, Uint16, ColorP = WHITE); void drawchar(char, ColorP = WHITE); + void drawcharontex(texture *, char, ColorP = WHITE); void newline(void); int printf(const ugly_string &, ...); int printf(const char *, ...); int printf(const ugly_string &, va_list); + rect size(const ugly_string &, ...); + rect size(const char *, ...); + rect size(const ugly_string &, va_list); + rect printtotex(texture *, const ugly_string &, ...); + rect printtotex(texture *, const char *, ...); + rect printtotex(texture *, const ugly_string &, va_list); + texture * printtex(rect *, const ugly_string &, ...); + texture * printtex(rect *, const char *, ...); + texture * printtex(rect *, const ugly_string &, va_list); void setcolor(ColorP); void setshadow(int); void setwspace(int); diff --git a/include/sprite.h b/include/sprite.h index b4ef54a..d328dba 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -10,7 +10,7 @@ namespace mogltk { class Sprite : public Base { public: - Sprite(Handle *, int, int); + Sprite(Handle *, int, int) throw (GeneralException); Sprite(Uint8 *, int, int); virtual ~Sprite(); virtual void draw(int, int, ColorP = WHITE, float = 1.0, float = 1.0); diff --git a/include/texture.h b/include/texture.h index b558694..3b60e5b 100644 --- a/include/texture.h +++ b/include/texture.h @@ -23,17 +23,17 @@ namespace mogltk { GLuint GetHeight(); static void Unbind(void); void Taint(void); + static void Taintall(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; + void recTaint(void); }; }; diff --git a/lib/base.cc b/lib/base.cc index 7a6c854..acfc654 100644 --- a/lib/base.cc +++ b/lib/base.cc @@ -17,7 +17,7 @@ mogltk::base::base(int w, int h, int flags) throw(GeneralException) : surface(0) throw GeneralException(String("Couldn't initialise Video SubSystem: ") + SDL_GetError()); } - if (!(surface = SDL_SetVideoMode(width, height, 0, flags))) { + if (!(surface = SDL_SetVideoMode(width, height, 0, flags | SDL_HWSURFACE))) { throw GeneralException(String("Couldn't set SDL mode: ") + SDL_GetError()); } @@ -94,3 +94,17 @@ void mogltk::base::changeviewport(int x, int y, unsigned int w, unsigned int h) SDL_SetClipRect(surface, &r); } + +void mogltk::base::ToggleFullscreen() { + int newflags = surface->flags; + + if (surface->flags & SDL_FULLSCREEN) + newflags &= ~SDL_FULLSCREEN; + else + newflags |= SDL_FULLSCREEN; + + texture::Taintall(); + + surface = SDL_SetVideoMode(surface->w, surface->h, surface->format->BitsPerPixel, + SDL_HWSURFACE | newflags); +} diff --git a/lib/engine.cc b/lib/engine.cc index 6e899e2..3a2aaa0 100644 --- a/lib/engine.cc +++ b/lib/engine.cc @@ -20,9 +20,27 @@ mogltk::glbase * mogltk::engine::glbase_o = 0; mogltk::base * mogltk::engine::base_o = 0; mogltk::engine::keyevent * mogltk::engine::keyevent_h = 0; +mogltk::engine::mouseevent * mogltk::engine::mouseevent_h = 0; #define UPDATERATE 1000 +mogltk::engine::keyevent::keyevent() { + new_handler = 0; + if ((old_handler = getkeyevent())) + old_handler->new_handler = this; + setkeyevent(this); +} + +mogltk::engine::keyevent::~keyevent() { + if (new_handler) + new_handler->old_handler = old_handler; + if (old_handler) + old_handler->new_handler = new_handler; + + if (getkeyevent() == this) + setkeyevent(old_handler); +} + void mogltk::engine::keyevent::up(SDL_keysym) { printm(M_INFO, "Generic keyevent::up called\n"); } @@ -31,6 +49,31 @@ void mogltk::engine::keyevent::down(SDL_keysym) { printm(M_INFO, "Generic keyevent::down called\n"); } +mogltk::engine::mouseevent::mouseevent() { + new_handler = 0; + old_handler = getmouseevent(); + old_handler->new_handler = this; + setmouseevent(this); +} + +mogltk::engine::mouseevent::~mouseevent() { + if (new_handler) + new_handler->old_handler = old_handler; + if (old_handler) + old_handler->new_handler = new_handler; + + if (getmouseevent() == this) + setmouseevent(old_handler); +} + +void mogltk::engine::mouseevent::move(SDL_MouseMotionEvent) { + printm(M_INFO, "Generic mouseevent::move called\n"); +} + +void mogltk::engine::mouseevent::action(SDL_MouseButtonEvent) { + printm(M_INFO, "Generic mouseevent::action called\n"); +} + int mogltk::engine::setup() throw(GeneralException) { if (inited) { printm(M_WARNING, FUNCNAME + _(" called twice, ignoring second call.\n")); @@ -154,7 +197,7 @@ void mogltk::engine::pollevents() throw (GeneralException) { } while(true) { - if (hastoreturn) + if (hastoreturn || quitrequest) if (!SDL_PollEvent(NULL)) { updatemouse(); return; @@ -186,8 +229,6 @@ void mogltk::engine::pollevents() throw (GeneralException) { case SDL_KEYUP: printm(M_INFO, String("Key ") + event.key.keysym.scancode + " on keyboard " + event.key.which + (event.key.state == SDL_PRESSED ? " pressed" : " released") + "\n"); printm(M_INFO, "SDL keysym: %i - Unicode: %04x = `%c`- modifiers: %04x\n", event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.unicode, event.key.keysym.mod); - if (event.key.keysym.sym == 27) - hastoreturn = quitrequest = true; if (keyevent_h) { if (event.key.state == SDL_PRESSED) { keyevent_h->down(event.key.keysym); @@ -205,18 +246,24 @@ void mogltk::engine::pollevents() throw (GeneralException) { } if (cursorvisible) hastoreturn = true; + if (mouseevent_h) { + mouseevent_h->move(event.motion); + } break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: printm(M_INFO, String().set("Mouse button %02x ", event.button.button) + String((event.button.state == SDL_PRESSED ? "pressed" : "released")) + " at (" + event.button.x + ", " + event.button.y + ")\n"); - if (event.button.state == SDL_PRESSED) { - if (event.button.button == 4) { + if (event.button.state == SDL_PRESSED) { + if (event.button.button == SDL_BUTTON_WHEELUP) { mz--; } - if (event.button.button == 5) { + if (event.button.button == SDL_BUTTON_WHEELDOWN) { mz++; } } + if (mouseevent_h) { + mouseevent_h->action(event.button); + } break; case SDL_QUIT: printm(M_INFO, "Quit requested\n"); @@ -249,6 +296,10 @@ bool mogltk::engine::getcursorvisible() { return cursorvisible; } +void mogltk::engine::quit() { + quitrequest = true; +} + bool mogltk::engine::quitrequested() { return quitrequest; } @@ -269,6 +320,20 @@ int mogltk::engine::mouseZ() { return mz; } +void mogltk::engine::setmouseX(int _mx) { + mx = _mx; + SDL_WarpMouse(mx, my); +} + +void mogltk::engine::setmouseY(int _my) { + my = _my; + SDL_WarpMouse(mx, my); +} + +void mogltk::engine::setmouseZ(int _mz) { + mz = _mz; +} + int mogltk::engine::mousebuttons() { return mbuttons; } @@ -286,6 +351,17 @@ void mogltk::engine::unlockmouse() { } void mogltk::engine::setkeyevent(keyevent * k) { - printm(M_INFO, "Setting up a new keyevent\n"); keyevent_h = k; } + +void mogltk::engine::setmouseevent(mouseevent * m) { + mouseevent_h = m; +} + +mogltk::engine::keyevent * mogltk::engine::getkeyevent() { + return keyevent_h; +} + +mogltk::engine::mouseevent * mogltk::engine::getmouseevent() { + return mouseevent_h; +} diff --git a/lib/font.cc b/lib/font.cc index cd04177..4062c37 100644 --- a/lib/font.cc +++ b/lib/font.cc @@ -232,6 +232,44 @@ void mogltk::font::drawentry(Uint16 entry, int x, int y, ColorP c) { SDL_UnlockSurface(mogltk::engine::base_o->getsurface()); } +void mogltk::font::drawtotex(texture * t, Uint16 entry, int x, int y, ColorP c) { + bool locked = false; + int trueentry, cx, cy, px, py; + SDL_Rect src, dst; + + if (SDL_MUSTLOCK(t->GetSurface())) { + locked = true; + SDL_LockSurface(t->GetSurface()); + } + + if (shadow) { + int os = shadow; + shadow = 0; + + drawtotex(t, entry, x + os, y + os, BLACK); + + shadow = os; + } + + checknbind(entry / nbcT, c); + + y -= base; + + trueentry = entry % nbcT; + cx = trueentry % nbcU; + cy = trueentry / nbcU; + px = cx * maxX; + py = cy * maxY; + + src.x = px; src.y = py; src.w = maxX; src.h = maxY; + dst.x = x; dst.y = y; dst.w = maxX; dst.h = maxY; + + SDL_BlitSurface(fonttex[entry / nbcT]->GetSurface(), &src, t->GetSurface(), &dst); + + if (locked) + SDL_UnlockSurface(t->GetSurface()); +} + void mogltk::font::putcursor(int x, int y) { cx = ox = x; cy = y; @@ -242,6 +280,11 @@ void mogltk::font::putentry(Uint16 entry, ColorP c) { cx += sizes[entry] + wspace; } +void mogltk::font::putentryontex(texture * t, Uint16 entry, ColorP c) { + drawtotex(t, entry, cx, cy, c); + cx += sizes[entry] + wspace; +} + void mogltk::font::drawchar(char ch, ColorP c) { Uint16 * p; int i; @@ -254,6 +297,18 @@ void mogltk::font::drawchar(char ch, ColorP c) { } } +void mogltk::font::drawcharontex(texture * t, char ch, ColorP c) { + Uint16 * p; + int i; + + for (i = 0, p = corresp; i < nbentries; i++, p++) { + if (*(p++) == ch) { + putentryontex(t, *p, c); + return; + } + } +} + int mogltk::font::findchar(char ch) const { Uint16 * p; int i; @@ -319,6 +374,256 @@ int mogltk::font::printf(const char * p, ...) { return r; } +mogltk::rect mogltk::font::size(const ugly_string & m, va_list ap) { + char * p; + static char buffer[STRBUFSIZ + 1]; + rect r; + int mw, w; + + r.x = cx; + r.y = cy; + r.h = inter; + r.w = 0; + mw = 0; + w = 0; + +#ifdef HAVE_VSNPRINTF + vsnprintf(buffer, STRBUFSIZ, m.p, ap); +#else + vsprintf(buffer, m.p, ap); +#endif + + for (p = buffer; *p; p++) { + if (*p == '\n') { + if (*(p+1)) { + r.h += inter; + if (w > mw) { + mw = w; + } + w = 0; + } + } else { + w += sizes[findchar(*p)] + wspace; + } + } + + if (w > mw) { + mw = w; + } + + r.w = mw; + + return r; +} + +mogltk::rect mogltk::font::size(const ugly_string & m, ...) { + va_list ap; + rect r; + + va_start(ap, m); + r = size(m, ap); + va_end(ap); + + return r; +} + +mogltk::rect mogltk::font::size(const char * p, ...) { + ugly_string m; + va_list ap; + rect r; + + m.p = p; + + va_start(ap, p); + r = size(m, ap); + va_end(ap); + + return r; +} + +mogltk::rect mogltk::font::printtotex(texture * t, const ugly_string & m, va_list ap) { + char * p; + static char buffer[STRBUFSIZ + 1]; + rect r; + int mw, w; + + r.x = cx; + r.y = cy; + r.h = inter; + r.w = 0; + mw = 0; + w = 0; + +#ifdef HAVE_VSNPRINTF + vsnprintf(buffer, STRBUFSIZ, m.p, ap); +#else + vsprintf(buffer, m.p, ap); +#endif + + for (p = buffer; *p; p++) { + if (*p == '\n') { + if (*(p+1)) { + r.h += inter; + if (w > mw) { + mw = w; + } + w = 0; + } + } else { + w += sizes[findchar(*p)] + wspace; + } + } + + if (w > mw) { + mw = w; + } + + r.w = mw; + + for (p = buffer; *p; p++) { + if (*p == '\n') { + newline(); + } else { + drawcharontex(t, *p, textcolor); + } + } + + return r; +} + +mogltk::rect mogltk::font::printtotex(texture * t, const ugly_string & m, ...) { + va_list ap; + rect r; + + va_start(ap, m); + r = printtotex(t, m, ap); + va_end(ap); + + return r; +} + +mogltk::rect mogltk::font::printtotex(texture * t, const char * p, ...) { + ugly_string m; + va_list ap; + rect r; + + m.p = p; + + va_start(ap, p); + r = printtotex(t, m, ap); + va_end(ap); + + return r; +} + +inline unsigned int nextpower(unsigned int n) { + unsigned int i; + + if (!n) + return n; + + if (ISPOT(n)) + return n; + + for (i = 31; i >= 0; i--) { + if ((n >> i) & 1) { + return 1 << (i + 1); + } + } +} + +mogltk::texture * mogltk::font::printtex(rect * _r, const ugly_string & m, va_list ap) { + rect r; + char * p; + static char buffer[STRBUFSIZ + 1]; + int mw, w, pw, ph; + texture * t; + int ocx, ocy, oox; + + ocx = cx; + ocy = cy; + oox = ox; + + cx = ox = 0; + cy = base; + + r.x = cx; + r.y = cy; + r.h = inter; + r.w = 0; + mw = 0; + w = 0; + +#ifdef HAVE_VSNPRINTF + vsnprintf(buffer, STRBUFSIZ, m.p, ap); +#else + vsprintf(buffer, m.p, ap); +#endif + + for (p = buffer; *p; p++) { + if (*p == '\n') { + if (*(p+1)) { + r.h += inter; + if (w > mw) { + mw = w; + } + w = 0; + } + } else { + w += sizes[findchar(*p)] + wspace; + } + } + + if (w > mw) { + mw = w; + } + + r.w = mw; + + pw = nextpower(r.w); + ph = nextpower(r.h); + + t = new texture(pw, ph); + + for (p = buffer; *p; p++) { + if (*p == '\n') { + newline(); + } else { + drawcharontex(t, *p, textcolor); + } + } + + if (_r) + *_r = r; + + return t; +} + +mogltk::texture * mogltk::font::printtex(rect * r, const ugly_string & m, ...) { + va_list ap; + texture * t; + + va_start(ap, m); + t = printtex(r, m, ap); + va_end(ap); + + return t; +} + +mogltk::texture * mogltk::font::printtex(rect * r, const char * p, ...) { + ugly_string m; + va_list ap; + texture * t; + + m.p = p; + + va_start(ap, p); + t = printtex(r, m, ap); + va_end(ap); + + return t; +} + void mogltk::font::setcolor(ColorP c) { textcolor = c; } @@ -336,7 +641,7 @@ int mogltk::font::singletextsize(const String & s) const { int r = 0; for (i = 0; i < s.strlen(); i++) { - r += sizes[findchar(s[i])]; + r += sizes[findchar(s[i])] + wspace; } return r; diff --git a/lib/glbase.cc b/lib/glbase.cc index ebbfe08..3d89644 100644 --- a/lib/glbase.cc +++ b/lib/glbase.cc @@ -16,7 +16,7 @@ mogltk::glbase::glbase(int w, int h, int flags) throw (GeneralException) : moglt throw GeneralException(String("Couldn't initialise Video SubSystem: ") + SDL_GetError()); } - if (!(surface = SDL_SetVideoMode(w, h, 0, flags | SDL_OPENGL))) { + if (!(surface = SDL_SetVideoMode(w, h, 0, flags | SDL_OPENGL | SDL_HWSURFACE))) { throw GeneralException(String("Couldn't set GL mode: ") + SDL_GetError()); } diff --git a/lib/glsprite.cc b/lib/glsprite.cc index f60c3a2..44322b7 100644 --- a/lib/glsprite.cc +++ b/lib/glsprite.cc @@ -61,12 +61,12 @@ void mogltk::glSprite::drawrotate(int cx, int cy, double a, ColorP c) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); - glRotated(a, 0, 0, 1); glTranslated(cx, cy, 0); - - glMatrixMode(GL_TEXTURE); glRotated(a, 0, 0, 1); +// glMatrixMode(GL_TEXTURE); +// glRotated(a, 0, 0, 1); + c.Bind(); Bind(); diff --git a/lib/sprite.cc b/lib/sprite.cc index e62fb1b..13c09da 100644 --- a/lib/sprite.cc +++ b/lib/sprite.cc @@ -3,14 +3,14 @@ #include "base.h" #include "sprite.h" -#define TEXSIZE 256 +#define TEXSIZE 1024 mogltk::Sprite::TexList * mogltk::Sprite::TexList::header = 0; -mogltk::Sprite::Sprite(Handle * h, int asx, int asy) : sx(asx), sy(asy) { +mogltk::Sprite::Sprite(Handle * h, int asx, int asy) throw (GeneralException) : sx(asx), sy(asy) { alloc(); for (int y = 0; y < sy; y++) { - h->read(tlist->GetTex()->GetPixels() + TEXSIZE * y + posx, sx * 4); + h->read(tlist->GetTex()->GetPixels() + TEXSIZE * y + posx, sx * 4); } } diff --git a/lib/texture.cc b/lib/texture.cc index d7cfa7c..a8036bc 100644 --- a/lib/texture.cc +++ b/lib/texture.cc @@ -11,10 +11,8 @@ #define DEBUG 1 -#ifdef TRACE_TEXTURES mogltk::texture * mogltk::texture::header = 0; mogltk::texture * mogltk::texture::footer = 0; -#endif mogltk::texture * mogltk::texture::active = 0; @@ -41,7 +39,6 @@ mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : wi SDL_FillRect(surface, 0, 0); -#ifdef TRACE_TEXTURES next = 0; prev = footer; footer = this; @@ -51,7 +48,6 @@ mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : wi if (prev) { prev->next = this; } -#endif } mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) : @@ -107,7 +103,6 @@ mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) : SDL_FreeSurface(temp); -#ifdef TRACE_TEXTURES next = 0; prev = footer; footer = this; @@ -117,7 +112,6 @@ mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) : if (prev) { prev->next = this; } -#endif } mogltk::texture::~texture() { @@ -129,7 +123,6 @@ mogltk::texture::~texture() { glDeleteTextures(1, &tex); } -#ifdef TRACE_TEXTURES if (prev) { prev->next = next; } @@ -145,7 +138,6 @@ mogltk::texture::~texture() { if (this == header) { header = next; } -#endif } Uint32 * mogltk::texture::GetPixels() { @@ -215,7 +207,6 @@ void mogltk::texture::Bind(bool expand) { active = this; -#ifdef TRACE_TEXTURES if (header == this) return; @@ -231,9 +222,10 @@ void mogltk::texture::Bind(bool expand) { footer = prev; } + next = header; + prev = 0; header->prev = this; header = this; -#endif } GLuint mogltk::texture::GetWidth() { @@ -256,6 +248,17 @@ void mogltk::texture::Taint(void) { tainted = true; } +void mogltk::texture::Taintall(void) { + if (header) + header->recTaint(); +} + +void mogltk::texture::recTaint(void) { + Taint(); + if (next) + next->recTaint(); +} + #ifdef WORDS_BIGENDIAN #define NTEX_SIGNATURE 0x4e544558 #else diff --git a/lib/widgets.cc b/lib/widgets.cc index 1f540f2..91e5904 100644 --- a/lib/widgets.cc +++ b/lib/widgets.cc @@ -113,10 +113,11 @@ mogltk::shape * mogltk::widget::Shaper() { } void mogltk::widget::fulldraw() { - bool was2D; + bool was2D = true; - if (!(was2D = mogltk::engine::glbase_o->is2D())) - mogltk::engine::glbase_o->Enter2DMode(); + if (mogltk::engine::glbase_o) + if (!(was2D = mogltk::engine::glbase_o->is2D())) + mogltk::engine::glbase_o->Enter2DMode(); texture::Unbind(); mogltk::ColorP::Max = WHITE; @@ -165,7 +166,7 @@ void mogltk::Root::draw() { if (dr) dr->draw(this); else - Shaper()->box(GetAX(), GetAY(), GetAX2(), GetAY2());
+ Shaper()->box(GetAX(), GetAY(), GetAX2(), GetAY2()); } void mogltk::Root::setdrawer(drawer * _dr) { diff --git a/src/test.cc b/src/test.cc index 16f6ed4..6884790 100644 --- a/src/test.cc +++ b/src/test.cc @@ -28,13 +28,26 @@ #include "glshape.h" #include "glwidgets.h" +class keyhandler_t : public mogltk::engine::keyevent { + virtual void down(SDL_keysym keysym) { + if (keysym.sym == SDLK_ESCAPE) + mogltk::engine::quit(); + if ((keysym.sym == SDLK_RETURN) && (keysym.mod & KMOD_ALT)) + mogltk::engine::base_o->ToggleFullscreen(); + } + virtual void up(SDL_keysym keysym) { + } +} keyhandler; + +#if 1 + #define SPIN .50 #define TILT .20 -#define NBSTARS 10000 +#define NBSTARS 300 #define STARSRATE 300.0 -#define LUA +#define SPHERE int zoom = 1; @@ -304,13 +317,13 @@ void checkluastack(lua_State * L) { break; case LUA_TTABLE: printm(M_INFO, String(i) + ": (Table) Exploring:\n"); - lua_pushnil(L); /* first key */
- j = 0;
- while (lua_next(L, -2) != 0) {
- /* `key' is at index -2 and `value' at index -1 */
- printm(M_INFO, " %s - %s\n", lua_typename(L, lua_type(L, -2)),
- lua_typename(L, lua_type(L, -1)));
- lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */
+ lua_pushnil(L); /* first key */ + j = 0; + while (lua_next(L, -2) != 0) { + /* `key' is at index -2 and `value' at index -1 */ + printm(M_INFO, " %s - %s\n", lua_typename(L, lua_type(L, -2)), + lua_typename(L, lua_type(L, -1))); + lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */ } t = ""; break; @@ -514,64 +527,37 @@ virtual int startup() throw (GeneralException) { verbosity = M_INFO; String str; - Buffer * b = new Buffer(true); - (*b) << "Blah! (1)\n"; - (*b) << "Blah! (2)\n"; - (*b) << "Blah! (3)\n"; - - (*b) >> str; - printm(M_INFO, "Read `" + str + "'\n"); - - (*b) << "Blah! (4)\n"; - - (*b) >> str; - printm(M_INFO, "Read `" + str + "'\n"); - (*b) >> str; - printm(M_INFO, "Read `" + str + "'\n"); - (*b) >> str; - printm(M_INFO, "Read `" + str + "'\n"); - - (*b)[10000] = 32; - - printm(M_INFO, "Size = %i\n", b->GetSize()); - - b->seek(10000); - printm(M_INFO, "Read %i\n", b->readU8()); + mogltk::engine::setmouseZ(50); +#if 0 Lua * l = new Lua(); LuaInput::pushconstruct(l); LuaOutput::pushconstruct(l); LuaBuffer::pushconstruct(l); l->open_math(); l->declarefunc("print", myprint); -#if 1 +#if 0 l->load(&Input("particules.lua"), false); l->dump(&Output("particules.out")); l->call(); #else l->load(&Input("particules.out")); #endif - l->call("testing"); +// l->call("testing"); delete l; - +#endif + new Archive("datas.paq"); // bdlload("cl.bdl"); - Input * t1; - Output * t2; - - t1 = new Input("font.bin"); - t2 = new Output("dump/font.bin"); - copy(t1, t2); - delete(t1); - delete(t2); - #if 1 mogltk::base * gl = new mogltk::glbase(); mogltk::shape * sh = new mogltk::glshape(); mogltk::font * font = new mogltk::glfont(&Input("font-2.bin")); - mogltk::Sprite * s = new mogltk::glSprite(&Input("cursor.rgba"), 25, 25); + mogltk::glSprite * s = new mogltk::glSprite(&Input("cursor.rgba"), 25, 25); mogltk::Sprite * p = new mogltk::glSprite(&Input("particule.rgba"), 16, 16); +// mogltk::glSprite * spr = new mogltk::glSprite(&Input("015_Over-Mind.raw"), 347, 328); + mogltk::glSprite * spr = new mogltk::glSprite(&Input("test.raw"), 200, 200); mogltk::widget * w = new mogltk::Root(sh); #else mogltk::base * gl = new mogltk::base(); @@ -579,77 +565,106 @@ virtual int startup() throw (GeneralException) { mogltk::font * font = new mogltk::font(&Input("font-2.bin")); mogltk::Sprite * s = new mogltk::Sprite(&Input("cursor.rgba"), 25, 25); mogltk::Sprite * p = new mogltk::Sprite(&Input("particule.rgba"), 16, 16); + mogltk::Sprite * spr = new mogltk::Sprite(&Input("015_Over-Mind.raw"), 347, 328); mogltk::widget * w = new mogltk::Root(sh); #endif +#if 1 + font->setcolor(WHITE); + font->setshadow(1); + mogltk::rect textrect; + mogltk::texture * text = font->printtex(&textrect, + "PixelPawa!\n" + "It works!!\n" + "I can't believe it!\n" + ); + SDL_SaveBMP(text->GetSurface(), "test-font.bmp"); + textrect.x = 10; + textrect.y = 30; +#endif + mogltk::engine::setcursorvisible(true); mogltk::engine::setappactive(true); + + mogltk::engine::setkeyevent(&keyhandler); mogltk::texture * mytex = new mogltk::texture(&Input("pattern6.tex"), true); Color AlphaBlue(AQUA); AlphaBlue.A = 50; -// mogltk::fill * f = sh->fcircle(320, 240, 50); + mogltk::fill * f = sh->fcircle(320, 240, 50); initstars(); while (!mogltk::engine::quitrequested()) { -// sx1 = 320 + 320 * sin(0.983 * t + 3.15); -// sx2 = 320 + 320 * sin(0.537 * t + 5.32); -// sy1 = 240 + 240 * sin(0.692 * t + 8.21); -// sy2 = 240 + 240 * sin(1.029 * t + 2.42); + sx1 = 320 + 320 * sin(0.983 * t + 3.15); + sx2 = 320 + 320 * sin(0.537 * t + 5.32); + sy1 = 240 + 240 * sin(0.692 * t + 8.21); + sy2 = 240 + 240 * sin(1.029 * t + 2.42); gl->Enter2DMode(); w->fulldraw(); -/* sh->tbox(mytex, 50, 50, 561, 561, BLACK, RED, LIME, BLUE); */ -// sh->box(400, 100, 450, 150, BLACK, RED, LIME, BLUE); - -// sh->box(5, 5, 150, 80, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); -/* mogltk::ColorP::Max.A = 100; - sh->box(5, 5, 400, 300, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); - mogltk::ColorP::Max.A = 255; */ -// font->setshadow(1); -// font->putcursor(10, 30); -// font->setcolor(WHITE); -// font->printf( -// "PixelPawa!\n" -// "It works!!\n" -// "I can't believe it!\n" -// ); + sh->tbox(mytex, 50, 50, 561, 561, BLACK, RED, LIME, BLUE); + //sh->box(400, 100, 450, 150, BLACK, RED, LIME, BLUE); + + sh->box(5, 5, 150, 80, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); + mogltk::ColorP::Max.A = 100; + //sh->box(5, 5, 400, 300, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); + mogltk::ColorP::Max.A = 255; +#if 1 + font->setshadow(1); + font->putcursor(10, 30); + mogltk::ColorP::Max.A = sy1 / 2; + font->setcolor(Color(sy1 / 2, sy1 / 2, sy1 / 2, sy1 / 2)); + font->printf( + "PixelPawa!\n" + "It works!!\n" + "I can't believe it!\n" + ); + mogltk::ColorP::Max.A = 255; + font->setcolor(WHITE); +#else + sh->tbox(text, textrect.x, textrect.y, textrect.x + textrect.w, textrect.y + textrect.h); +#endif -// sh->box3d(50, 150, 150, 200); -// sh->obox3d(50, 250, 150, 300); -// sh->window(50, 350, 150, 400, "Titre plus beau ;)"); -// sh->box3d(180, 130, 320, 220); -// sh->button(200, 150, 300, 200, "Bouton"); - -// sh->fdraw(f, BLUE); -// sh->sdraw(f); + sh->box3d(50, 150, 150, 200); + sh->obox3d(50, 250, 150, 300); + sh->window(50, 350, 150, 400, "Titre plus beau ;)"); + sh->box3d(180, 130, 320, 220); + sh->button(200, 150, 300, 200, "Bouton"); + + sh->fdraw(f, BLUE); + sh->sdraw(f); + + spr->drawrotate(500, 400, sx1); -// sh->box(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); -// mogltk::ColorP::Min.A = 200; -// sh->obox(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); -// mogltk::ColorP::Min.A = 0; + sh->box(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); + mogltk::ColorP::Min.A = 200; + sh->obox(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); + mogltk::ColorP::Min.A = 0; + + p->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 8); + sh->line(320, 240, mogltk::engine::mouseX(), mogltk::engine::mouseY()); + + mogltk::ColorP::Min.A = 200; + p->draw(sx1 - 8, sy1 - 8, AlphaBlue); + p->draw(sx2 - 8, sy2 - 8, AlphaBlue); + + displaystars(p); + incrementstars(t); font->putcursor(550, 400); font->printf("FPS: %.2f\n", mogltk::engine::FPS()); font->printf("mx: %i\n", mogltk::engine::mouseX()); font->printf("my: %i\n", mogltk::engine::mouseY()); font->printf("t: %.2fs\n", SDL_GetTicks() / 1000.0); - -/* p->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 8); */ + mogltk::ColorP::Max.A = 50; + s->draw(mogltk::engine::mouseX() - 6, mogltk::engine::mouseY() - 3, BLACK); + mogltk::ColorP::Max.A = 255; s->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 6); -// sh->line(320, 240, mogltk::engine::mouseX(), mogltk::engine::mouseY()); - -/* mogltk::ColorP::Min.A = 200; */ -// p->draw(sx1, sy1, AlphaBlue); -// p->draw(sx2, sy2, AlphaBlue); - - displaystars(p); - incrementstars(t); gl->Leave2DMode(); @@ -662,3 +677,61 @@ virtual int startup() throw (GeneralException) { return 0; } CODE_ENDS + +#else + +CODE_BEGINS +virtual int startup() throw (GeneralException) { + unsigned char palette[256][3], * pixels, c; + char outname[256]; + int width, height, x, y; + + if (argc != 2) + exit(-1); + Input i(argv[1]); + SDL_Init(SDL_INIT_VIDEO); + atexit(SDL_Quit); + width = i.readU16(); + height = i.readU16(); + i.seek(12, SEEK_CUR); + SDL_Surface * s = SDL_SetVideoMode(width, height, 24, 0); + pixels = (unsigned char *) s->pixels; + for (x = 0; x < 256; x++) { + for (y = 0; y < 3; y++) { + palette[x][y] = i.readU8(); + } + i.seek(1, SEEK_CUR); + } + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + c = i.readU8(); + pixels[(y * width + x) * 3 + 0] = palette[c][2]; + pixels[(y * width + x) * 3 + 1] = palette[c][1]; + pixels[(y * width + x) * 3 + 2] = palette[c][0]; + } + } + + *strchr(argv[1], '.') = 0; + + sprintf(outname, "%s.bmp", argv[1]); + + SDL_SaveBMP(s, outname); + + SDL_Flip(s); + + SDL_Event event; + + while(true) { + SDL_PollEvent(&event); + switch (event.type) { + case SDL_QUIT: + exit(0); + } + } + + return 0; +} +CODE_ENDS + + +#endif
\ No newline at end of file |