X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2FMoof%2FVideo.cc;h=8de161aa085daca5f087500869eb4067f329b34d;hb=a4debfe4a5f5d339410788971b698ba00cb7f09c;hp=c41517e51c87601ff96bd25f1c63ba3e83dcfcb1;hpb=c2321281bf12a7efaedde930422c7ddbc92080d4;p=chaz%2Fyoink diff --git a/src/Moof/Video.cc b/src/Moof/Video.cc index c41517e..8de161a 100644 --- a/src/Moof/Video.cc +++ b/src/Moof/Video.cc @@ -28,8 +28,10 @@ #include +#include + #include "Dispatcher.hh" -#include "Serializable.hh" +#include "Log.hh" #include "Settings.hh" #include "Video.hh" @@ -39,41 +41,29 @@ namespace Mf { 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; @@ -82,7 +72,8 @@ void Video::init(const Attributes& attribs, const std::string& caption) setFull(attribs.fullscreen); setResizable(attribs.resizable); setOpenGLAttributes(); - setCaption(caption); + setCaption(attribs.caption); + setIcon(); setCursorVisible(attribs.cursorVisible); setCursorGrab(attribs.cursorGrab); setVideoMode(attribs.mode); @@ -93,7 +84,6 @@ void Video::recreateContext() SDL_FreeSurface(context_); context_ = 0; setVideoMode(attribs_.mode); - Mf::Dispatcher::instance().dispatch("video.context_recreated"); } void Video::setOpenGLAttributes() @@ -138,8 +128,16 @@ void Video::setVideoMode(const long mode[3]) 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); } } @@ -163,14 +161,26 @@ bool Video::iconify() 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; } @@ -278,6 +288,17 @@ void Video::swap() } +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) @@ -306,41 +327,52 @@ Video::Attributes::Attributes() cursorVisible = true; cursorGrab = false; - std::vector 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 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 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 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 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 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); }