win32: add simple menu to opengl context

This commit is contained in:
OV2 2013-07-06 17:52:22 +02:00 committed by twinaphex
parent ab3a8822ce
commit b9cbcd0b81
4 changed files with 83 additions and 5 deletions

View File

@ -115,7 +115,7 @@ endif
ifeq ($(HAVE_OPENGL), 1)
OBJ += gfx/gl.o gfx/math/matrix.o gfx/fonts/gl_font.o gfx/fonts/gl_raster_font.o gfx/gfx_context.o gfx/context/wgl_ctx.o gfx/shader_glsl.o
DEFINES += -DHAVE_OPENGL -DHAVE_OVERLAY -DHAVE_GLSL -DHAVE_GL_SYNC
LIBS += -lopengl32 -lgdi32
LIBS += -lopengl32 -lgdi32 -lcomdlg32
endif
ifeq ($(HAVE_SDL_IMAGE), 1)

View File

@ -25,7 +25,9 @@
#include "../gfx_context.h"
#include "../gl_common.h"
#include "../gfx_common.h"
#include "../../media/resource.h"
#include <windows.h>
#include <commdlg.h>
#include <string.h>
#define IDI_ICON 1
@ -44,6 +46,8 @@ static unsigned g_interval;
static unsigned g_resize_width;
static unsigned g_resize_height;
static unsigned g_pos_x = CW_USEDEFAULT;
static unsigned g_pos_y = CW_USEDEFAULT;
static bool g_resized;
static bool g_restore_desktop;
@ -86,6 +90,25 @@ static void create_gl_context(HWND hwnd)
g_quit = true;
}
static bool BrowseForFile(char *filename)
{
OPENFILENAME ofn;
memset((void *)&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = g_hwnd;
ofn.lpstrFilter = "All Files\0*.*\0\0";
ofn.lpstrFile = filename;
ofn.lpstrTitle = "Select ROM";
ofn.lpstrDefExt = "";
ofn.nMaxFile = PATH_MAX;
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if(GetOpenFileName(&ofn)) {
return true;
}
return false;
}
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
@ -118,8 +141,14 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
case WM_CLOSE:
case WM_DESTROY:
case WM_QUIT:
{
WINDOWPLACEMENT placement;
GetWindowPlacement(g_hwnd, &placement);
g_pos_x = placement.rcNormalPosition.left;
g_pos_y = placement.rcNormalPosition.top;
g_quit = true;
return 0;
}
case WM_SIZE:
// Do not send resize message if we minimize.
@ -130,6 +159,28 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
g_resized = true;
}
return 0;
case WM_COMMAND:
switch(wparam & 0xffff)
{
case ID_M_OPENROM:
{
char rom_file[PATH_MAX] = {0};
if(BrowseForFile(rom_file))
{
strlcpy(g_extern.fullpath, rom_file, sizeof(g_extern.fullpath));
g_extern.lifecycle_mode_state |= (1ULL << MODE_LOAD_GAME);
PostMessage(g_hwnd, WM_CLOSE, 0, 0);
}
}
break;
case ID_M_RESET:
rarch_game_reset();
break;
case ID_M_QUIT:
PostMessage(g_hwnd, WM_CLOSE, 0, 0);
break;
}
break;
}
return DefWindowProc(hwnd, message, wparam, lparam);
@ -280,6 +331,7 @@ static bool gfx_ctx_set_video_mode(
bool fullscreen)
{
DWORD style;
RECT rect = {0};
HMONITOR hm_to_use = NULL;
MONITORINFOEX current_mon;
@ -315,7 +367,6 @@ static bool gfx_ctx_set_video_mode(
else
{
style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
RECT rect = {0};
rect.right = width;
rect.bottom = height;
AdjustWindowRect(&rect, style, FALSE);
@ -324,14 +375,23 @@ static bool gfx_ctx_set_video_mode(
}
g_hwnd = CreateWindowEx(0, "RetroArch", "RetroArch", style,
fullscreen ? mon_rect.left : CW_USEDEFAULT,
fullscreen ? mon_rect.top : CW_USEDEFAULT,
fullscreen ? mon_rect.left : g_pos_x,
fullscreen ? mon_rect.top : g_pos_y,
width, height,
NULL, NULL, NULL, NULL);
if (!g_hwnd)
goto error;
if(!fullscreen)
{
SetMenu(g_hwnd,LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_MENU)));
RECT rcTemp = {0, 0, g_resize_height, 0x7FFF}; // 0x7FFF="Infinite" height
SendMessage(g_hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rcTemp); // recalculate margin, taking possible menu wrap into account
g_resize_height += rcTemp.top + rect.top; // extend by new top margin and substract previous margin
SetWindowPos(g_hwnd, NULL, 0, 0, g_resize_width, g_resize_height, SWP_NOMOVE);
}
if (!fullscreen || windowed_full)
{
ShowWindow(g_hwnd, SW_RESTORE);

View File

@ -1 +1,13 @@
1 ICON DISCARDABLE "retroarch-icon.ico"
#include "resource.h"
1 ICON "retroarch-icon.ico"
IDR_MENU MENU
BEGIN
POPUP "File"
BEGIN
MENUITEM "Open ROM", ID_M_OPENROM
MENUITEM SEPARATOR
MENUITEM "Reset", ID_M_RESET
MENUITEM "Quit", ID_M_QUIT
END
END

6
media/resource.h Normal file
View File

@ -0,0 +1,6 @@
// Used by rarch.rc
//
#define IDR_MENU 101
#define ID_M_OPENROM 40001
#define ID_M_RESET 40002
#define ID_M_QUIT 40003