Skip to content

Commit d242d1a

Browse files
committed
Add launcher dialog for win32 port
1 parent 5398dcb commit d242d1a

File tree

6 files changed

+135
-26
lines changed

6 files changed

+135
-26
lines changed

Makefile.win

+8-22
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,32 @@
1-
# mcmap/Makefile.win
1+
# mcmap/Makefile.win -*- mode: makefile -*-
22

3-
sources := cmd.c console.c main.c map.c protocol.c world.c
3+
sources := cmd.c console.c main.c map.c protocol.c world.c win32.c
44

5-
objs := $(sources:.c=.o)
5+
objs := $(sources:.c=.o) win32-res.o
66
deps := $(sources:.c=.d)
77

88
CC := i586-mingw32msvc-gcc
9+
WINDRES := i586-mingw32msvc-windres
910

1011
CFLAGS := $(CFLAGS)
1112
CFLAGS += -Wall -Werror -std=gnu99
1213
CFLAGS += -Iwin/glib/include -Iwin/glib/include/glib-2.0 -Iwin/glib/lib/glib-2.0/include
1314
CFLAGS += -Iwin/SDL-1.2.14/include/SDL
14-
15-
ifndef EXTCFLAGS
16-
ifdef DEBUG
17-
EXTCFLAGS := -g
18-
else
19-
EXTCFLAGS := -O3 -funroll-loops
20-
endif
21-
endif
22-
23-
CFLAGS += $(EXTCFLAGS)
15+
CFLAGS += -O2
2416

2517
LDFLAGS := $(LDFLAGS)
2618
LDFLAGS += -Lwin/glib/lib -lglib-2.0 -lgobject-2.0 -lgthread-2.0 -lgio-2.0 -lz
2719
LDFLAGS += -Lwin/SDL-1.2.14/lib -lSDL
2820

29-
.PHONY: all opt debug diet clean
21+
.PHONY: all clean
3022

3123
all: mcmap.exe
3224

3325
mcmap.exe: $(objs)
3426
$(CC) -Wl,--subsystem,console -o $@ $^ $(LDFLAGS)
3527

36-
opt: $(sources)
37-
$(CC) -o mcmap $(CFLAGS) -combine -fwhole-program $(sources) $(LDFLAGS)
38-
39-
debug:
40-
@$(MAKE) --no-print-directory DEBUG=1
41-
42-
diet:
43-
@$(MAKE) --no-print-directory CC="diet -Os $(CC)" EXTCFLAGS=""
28+
win32-res.o: win32.rc win32-res.h
29+
$(WINDRES) -O coff $< $@
4430

4531
-include $(deps)
4632

main.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55

66
#include <gio/gio.h>
77
#include <SDL.h>
8-
#ifdef WIN32
9-
#undef main
10-
#include <windows.h>
11-
#endif
128

139
#include "cmd.h"
1410
#include "common.h"
@@ -17,6 +13,12 @@
1713
#include "protocol.h"
1814
#include "world.h"
1915

16+
#ifdef WIN32
17+
#undef main
18+
#include <windows.h>
19+
#include "win32.h"
20+
#endif
21+
2022
/* default command-line options */
2123

