summaryrefslogtreecommitdiff
path: root/lib/base.cc
diff options
context:
space:
mode:
authorpixel <pixel>2004-11-27 21:44:50 +0000
committerpixel <pixel>2004-11-27 21:44:50 +0000
commit1ae229afb9bff4a3636c08632032b509e1e80ec4 (patch)
tree9a78b288fcff587617d5174d8e74b7bdd6d41aa3 /lib/base.cc
parent70b1a3c1c6b7f33b3af777bedaa784e34ef81719 (diff)
Large dos2unix commit...
Diffstat (limited to 'lib/base.cc')
-rw-r--r--lib/base.cc356
1 files changed, 178 insertions, 178 deletions
diff --git a/lib/base.cc b/lib/base.cc
index d1ba7ef..61426eb 100644
--- a/lib/base.cc
+++ b/lib/base.cc
@@ -1,178 +1,178 @@
-/*
- * mogltk
- * Copyright (C) 1999-2004 Nicolas "Pixel" Noble
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/* $Id: base.cc,v 1.12 2004-07-15 14:21:31 pixel Exp $ */
-
-#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"
-
-mogltk::base::base(int w, int h, int flags) throw(GeneralException) : surface(0) {
- 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_HWSURFACE))) {
- throw GeneralException(String("Couldn't set SDL 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);
-
- SDL_ShowCursor(SDL_DISABLE);
- SDL_FillRect(surface, NULL, 0);
- SDL_Flip(surface);
- SDL_FillRect(surface, NULL, 0);
- mogltk::engine::postsetup();
-}
-
-mogltk::base::~base() {
-}
-
-int mogltk::base::GetWidth(void) {
- return width;
-}
-
-int mogltk::base::GetHeight(void) {
- return height;
-}
-
-void mogltk::base::Flip(bool clear) {
- mogltk::engine::pollevents();
- SDL_Flip(surface);
- if (clear)
- SDL_FillRect(surface, NULL, 0);
-}
-
-mogltk::base::base(int w, int h, int flags, int) : surface(0) {
- width = w;
- height = h;
-
- SDL_ShowCursor(SDL_DISABLE);
-}
-
-void mogltk::base::setsurface(SDL_Surface * _surface) throw (GeneralException) {
- if (surface)
- throw GeneralException("Can't set video surface twice");
- surface = _surface;
-}
-
-SDL_Surface * mogltk::base::getsurface() {
- return surface;
-}
-
-void mogltk::base::Enter2DMode() {
-}
-
-void mogltk::base::Leave2DMode() {
-}
-
-bool mogltk::base::is2D() {
- return true;
-}
-
-void mogltk::base::changeviewport(int x, int y, unsigned int w, unsigned int h) {
- SDL_Rect r;
-
- if ((w == 0) && (h == 0)) {
- w = GetWidth() - x;
- h = GetHeight() - y;
- }
-
- r.x = x;
- r.y = y;
- r.w = w;
- r.h = h;
-
- SDL_SetClipRect(surface, &r);
-}
-
-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);
-}
-
-inline static 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::base::GrabTexture() {
- int w = nextpower(GetWidth());
- int h = nextpower(GetHeight());
- texture * r = new texture(w, h);
-
- SDL_BlitSurface(getsurface(), NULL, r->GetSurface(), NULL);
-
- return r;
-}
-
-SDL_Surface * mogltk::base::GrabSurface() {
- SDL_Surface * r = SDL_CreateRGBSurface(SDL_SWSURFACE, GetWidth(), GetHeight(), 24,
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- 0xff000000,
- 0x00ff0000,
- 0x0000ff00,
- 0x00000000
-#else
- 0x000000ff,
- 0x0000ff00,
- 0x00ff0000,
- 0x00000000
-#endif
- );
-
- SDL_BlitSurface(getsurface(), NULL, r, NULL);
-
- return r;
-}
+/*
+ * mogltk
+ * Copyright (C) 1999-2004 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: base.cc,v 1.13 2004-11-27 21:44:52 pixel Exp $ */
+
+#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"
+
+mogltk::base::base(int w, int h, int flags) throw(GeneralException) : surface(0) {
+ 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_HWSURFACE))) {
+ throw GeneralException(String("Couldn't set SDL 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);
+
+ SDL_ShowCursor(SDL_DISABLE);
+ SDL_FillRect(surface, NULL, 0);
+ SDL_Flip(surface);
+ SDL_FillRect(surface, NULL, 0);
+ mogltk::engine::postsetup();
+}
+
+mogltk::base::~base() {
+}
+
+int mogltk::base::GetWidth(void) {
+ return width;
+}
+
+int mogltk::base::GetHeight(void) {
+ return height;
+}
+
+void mogltk::base::Flip(bool clear) {
+ mogltk::engine::pollevents();
+ SDL_Flip(surface);
+ if (clear)
+ SDL_FillRect(surface, NULL, 0);
+}
+
+mogltk::base::base(int w, int h, int flags, int) : surface(0) {
+ width = w;
+ height = h;
+
+ SDL_ShowCursor(SDL_DISABLE);
+}
+
+void mogltk::base::setsurface(SDL_Surface * _surface) throw (GeneralException) {
+ if (surface)
+ throw GeneralException("Can't set video surface twice");
+ surface = _surface;
+}
+
+SDL_Surface * mogltk::base::getsurface() {
+ return surface;
+}
+
+void mogltk::base::Enter2DMode() {
+}
+
+void mogltk::base::Leave2DMode() {
+}
+
+bool mogltk::base::is2D() {
+ return true;
+}
+
+void mogltk::base::changeviewport(int x, int y, unsigned int w, unsigned int h) {
+ SDL_Rect r;
+
+ if ((w == 0) && (h == 0)) {
+ w = GetWidth() - x;
+ h = GetHeight() - y;
+ }
+
+ r.x = x;
+ r.y = y;
+ r.w = w;
+ r.h = h;
+
+ SDL_SetClipRect(surface, &r);
+}
+
+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);
+}
+
+inline static 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::base::GrabTexture() {
+ int w = nextpower(GetWidth());
+ int h = nextpower(GetHeight());
+ texture * r = new texture(w, h);
+
+ SDL_BlitSurface(getsurface(), NULL, r->GetSurface(), NULL);
+
+ return r;
+}
+
+SDL_Surface * mogltk::base::GrabSurface() {
+ SDL_Surface * r = SDL_CreateRGBSurface(SDL_SWSURFACE, GetWidth(), GetHeight(), 24,
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ 0xff000000,
+ 0x00ff0000,
+ 0x0000ff00,
+ 0x00000000
+#else
+ 0x000000ff,
+ 0x0000ff00,
+ 0x00ff0000,
+ 0x00000000
+#endif
+ );
+
+ SDL_BlitSurface(getsurface(), NULL, r, NULL);
+
+ return r;
+}