2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2009-02-09 21:15:56 +00:00
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* This Program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* This Program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2010-04-25 00:31:27 +00:00
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
2009-02-09 21:15:56 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#include "stdafx.h"
|
2009-05-18 11:08:04 +00:00
|
|
|
#include "GSdx.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "GSWnd.h"
|
|
|
|
|
|
|
|
GSWnd::GSWnd()
|
2009-06-03 12:09:04 +00:00
|
|
|
: m_hWnd(NULL)
|
2009-09-17 07:40:38 +00:00
|
|
|
, m_IsManaged(true)
|
|
|
|
, m_HasFrame(true)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GSWnd::~GSWnd()
|
|
|
|
{
|
2009-06-03 12:09:04 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
LRESULT CALLBACK GSWnd::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
GSWnd* wnd = NULL;
|
|
|
|
|
|
|
|
if(message == WM_NCCREATE)
|
|
|
|
{
|
|
|
|
wnd = (GSWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams;
|
|
|
|
|
2011-02-12 21:45:16 +00:00
|
|
|
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)wnd);
|
2009-06-03 12:09:04 +00:00
|
|
|
|
|
|
|
wnd->m_hWnd = hWnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-12 21:45:16 +00:00
|
|
|
wnd = (GSWnd*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
2009-06-03 12:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(wnd == NULL)
|
|
|
|
{
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return wnd->OnMessage(message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT GSWnd::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch(message)
|
|
|
|
{
|
|
|
|
case WM_CLOSE:
|
|
|
|
Hide();
|
|
|
|
// DestroyWindow(m_hWnd);
|
|
|
|
return 0;
|
|
|
|
case WM_DESTROY:
|
2009-09-18 23:48:12 +00:00
|
|
|
// This kills the emulator when GS is closed, which *really* isn't desired behavior,
|
|
|
|
// especially in STGS mode (worked in MTGS mode since it only quit the thread, but even
|
|
|
|
// that wasn't needed).
|
2009-09-18 22:13:40 +00:00
|
|
|
//PostQuitMessage(0);
|
2009-06-03 12:09:04 +00:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
return DefWindowProc((HWND)m_hWnd, message, wParam, lParam);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#endif
|
|
|
|
|
2009-07-17 23:45:32 +00:00
|
|
|
bool GSWnd::Create(const string& title, int w, int h)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
if(m_hWnd) return true;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
WNDCLASS wc;
|
|
|
|
|
|
|
|
memset(&wc, 0, sizeof(wc));
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
|
|
|
|
wc.lpfnWndProc = WndProc;
|
|
|
|
wc.hInstance = theApp.GetModuleHandle();
|
|
|
|
// TODO: wc.hIcon = ;
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
|
|
|
wc.lpszClassName = "GSWnd";
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-04 00:15:05 +00:00
|
|
|
if(!GetClassInfo(wc.hInstance, wc.lpszClassName, &wc))
|
2009-06-03 12:09:04 +00:00
|
|
|
{
|
2009-06-04 00:15:05 +00:00
|
|
|
if(!RegisterClass(&wc))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-03 12:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW | WS_BORDER;
|
|
|
|
|
2009-07-17 23:45:32 +00:00
|
|
|
GSVector4i r;
|
|
|
|
|
|
|
|
GetWindowRect(GetDesktopWindow(), r);
|
|
|
|
|
|
|
|
bool remote = !!GetSystemMetrics(SM_REMOTESESSION);
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
if(w <= 0 || h <= 0 || remote)
|
2009-07-17 23:45:32 +00:00
|
|
|
{
|
|
|
|
w = r.width() / 3;
|
|
|
|
h = r.width() / 4;
|
|
|
|
|
|
|
|
if(!remote)
|
|
|
|
{
|
|
|
|
w *= 2;
|
|
|
|
h *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r.left = (r.left + r.right - w) / 2;
|
|
|
|
r.top = (r.top + r.bottom - h) / 2;
|
|
|
|
r.right = r.left + w;
|
|
|
|
r.bottom = r.top + h;
|
|
|
|
|
|
|
|
AdjustWindowRect(r, style, FALSE);
|
|
|
|
|
|
|
|
m_hWnd = CreateWindow(wc.lpszClassName, title.c_str(), style, r.left, r.top, r.width(), r.height(), NULL, NULL, wc.hInstance, (LPVOID)this);
|
2009-06-03 12:09:04 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
return m_hWnd != NULL;
|
2009-06-03 12:09:04 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
// TODO: linux
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#endif
|
2009-06-03 12:09:04 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
bool GSWnd::Attach(void* hWnd, bool isManaged)
|
2009-06-03 12:09:04 +00:00
|
|
|
{
|
|
|
|
// TODO: subclass
|
|
|
|
|
|
|
|
m_hWnd = hWnd;
|
2009-09-17 07:40:38 +00:00
|
|
|
m_IsManaged = isManaged;
|
2009-06-03 12:09:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
void GSWnd::Detach()
|
|
|
|
{
|
2009-09-18 22:13:40 +00:00
|
|
|
if(m_hWnd && m_IsManaged)
|
|
|
|
{
|
|
|
|
// close the window, since it's under GSdx care. It's not taking messages anyway, and
|
|
|
|
// that means its big, ugly, and in the way.
|
2011-02-19 03:36:30 +00:00
|
|
|
|
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
DestroyWindow((HWND)m_hWnd);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// TODO: linux
|
|
|
|
|
|
|
|
#endif
|
2009-09-18 22:13:40 +00:00
|
|
|
}
|
2011-02-18 01:56:05 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
m_hWnd = NULL;
|
|
|
|
m_IsManaged = true;
|
|
|
|
}
|
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
GSVector4i GSWnd::GetClientRect()
|
|
|
|
{
|
|
|
|
GSVector4i r;
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
::GetClientRect((HWND)m_hWnd, r);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
r = GSVector4i::zero();
|
|
|
|
|
2011-02-19 10:27:10 +00:00
|
|
|
// TODO: linux
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#endif
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
// Returns FALSE if the window has no title, or if th window title is under the strict
|
|
|
|
// management of the emulator.
|
2011-02-07 01:59:05 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
bool GSWnd::SetWindowText(const char* title)
|
2009-06-03 12:09:04 +00:00
|
|
|
{
|
2011-02-18 01:56:05 +00:00
|
|
|
if(!m_IsManaged) return false;
|
2009-09-17 07:40:38 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
::SetWindowText((HWND)m_hWnd, title);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// TODO: linux
|
|
|
|
|
|
|
|
#endif
|
2009-09-17 07:40:38 +00:00
|
|
|
|
|
|
|
return m_HasFrame;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSWnd::Show()
|
|
|
|
{
|
2011-02-18 01:56:05 +00:00
|
|
|
if(!m_IsManaged) return;
|
2009-09-17 07:40:38 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2011-02-19 10:27:10 +00:00
|
|
|
HWND hWnd = (HWND)m_hWnd;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-19 10:27:10 +00:00
|
|
|
SetForegroundWindow(hWnd);
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2011-02-19 10:27:10 +00:00
|
|
|
ShowWindow(hWnd, SW_SHOWNORMAL);
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2011-02-19 10:27:10 +00:00
|
|
|
UpdateWindow(hWnd);
|
2011-02-19 03:36:30 +00:00
|
|
|
|
|
|
|
#else
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
// TODO: linux
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#endif
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSWnd::Hide()
|
|
|
|
{
|
2011-02-18 01:56:05 +00:00
|
|
|
if(!m_IsManaged) return;
|
2009-09-17 07:40:38 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
ShowWindow((HWND)m_hWnd, SW_HIDE);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// TODO: linux
|
|
|
|
|
|
|
|
#endif
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
void GSWnd::HideFrame()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-18 01:56:05 +00:00
|
|
|
if(!m_IsManaged) return;
|
2009-09-17 07:40:38 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#ifdef _WINDOWS
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
HWND hWnd = (HWND)m_hWnd;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) & ~(WS_CAPTION|WS_THICKFRAME));
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
|
|
|
|
|
|
|
|
SetMenu(hWnd, NULL);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// TODO: linux
|
2011-02-18 01:56:05 +00:00
|
|
|
|
|
|
|
#endif
|
2011-02-19 03:36:30 +00:00
|
|
|
|
|
|
|
m_HasFrame = false;
|
|
|
|
}
|