X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FVideo.cc;h=1ed24c75fee3e3e877cea604eab0261c9028b0cf;hp=c41517e51c87601ff96bd25f1c63ba3e83dcfcb1;hb=33842c860fe18ca8cf087905992885687434320c;hpb=c2321281bf12a7efaedde930422c7ddbc92080d4 diff --git a/src/Moof/Video.cc b/src/Moof/Video.cc index c41517e..1ed24c7 100644 --- a/src/Moof/Video.cc +++ b/src/Moof/Video.cc @@ -28,7 +28,10 @@ #include +#include + #include "Dispatcher.hh" +#include "Log.hh" #include "Serializable.hh" #include "Settings.hh" #include "Video.hh" @@ -39,41 +42,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 +73,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 +85,6 @@ void Video::recreateContext() SDL_FreeSurface(context_); context_ = 0; setVideoMode(attribs_.mode); - Mf::Dispatcher::instance().dispatch("video.context_recreated"); } void Video::setOpenGLAttributes() @@ -138,6 +129,14 @@ 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()); } @@ -163,14 +162,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; } @@ -306,41 +317,49 @@ Video::Attributes::Attributes() cursorVisible = true; cursorGrab = false; - std::vector colors; - Settings::instance().get("video.colorbuffers", colors); + Settings& settings = Settings::getInstance(); + + Serializable::Array colors; + settings.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); + settings.get("video.framebuffer", frameBuffer); + settings.get("video.doublebuffer", doubleBuffer); + settings.get("video.depthbuffer", depthBuffer); + settings.get("video.stencilbuffer", stencilBuffer); - std::vector accum; - Settings::instance().get("video.accumbuffers", accum); + Serializable::Array accum; + settings.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); + settings.get("video.stereo", stereo); + settings.get("video.multiesamplebuffers", multisampleBuffers); + settings.get("video.multiesamplesamples", multisampleSamples); + settings.get("video.swapcontrol", swapControl); + settings.get("video.hardwareonly", hardwareonly); + + if (!settings.get("video.caption", caption)) + { + caption = "Untitled"; + } + settings.get("video.icon", icon); - std::vector dimensions; - Settings::instance().get("video.mode", dimensions); + Serializable::Array dimensions; + settings.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.get("video.fullscreen", fullscreen); + settings.get("video.resizable", resizable); + settings.get("video.showcursor", cursorVisible); + settings.get("input.grab", cursorGrab); }