-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPORTING.EXAMPLE.DxLib.txt
146 lines (115 loc) · 4.53 KB
/
PORTING.EXAMPLE.DxLib.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
This is basically an annotated C program which shows how much work you
need to do in order to port an application from DxLib to DxPortLib,
provided all functions are available.
This can also be found in test/porting_example.cpp
---------------------------------------------------------------------------
/* - Any comments starting with "-" are relevant to DxPortLib. */
#include "DxLib.h"
#ifdef _WIN32
# ifdef DXPORTLIB
/* - OPTIONAL: If you want to use main() on Windows, include this
* and link SDL2main.lib. Otherwise ignore. */
# include "SDL_main.h"
# endif
#endif
/* - Non-Windows platforms do not use WinMain. */
int main(int argc, char **argv) {
/* - DxPortLib requires the text encoding to be set early.
* An extension is included that supports UTF8, which is the
* ideal text encoding to use. This is the default.
*
* If you are porting a DX_CHARSET_SHFTJIS app, you will have to
* set this.
*/
#ifdef DXPORTLIB
SetUseCharSet(DX_CHARSET_EXT_UTF8);
#endif
/* - DxPortLib cannot set WindowResize after the window has been
* created. */
SetWindowSizeChangeEnableFlag(TRUE);
/* - DxPortLib cannot set the VSync flag after the window has been
* created. */
SetWaitVSyncFlag(TRUE);
/* - DxPortLib does not support setting the color depth, so the given
* value will be ignored. It will always be 32bpp. */
SetGraphMode(640, 480, 32);
/* - DxPortLib defines the _T() and _TEXT() macro for all platforms.
* This chooses between Unicode or Multibyte text automatically. */
SetWindowText(_T("Ported Application"));
/* Normal DxLib initialization... */
ChangeWindowMode(TRUE);
DxLib_Init();
/* - DxPortLib requires fonts be "mapped" before they can be used.
* System fonts are not accessible, so you must include a font
* and use EXT_MapFontFileToName.
* (all extensions have EXT_ somewhere.)
* Loading TTF files from DXA is supported.
*
* Usage:
* EXT_MapFontFileToName(
* "filename.ttf",
* "Font Name",
* minimumThickness,
* boldFontFlag
* );
*
* The font mapping list may be cleared with
* EXT_InitFontMappings();
*
* Clearing the mappings will not destroy any font handles.
*/
#ifdef DXPORTLIB
EXT_MapFontFileToName("NotAnArialClone.ttf", "Arial", -1, FALSE);
EXT_MapFontFileToName("BoldArialClone.ttf", "Arial", 8, TRUE);
#endif
/* Creates a handle to the NotAnArialClone font. */
int fontHandle = CreateFontToHandle("Arial", 22);
/* - DxPortLib does not have a "default" font.
* If you use the default font, you must set it manually.
*
* The default font will be used by any unspecified drawing
* in the program.
*/
/* Creates the BoldArialClone font as the default font. */
SetFontSize(22);
SetFontThickness(8);
ChangeFont(_T("Arial"));
/* - Note: DxPortLib will not actually create the default font
* until it is used. */
SRand(0);
/* Run a main loop. */
while (ProcessMessage() == 0) {
DrawFillBox(0, 0, 640, 480, GetColor(0x10, 0x20, 0x30));
DrawString(
20, 20,
_T("This is the BoldArialClone font."),
GetColor(GetRand(255), GetRand(255), GetRand(255))
);
DrawStringToHandle(
20+GetRand(3), 80+GetRand(3),
_T("This is the NotAnArialClone font."),
GetColor(0xff, 0xff, 0x80),
fontHandle
);
ScreenFlip();
WaitTimer(16);
}
/* Finish up as normal. */
DxLib_End();
return 0;
}
---------------------------------------------------------------------------
That's all you should have to change, as long as nothing was removed.
If you want to convert files from SJIS to UTF8, you can run the following
command line:
$ iconv -f sjis-win -t utf8 filename.c >filename_utf8.c
Or to dump everything in batch to a directory named utf8:
$ for i in *.c *.cpp *.h ; do iconv -f sjis-win -t utf8 $i >utf8/$i ; done
Easy!
---------------------------------------------------------------------------
In DxLib_c.h is a completely C interface to DxLib's functions, simply
preface any normal function DxLib_ and it will work.
e.g.: ProcessMessage() becomes DxLib_ProcessMessage()
DxLib_Init() becomes DxLib_DxLib_Init()
This is suitable for interop libraries with other languages, such as C#.
---------------------------------------------------------------------------