2224
struct options opt = {
@@ -157,6 +159,11 @@ int main(int argc, char **argv)
157159

158160
/* command line option grokking */
159161

162+
#ifdef WIN32
163+
if (argc <= 1)
164+
win32_splash(&argc, &argv);
165+
#endif
166+
160167
static GOptionEntry gopt_entries[] = {
161168
{ "nocolor", 'c', 0, G_OPTION_ARG_NONE, &opt.noansi, "Disable ANSI color escapes" },
162169
{ "nomap", 'm', 0, G_OPTION_ARG_NONE, &opt.nomap, "Disable the map" },

win32-res.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef IDC_STATIC
2+
#define IDC_STATIC (-1)
3+
#endif
4+
5+
#define IDD_SPLASH 101
6+
#define IDC_SPLASH_SERVER 1003
7+
#define IDC_SPLASH_SIZE 1005

win32.c

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include <windows.h>
2+
#include <glib.h>
3+
4+
#include "win32.h"
5+
#include "win32-res.h"
6+
7+
static int splash_argc = 0;
8+
static char** splash_argv = 0;
9+
10+
static void splash_setargs(HWND hWnd)
11+
{
12+
splash_argc = 4;
13+
splash_argv = g_new0(char *, 5);
14+
15+
char buf_server[256] = {0}, buf_size[256] = {0};
16+
GetWindowText(GetDlgItem(hWnd, IDC_SPLASH_SERVER), buf_server, sizeof buf_server);
17+
GetWindowText(GetDlgItem(hWnd, IDC_SPLASH_SIZE), buf_size, sizeof buf_size);
18+
19+
splash_argv[0] = "mcmap";
20+
splash_argv[1] = "-c";
21+
22+
if (strcmp(buf_size, "nomap") == 0)
23+
splash_argv[2] = "-m";
24+
else
25+
splash_argv[2] = g_strdup_printf("--size=%s", buf_size);
26+
27+
splash_argv[3] = g_strdup(buf_server);
28+
splash_argv[4] = 0;
29+
}
30+
31+
static INT_PTR CALLBACK splash_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
32+
{
33+
if (uMsg == WM_INITDIALOG)
34+
{
35+
/* initialize the server name control */
36+
37+
SetWindowText(GetDlgItem(hWnd, IDC_SPLASH_SERVER), "example.org");
38+
39+
/* initialize the screen size control */
40+
41+
HWND sc = GetDlgItem(hWnd, IDC_SPLASH_SIZE);
42+
SendMessage(sc, CB_RESETCONTENT, 0, 0);
43+
SendMessage(sc, CB_ADDSTRING, 0, (LPARAM)"nomap");
44+
SendMessage(sc, CB_ADDSTRING, 0, (LPARAM)"512x512");
45+
SendMessage(sc, CB_ADDSTRING, 0, (LPARAM)"resizable");
46+
SetWindowText(sc, "nomap");
47+
48+
/* finish up */
49+
50+
SetFocus(GetDlgItem(hWnd, IDOK));
51+
52+
return FALSE;
53+
}
54+
55+
if (uMsg == WM_COMMAND)
56+
{
57+
switch (LOWORD(wParam))
58+
{
59+
case IDOK:
60+
splash_setargs(hWnd);
61+
EndDialog(hWnd, 1);
62+
break;
63+
64+
case IDCANCEL:
65+
EndDialog(hWnd, 0);
66+
break;
67+
}
68+
69+
return FALSE;
70+
}
71+
72+
return FALSE;
73+
}
74+
75+
void win32_splash(int *argc, char ***argv)
76+
{
77+
INT_PTR ret = DialogBox(NULL, MAKEINTRESOURCE(IDD_SPLASH), NULL, splash_proc);
78+
79+
if (ret <= 0)
80+
exit(0);
81+
82+
*argc = splash_argc;
83+
*argv = splash_argv;
84+
}

win32.h

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef MCMAP_WIN32_H
2+
#define MCMAP_WIN32_H 1
3+
4+
void win32_splash(int *argc, char ***argv);
5+
6+
#endif /* MCMAP_WIN32_H */

win32.rc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <windows.h>
2+
#include <commctrl.h>
3+
#include <richedit.h>
4+
#include "win32-res.h"
5+
6+
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
7+
IDD_SPLASH DIALOG 0, 0, 286, 95
8+
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
9+
CAPTION "Mcmap Launcher"
10+
FONT 8, "Ms Shell Dlg"
11+
{
12+
DEFPUSHBUTTON "Start", IDOK, 5, 75, 75, 15
13+
PUSHBUTTON "Cancel", IDCANCEL, 85, 75, 75, 15
14+
GROUPBOX "Minecraft server:", IDC_STATIC, 5, 5, 275, 30
15+
EDITTEXT IDC_SPLASH_SERVER, 10, 15, 265, 15, ES_AUTOHSCROLL
16+
GROUPBOX "Mcmap graphics:", IDC_STATIC, 5, 40, 275, 30
17+
LTEXT "Screen size:", IDC_STATIC, 10, 50, 45, 10, SS_LEFT
18+
COMBOBOX IDC_SPLASH_SIZE, 60, 50, 215, 17, CBS_DROPDOWN | CBS_HASSTRINGS
19+
}

0 commit comments

Comments
 (0)