};
};
+ feature "devil" "Include DevIL support for loading image files";
+ if "with_devil"
+ {
+ require "devil";
+ };
+
headers "gbase"
{
source "source/gbase";
--- /dev/null
+/* $Id$
+
+This file is part of libmspgbase
+Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifdef WITH_DEVIL
+#include <IL/il.h>
+#endif
+#include <msp/core/except.h>
+#include "image.h"
+
+using namespace std;
+
+namespace Msp {
+namespace Graphics {
+
+Image::Image()
+{
+#ifdef WITH_DEVIL
+ static bool init_done=false;
+
+ if(!init_done)
+ {
+ ilInit();
+ ilEnable(IL_ORIGIN_SET);
+ ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
+ init_done=true;
+ }
+
+ ilGenImages(1, &id);
+#else
+ throw Exception("DevIL support not compiled in");
+#endif
+}
+
+Image::~Image()
+{
+#ifdef WITH_DEVIL
+ ilDeleteImages(1, &id);
+#endif
+}
+
+void Image::load_file(const string &fn)
+{
+#ifdef WITH_DEVIL
+ ilBindImage(id);
+ if(!ilLoadImage(const_cast<char *>(fn.c_str())))
+ throw Exception("Error loading image "+fn);
+#else
+ (void)fn;
+#endif
+}
+
+void Image::load_memory(const void *data, unsigned size)
+{
+#ifdef WITH_DEVIL
+ ilBindImage(id);
+ if(!ilLoadL(IL_TYPE_UNKNOWN, const_cast<void *>(data), size))
+ throw Exception("Error loading image from lump");
+#else
+ (void)data; (void)size;
+#endif
+}
+
+PixelFormat Image::get_format() const
+{
+#ifdef WITH_DEVIL
+ switch(ilGetInteger(IL_IMAGE_FORMAT))
+ {
+ case IL_COLOR_INDEX: return COLOR_INDEX;
+ case IL_LUMINANCE: return LUMINANCE;
+ case IL_LUMINANCE_ALPHA: return LUMINANCE_ALPHA;
+ case IL_RGB: return RGB;
+ case IL_RGBA: return RGBA;
+ case IL_BGR: return BGR;
+ case IL_BGRA: return BGRA;
+ default: throw InvalidParameterValue("Unknown pixel format in image");
+ }
+#else
+ return RGB;
+#endif
+}
+
+unsigned Image::get_width() const
+{
+#ifdef WITH_DEVIL
+ return ilGetInteger(IL_IMAGE_WIDTH);
+#else
+ return 0;
+#endif
+}
+
+unsigned Image::get_height() const
+{
+#ifdef WITH_DEVIL
+ return ilGetInteger(IL_IMAGE_HEIGHT);
+#else
+ return 0;
+#endif
+}
+
+const void *Image::get_data() const
+{
+#ifdef WITH_DEVIL
+ return ilGetData();
+#else
+ return 0;
+#endif
+}
+
+} // namespace Graphics
+} // namespace Msp
--- /dev/null
+/* $Id$
+
+This file is part of libmspgbase
+Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef MSP_GBASE_IMAGE_H_
+#define MSP_GBASE_IMAGE_H_
+
+#include <string>
+#include "pixelformat.h"
+
+namespace Msp {
+namespace Graphics {
+
+class Image
+{
+private:
+ unsigned id;
+
+public:
+ Image();
+ ~Image();
+
+ void load_file(const std::string &);
+ void load_memory(const void *, unsigned);
+ PixelFormat get_format() const;
+ unsigned get_width() const;
+ unsigned get_height() const;
+ const void *get_data() const;
+};
+
+} // namespace Graphics
+} // namespace Msp
+
+#endif
--- /dev/null
+/* $Id$
+
+This file is part of libmspgl
+Copyright © 2008 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef MSP_GBASE_PIXELFORMAT_H_
+#define MSP_GBASE_PIXELFORMAT_H_
+
+namespace Msp {
+namespace Graphics {
+
+enum PixelFormat
+{
+ COLOR_INDEX,
+ LUMINANCE,
+ LUMINANCE_ALPHA,
+ RGB,
+ RGBA,
+ BGR,
+ BGRA
+};
+
+} // namespace Graphics
+} // namespace Msp
+
+#endif
CloseWindow(window);
#else
XDestroyWindow(display.get_display(), window);
+
+ if(invisible_cursor)
+ XFreeCursor(display.get_display(), invisible_cursor);
#endif
display.remove_window(this);
display.restore_mode();
}
+void Window::show_cursor(bool s)
+{
+#ifdef WIN32
+ ShowCursor(s);
+#else
+ ::Display *dpy=display.get_display();
+
+ if(s)
+ XUndefineCursor(dpy, window);
+ else
+ {
+ if(!invisible_cursor)
+ {
+ int screen=DefaultScreen(dpy);
+ char data=0;
+ XImage *img=XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap, 0, &data, 1, 1, 8, 1);
+
+ Pixmap pm=XCreatePixmap(dpy, window, 1, 1, 1);
+ GC gc=XCreateGC(dpy, pm, 0, 0);
+ XPutImage(dpy, pm, gc, img, 0, 0, 0, 0, 1, 1);
+
+ XColor black;
+ black.pixel=BlackPixel(dpy, screen);
+ XQueryColor(dpy, DefaultColormap(dpy, screen), &black);
+
+ invisible_cursor=XCreatePixmapCursor(dpy, pm, pm, &black, &black, 0, 0);
+
+ XFreeGC(dpy, gc);
+ XFreePixmap(dpy, pm);
+ img->data=0;
+ XDestroyImage(img);
+ }
+ XDefineCursor(dpy, window, invisible_cursor);
+ }
+#endif
+}
+
void Window::show()
{
#ifdef WIN32
::Display *dpy=display.get_display();
wm_delete_window=XInternAtom(dpy, "WM_DELETE_WINDOW", true);
+ invisible_cursor=0;
XSetWindowAttributes attr;
attr.override_redirect=options.fullscreen;
WindowHandle window;
#ifndef WIN32
Atom wm_delete_window;
+ Cursor invisible_cursor;
#endif
public:
void set_title(const std::string &);
void reconfigure(const WindowOptions &);
+ void show_cursor(bool);
Display &get_display() const { return display; }
const WindowOptions &get_options() const { return options; }