#include <stdexcept>
+#include <SDL/SDL_image.h>
+
#include "Dispatcher.hh"
-#include "Serializable.hh"
+#include "Log.hh"
#include "Settings.hh"
#include "Video.hh"
Video::Video()
{
- std::string caption;
- if (Settings::instance().get("video.caption", caption))
- {
- init(attribs_, caption);
- }
- else
- {
- init(attribs_, "Untitled");
- }
+ init(attribs_);
}
-Video::Video(const Attributes& attribs, const std::string& caption)
+Video::Video(const Attributes& attribs)
{
- init(attribs, caption);
+ init(attribs);
}
-Video::Video(const Attributes& attribs)
+Video::Video(const std::string& caption, const std::string& icon)
{
- std::string caption;
- if (Settings::instance().get("video.caption", caption))
+ if (attribs_.caption == "Untitled")
{
- init(attribs, caption);
+ attribs_.caption = caption;
}
- else
+ if (attribs_.icon == "")
{
- init(attribs, "Untitled");
+ attribs_.icon = icon;
}
-}
-Video::Video(const std::string& caption)
-{
- init(attribs_, caption);
+ init(attribs_);
}
-void Video::init(const Attributes& attribs, const std::string& caption)
+void Video::init(const Attributes& attribs)
{
context_ = 0;
flags_ = 0;
setFull(attribs.fullscreen);
setResizable(attribs.resizable);
setOpenGLAttributes();
- setCaption(caption);
+ setCaption(attribs.caption);
+ setIcon();
setCursorVisible(attribs.cursorVisible);
setCursorGrab(attribs.cursorGrab);
setVideoMode(attribs.mode);
SDL_FreeSurface(context_);
context_ = 0;
setVideoMode(attribs_.mode);
- Mf::Dispatcher::instance().dispatch("video.context_recreated");
}
void Video::setOpenGLAttributes()
attribs_.mode[0] = mode[0];
attribs_.mode[1] = mode[1];
attribs_.mode[2] = mode[2];
+
+#if defined(_WIN32) || defined (_WIN64) || defined(__WIN32__)
+ // on win32, creating a new context via SDL_SetVideoMode will wipe
+ // out the GL state, so we gotta notify everyone to reload their
+ // state after the change
+ Mf::dispatcher::dispatch("video.context_recreated");
+ logInfo("video context recreated");
+#endif
}
- else throw Exception(SDL_GetError());
+ else throw Exception(Exception::SDL_ERROR);
}
}
void Video::setCaption(const std::string& caption)
{
+ attribs_.caption = caption;
SDL_WM_SetCaption(caption.c_str(), 0);
}
+void Video::setIcon()
+{
+ if (attribs_.icon != "")
+ {
+ SDL_Surface* icon = IMG_Load(attribs_.icon.c_str());
+ if (icon)
+ {
+ SDL_WM_SetIcon(icon, 0);
+ SDL_FreeSurface(icon);
+ }
+ }
+}
+
std::string Video::getCaption() const
{
- char* str;
- SDL_WM_GetCaption(&str, 0);
- return std::string(str);
+ return attribs_.caption;
}
}
+int Video::getWidth() const
+{
+ return context_->w;
+}
+
+int Video::getHeight() const
+{
+ return context_->h;
+}
+
+
Video::Attributes::Attributes()
{
// Set some sane GL and window defaults (see SDL_video.c:217)
cursorVisible = true;
cursorGrab = false;
- std::vector<SerializablePtr> colors;
- Settings::instance().get("video.colorbuffers", colors);
- if (colors.size() > 0) colors[0]->get(colorBuffer[0]);
- if (colors.size() > 1) colors[1]->get(colorBuffer[1]);
- if (colors.size() > 2) colors[2]->get(colorBuffer[2]);
- if (colors.size() > 3) colors[3]->get(colorBuffer[3]);
-
- Settings::instance().get("video.framebuffer", frameBuffer);
- Settings::instance().get("video.doublebuffer", doubleBuffer);
- Settings::instance().get("video.depthbuffer", depthBuffer);
- Settings::instance().get("video.stencilbuffer", stencilBuffer);
-
- std::vector<SerializablePtr> accum;
- Settings::instance().get("video.accumbuffers", accum);
- if (accum.size() > 0) accum[0]->get(accumBuffer[0]);
- if (accum.size() > 1) accum[1]->get(accumBuffer[1]);
- if (accum.size() > 2) accum[2]->get(accumBuffer[2]);
- if (accum.size() > 3) accum[3]->get(accumBuffer[3]);
-
- Settings::instance().get("video.stereo", stereo);
- Settings::instance().get("video.multiesamplebuffers", multisampleBuffers);
- Settings::instance().get("video.multiesamplesamples", multisampleSamples);
- Settings::instance().get("video.swapcontrol", swapControl);
- Settings::instance().get("video.hardwareonly", hardwareonly);
-
- std::vector<SerializablePtr> dimensions;
- Settings::instance().get("video.mode", dimensions);
- if (dimensions.size() > 0) dimensions[0]->get(mode[0]);
- if (dimensions.size() > 1) dimensions[1]->get(mode[1]);
- if (dimensions.size() > 2) dimensions[2]->get(mode[2]);
-
- Settings::instance().get("video.fullscreen", fullscreen);
- Settings::instance().get("video.resizable", resizable);
- Settings::instance().get("video.showcursor", cursorVisible);
- Settings::instance().get("input.grab", cursorGrab);
+ Settings& settings = Settings::getInstance();
+
+ std::vector<long> colors;
+ settings.get("colorbuffers", colors);
+ if (colors.size() > 0) colorBuffer[0] = colors[0];
+ if (colors.size() > 1) colorBuffer[1] = colors[1];
+ if (colors.size() > 2) colorBuffer[2] = colors[2];
+ if (colors.size() > 3) colorBuffer[3] = colors[3];
+
+ settings.get("framebuffer", frameBuffer);
+ settings.get("doublebuffer", doubleBuffer);
+ settings.get("depthbuffer", depthBuffer);
+ settings.get("stencilbuffer", stencilBuffer);
+
+ std::vector<long> accum;
+ settings.get("accumbuffers", accum);
+ if (accum.size() > 0) accumBuffer[0] = accum[0];
+ if (accum.size() > 1) accumBuffer[1] = accum[1];
+ if (accum.size() > 2) accumBuffer[2] = accum[2];
+ if (accum.size() > 3) accumBuffer[3] = accum[3];
+
+ settings.get("stereo", stereo);
+ settings.get("multiesamplebuffers", multisampleBuffers);
+ settings.get("multiesamplesamples", multisampleSamples);
+ settings.get("swapcontrol", swapControl);
+ settings.get("hardwareonly", hardwareonly);
+
+ if (!settings.get("caption", caption))
+ {
+ caption = "Untitled";
+ }
+ settings.get("icon", icon);
+
+ std::vector<long> dimensions;
+ settings.get("videomode", dimensions);
+ if (dimensions.size() > 1)
+ {
+ mode[0] = dimensions[0];
+ mode[1] = dimensions[1];
+ }
+ if (dimensions.size() > 2) mode[2] = dimensions[2];
+
+ settings.get("fullscreen", fullscreen);
+ settings.get("resizable", resizable);
+ settings.get("showcursor", cursorVisible);
+ settings.get("grab", cursorGrab);
}