#include <X11/extensions/xf86vmode.h>
#endif
#endif
-#include <msp/core/except.h>
#include <msp/strings/format.h>
#include <msp/strings/lexicalcast.h>
#include "display.h"
namespace Msp {
namespace Graphics {
+unsupported_video_mode::unsupported_video_mode(const VideoMode &mode):
+ runtime_error(format("%dx%d", mode.width, mode.height))
+{ }
+
+
Display::Display(const string &disp_name):
priv(new Private)
{
else
priv->display = XOpenDisplay(disp_name.c_str());
if(!priv->display)
- throw Exception("Couldn't open X display");
+ throw runtime_error("XOpenDisplay");
XSetErrorHandler(x_error_handler);
info.dmDisplayFrequency = mode.rate;
}
- ChangeDisplaySettings(&info, CDS_FULLSCREEN);
+ LONG ret = ChangeDisplaySettings(&info, CDS_FULLSCREEN);
+ if(ret!=DISP_CHANGE_SUCCESSFUL)
+ throw unsupported_video_mode(mode);
#elif defined(WITH_XF86VIDMODE)
int screen = DefaultScreen(priv->display);
}
}
- throw InvalidParameterValue("Requested mode not supported");
+ throw unsupported_video_mode(mode);
#else
(void)mode;
- throw Exception("Video mode switching not supported");
+ throw runtime_error("no xf86vidmode support");
#endif
}
if(error_flag)
{
error_flag = false;
- throw Exception(error_msg);
+ throw runtime_error(error_msg);
}
}
#include <list>
#include <map>
+#include <stdexcept>
#include <string>
namespace Msp {
VideoMode(unsigned w, unsigned h): width(w), height(h), rate(0) { }
};
+
+class unsupported_video_mode: public std::runtime_error
+{
+public:
+ unsupported_video_mode(const VideoMode &);
+ virtual ~unsupported_video_mode() throw () { }
+};
+
+
class Display
{
public:
+#include <stdexcept>
#ifndef WIN32
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/extensions/XShm.h>
#include <X11/Xutil.h>
#endif
-#include <msp/core/except.h>
#include "display.h"
#include "drawcontext.h"
#include "window.h"
#include "display_priv.h"
+using namespace std;
+
namespace Msp {
namespace Graphics {
window(w)
{
#ifdef WIN32
- throw Exception("DrawContext not supported on win32 yet");
+ throw runtime_error("no DrawContext support on windows");
#else
priv = new Private;
{
priv->image = XShmCreateImage(dpy, wa.visual, wa.depth, ZPixmap, 0, &priv->shminfo, wa.width, wa.height);
if(!priv->image)
- throw Exception("Could not create shared memory XImage");
+ throw runtime_error("XShmCreateImage");
priv->shminfo.shmid = shmget(IPC_PRIVATE, priv->image->bytes_per_line*priv->image->height, IPC_CREAT|0666);
priv->shminfo.shmaddr=priv->image->data = reinterpret_cast<char *>(shmat(priv->shminfo.shmid, 0, 0));
{
priv->image = XCreateImage(dpy, wa.visual, wa.depth, ZPixmap, 0, 0, wa.width, wa.height, 8, 0);
if(!priv->image)
- throw Exception("Could not create XImage");
+ throw runtime_error("XCreateImage");
priv->image->data = new char[priv->image->bytes_per_line*priv->image->height];
}
#endif
#endif
#endif
#include <msp/core/application.h>
-#include <msp/core/except.h>
+#include <msp/strings/format.h>
#include "display.h"
#include "glcontext.h"
#include "window.h"
{ }
+unsupported_gl_mode::unsupported_gl_mode(const GLOptions &opts):
+ runtime_error(format("{ .alpha=%s, .stencil=%s, .doublebuffer=%s, .multisample=%d }",
+ opts.alpha, opts.stencil, opts.doublebuffer, opts.multisample))
+{ }
+
+
#ifdef WITH_OPENGL
#ifdef WIN32
typedef HGLRC Context;
int pf_index = ChoosePixelFormat(dc, &pfd);
if(!pf_index)
- throw Exception("Couldn't find a suitable pixel format");
+ throw unsupported_gl_mode(opts);
SetPixelFormat(dc, pf_index, &pfd);
priv->context = wglCreateContext(dc);
XVisualInfo *vi = glXChooseVisual(dpy, DefaultScreen(dpy), &attribs.front());
if(!vi)
- throw Exception("Couldn't find a suitable GLX visual");
+ throw unsupported_gl_mode(opts);
priv->context = glXCreateContext(dpy, vi, 0, true);
XSetWindowAttributes attr;
#else
(void)wnd;
(void)opts;
- throw Exception("OpenGL support not compiled in");
+ throw runtime_error("no OpenGL support");
#endif
window.signal_resize.connect(sigc::mem_fun(this, &GLContext::window_resized));
#ifndef MSP_GBASE_GLCONTEXT_H_
#define MSP_GBASE_GLCONTEXT_H_
+#include <stdexcept>
+
namespace Msp {
namespace Graphics {
GLOptions();
};
+
+class unsupported_gl_mode: public std::runtime_error
+{
+public:
+ unsupported_gl_mode(const GLOptions &);
+ virtual ~unsupported_gl_mode() throw () { }
+};
+
+
class GLContext
{
private:
#include <msp/io/file.h>
#include <msp/io/memory.h>
#endif
-#include <msp/core/except.h>
#include "image.h"
using namespace std;
info = png_create_info_struct(png);
if(setjmp(png_jmpbuf(png)))
- throw Exception("Error loading PNG image");
+ throw bad_image_data("PNG error");
png_set_read_fn(png, &in, read);
png_read_info(png, info);
priv.width = width;
priv.height = height;
if(depth!=8)
- throw Exception("Only 8-bit PNG images are supported");
+ throw unsupported_image_format("depth!=8");
switch(color)
{
case PNG_COLOR_TYPE_PALETTE: priv.fmt = COLOR_INDEX; break;
case PNG_COLOR_TYPE_GRAY_ALPHA: priv.fmt = LUMINANCE_ALPHA; break;
case PNG_COLOR_TYPE_RGB: priv.fmt = RGB; break;
case PNG_COLOR_TYPE_RGB_ALPHA: priv.fmt = RGBA; break;
- default: throw Exception("Unknown color type");
+ default: throw unsupported_image_format("unknown color type");
}
unsigned nchans = png_get_channels(png, info);
priv(new Private)
{
#if !defined(WITH_DEVIL) && !defined(WITH_LIBPNG)
- throw Exception("Image needs either DevIL or libpng support");
+ throw runtime_error("no image support");
#endif
}
ensure_devil_image(priv->id);
ilBindImage(priv->id);
if(!ilLoadImage(const_cast<char *>(fn.c_str())))
- throw Exception("Error loading image "+fn);
+ throw bad_image_data("IL error");
#else
- throw Exception("Not a PNG image and DevIL support not compiled in");
+ throw unsupported_image_format("DevIL needed for non-PNG images");
#endif
}
(void)fn;
ensure_devil_image(priv->id);
ilBindImage(priv->id);
if(!ilLoadL(IL_TYPE_UNKNOWN, const_cast<void *>(data), size))
- throw Exception("Error loading image from memory");
+ throw bad_image_data("IL error");
#else
- throw Exception("Not a PNG image and DevIL support not compiled in");
+ throw unsupported_image_format("DevIL needed for non-PNG images");
#endif
}
(void)data;
case IL_RGBA: return RGBA;
case IL_BGR: return BGR;
case IL_BGRA: return BGRA;
- default: throw InvalidParameterValue("Unknown pixel format in image");
+ // XXX bad, should throw when loading
+ default: throw invalid_argument("unknown pixel format in image");
}
}
#endif
namespace Msp {
namespace Graphics {
+class unsupported_image_format: public std::runtime_error
+{
+public:
+ unsupported_image_format(const std::string &w): std::runtime_error(w) { }
+ virtual ~unsupported_image_format() throw() { }
+};
+
+class bad_image_data: public std::runtime_error
+{
+public:
+ bad_image_data(const std::string &w): std::runtime_error(w) { }
+ virtual ~bad_image_data() throw() { }
+};
+
+
class Image
{
public:
#include <windowsx.h>
#endif
#include <msp/core/application.h>
-#include <msp/core/except.h>
#include "display.h"
#include "window.h"
#include "display_priv.h"
wndcl.hIconSm = 0;
if(!RegisterClassEx(&wndcl))
- throw Exception("Couldn't register window class");
+ throw system_error("RegisterClassEx");
wndclass_created = true;
}
reinterpret_cast<HINSTANCE>(Application::get_data()),
this);
if(!priv->window)
- throw Exception("CreateWindowEx failed");
+ throw system_error("CreateWindowEx");
#else
::Display *dpy = display.get_private().display;
-#include <msp/core/except.h>
#include <msp/strings/lexicalcast.h>
#include "control.h"
#include "device.h"
case AXIS_NEG:
src.dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion));
break;
- default:
- throw Exception("Invalid source in Control");
}
}
+#include <stdexcept>
#include <sigc++/bind.h>
-#include <msp/core/except.h>
#include "hub.h"
+using namespace std;
+
namespace Msp {
namespace Input {
{
unsigned dev_index = btn>>12;
if(dev_index>=devices.size())
- throw InvalidParameterValue("Button does not exist");
+ throw invalid_argument("Hub::get_button_name");
const Device &dev = *devices[dev_index];
return dev.get_name()+": "+dev.get_button_name(btn&0xFFF);
{
unsigned dev_index = axis>>12;
if(dev_index>=devices.size())
- throw InvalidParameterValue("Axis does not exist");
+ throw invalid_argument("Hub::get_axis_name");
const Device &dev = *devices[dev_index];
return dev.get_name()+": "+dev.get_axis_name(axis&0xFFF);
#include <map>
+#include <stdexcept>
#ifdef WIN32
#include <windows.h>
#else
#include <X11/X.h>
#include <X11/keysym.h>
#endif
-#include <msp/core/except.h>
#include "keys.h"
using namespace std;
unsigned key_to_sys(unsigned key)
{
if(key>=N_KEYS_)
- throw InvalidParameterValue("Key out of range");
+ throw invalid_argument("key_to_sys");
return keymap[key];
}