From cbdcb536bf818d0313c9ac6a61c7783b494c300b Mon Sep 17 00:00:00 2001 From: nakeee Date: Thu, 18 Dec 2008 10:52:06 +0000 Subject: [PATCH] WXGL window git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1581 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Plugins/Plugin_VideoOGL/Src/SConscript | 5 +- .../Plugin_VideoOGL/Src/WXGLWindow.cpp | 101 ++++++++++++++++++ .../Plugins/Plugin_VideoOGL/Src/WXGLWindow.h | 34 ++++++ 3 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 Source/Plugins/Plugin_VideoOGL/Src/WXGLWindow.cpp create mode 100644 Source/Plugins/Plugin_VideoOGL/Src/WXGLWindow.h diff --git a/Source/Plugins/Plugin_VideoOGL/Src/SConscript b/Source/Plugins/Plugin_VideoOGL/Src/SConscript index 288db7fc52..aa2aaa3d37 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/SConscript +++ b/Source/Plugins/Plugin_VideoOGL/Src/SConscript @@ -105,7 +105,10 @@ if gfxenv['HAVE_SDL']: files += [ 'SDLWindow.cpp', ] - +if gfxenv['USE_WX']: + files += [ + 'WXGLWindow.cpp', + ] # Sanity check if gfxenv['USE_WX'] and not gfxenv['HAVE_WX']: print "Must have wx to use wxgl" diff --git a/Source/Plugins/Plugin_VideoOGL/Src/WXGLWindow.cpp b/Source/Plugins/Plugin_VideoOGL/Src/WXGLWindow.cpp new file mode 100644 index 0000000000..a14d4e669a --- /dev/null +++ b/Source/Plugins/Plugin_VideoOGL/Src/WXGLWindow.cpp @@ -0,0 +1,101 @@ +#include "WXGLWindow.h" + +void WXGLWindow::SwapBuffers() { + glCanvas->SwapBuffers(); +} + +void WXGLWindow::SetWindowText(const char *text) { + frame->SetTitle(wxString::FromAscii(text)); +} + +bool WXGLWindow::PeekMessages() { + // TODO implmenent + return false; +} + +void WXGLWindow::Update() { + float FactorW = 640.0f / (float)GetWidth(); + float FactorH = 480.0f / (float)GetHeight(); + float Max = (FactorW < FactorH) ? FactorH : FactorW; + //AR = (float)nBackbufferWidth / (float)nBackbufferHeight; + + if (g_Config.bStretchToFit) { + MValueX = 1; + MValueY = 1; + nXoff = 0; + nYoff = 0; + } else { + MValueX = 1.0f / Max; + MValueY = 1.0f / Max; + nXoff = (int)((GetWidth() - (640 * MValueX)) / 2); + nYoff = (int)((GetHeight() - (480 * MValueY)) / 2); + } +} + +bool WXGLWindow::MakeCurrent() { + glCanvas->SetCurrent(*glCtxt); + return true; +} + +WXGLWindow::~WXGLWindow() { + delete glCanvas; + delete frame; +} + +WXGLWindow::WXGLWindow(int _iwidth, int _iheight) { + int _twidth, _theight; + if(g_Config.bFullscreen) { + if(strlen(g_Config.iFSResolution) > 1) { + sscanf(g_Config.iFSResolution, "%dx%d", &_twidth, &_theight); + } else {// No full screen reso set, fall back to default reso + _twidth = _iwidth; + _theight = _iheight; + } + } else {// Going Windowed + if(strlen(g_Config.iWindowedRes) > 1) { + sscanf(g_Config.iWindowedRes, "%dx%d", &_twidth, &_theight); + } else {// No Window reso set, fall back to default + _twidth = _iwidth; + _theight = _iheight; + } + } + + SetSize(_iwidth, _theight); + + float FactorW = 640.0f / (float)_twidth; + float FactorH = 480.0f / (float)_theight; + float Max = (FactorW < FactorH) ? FactorH : FactorW; + + if(g_Config.bStretchToFit) { + MValueX = 1.0f / FactorW; + MValueY = 1.0f / FactorH; + nXoff = 0; + nYoff = 0; + } else { + MValueX = 1.0f / Max; + MValueY = 1.0f / Max; + nXoff = (int)((_twidth - (640 * MValueX)) / 2); + nYoff = (int)((_theight - (480 * MValueY)) / 2); + } + + int args[] = {WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, 0}; + + wxSize size(GetWidth(), GetHeight()); + if (!g_Config.renderToMainframe || + g_VideoInitialize.pWindowHandle == NULL) { + frame = new wxFrame((wxWindow *)g_VideoInitialize.pWindowHandle, + -1, _("Dolphin"), wxPoint(0,0), size); + } else { + frame = new wxFrame((wxWindow *)NULL, + -1, _("Dolphin"), wxPoint(0,0), size); + } + glCanvas = new wxGLCanvas(frame, wxID_ANY, args, + wxPoint(0,0), size, wxSUNKEN_BORDER); + glCtxt = new wxGLContext(glCanvas); + + frame->Show(TRUE); + glCanvas->Show(TRUE); + + glCanvas->SetCurrent(*glCtxt); +} + diff --git a/Source/Plugins/Plugin_VideoOGL/Src/WXGLWindow.h b/Source/Plugins/Plugin_VideoOGL/Src/WXGLWindow.h new file mode 100644 index 0000000000..2a1f6badfe --- /dev/null +++ b/Source/Plugins/Plugin_VideoOGL/Src/WXGLWindow.h @@ -0,0 +1,34 @@ +#ifndef _WXGLWINDOW_H +#define _WXGLWINDOW_H + +#include "GLWindow.h" +#include +#include "wx/wx.h" +#include "wx/glcanvas.h" + +#include + +class WXGLWindow : public GLWindow +{ +private: + wxGLCanvas *glCanvas; + wxFrame *frame; + wxGLContext *glCtxt; + +public: + + int nXoff, nYoff; // screen offset + // Since it can Stretch to fit Window, we need two different multiplication values + float MValueX, MValueY; + + virtual void SwapBuffers(); + virtual void SetWindowText(const char *text); + virtual bool PeekMessages(); + virtual void Update(); + virtual bool MakeCurrent(); + + ~WXGLWindow(); + WXGLWindow(int _iwidth, int _iheight); + +}; +#endif