forked from misakamm/xege
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
总是创建 Unicode 窗口, 支持设置是否使用多字符的 char 消息; 支持设置代码页, 并在 API 内部转换编码, 全面使用 Unicode 版本 (W 后缀)的 Win32 API
- Loading branch information
1 parent
573c7bf
commit 315b277
Showing
17 changed files
with
307 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <ege.h> | ||
#include <cstring> | ||
#include <vector> | ||
#include <string> | ||
#include <cstdio> | ||
|
||
#define CHAR_MSG_MBCS 0 | ||
#define CHAR_MSG_UTF_16 1 | ||
|
||
#define FONT_HEIGHT 20 | ||
#define FONT_WIDTH 10 | ||
#define WIDTH 480 | ||
#define HEIGHT 360 | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
int mode = CHAR_MSG_MBCS; | ||
if (argc > 1 && strcmp(argv[1], "--utf-8") == 0) { | ||
ege::setcaption("ege input demo - UTF-8"); | ||
ege::setcodepage(EGE_CODEPAGE_UTF8); | ||
// ege::setunicodecharmessage(false); | ||
} else if (argc > 1 && strcmp(argv[1], "--utf-16") == 0) { | ||
ege::setcaption("ege input demo - UTF-16"); | ||
// ege::setcodepage(EGE_CODEPAGE_ANSI); | ||
ege::setunicodecharmessage(true); | ||
mode = CHAR_MSG_UTF_16; | ||
} else { | ||
// ege::setcodepage(EGE_CODEPAGE_ANSI); | ||
ege::setcaption("ege input demo - ANSI"); | ||
// ege::setunicodecharmessage(false); | ||
} | ||
|
||
ege::initgraph(WIDTH, HEIGHT); | ||
ege::setfont(FONT_HEIGHT, FONT_WIDTH, "SimHei"); | ||
|
||
std::vector<std::vector<char> > input_strings; | ||
std::vector<std::vector<wchar_t> > input_strings_w; | ||
|
||
while (ege::is_run()) { | ||
std::vector<wchar_t> chars; | ||
|
||
while (ege::kbmsg()) { | ||
ege::key_msg kmsg = ege::getkey(); | ||
if (kmsg.msg == ege::key_msg_char) { | ||
chars.push_back(kmsg.key); | ||
} | ||
} | ||
|
||
// print to console | ||
if (!chars.empty()) { | ||
for (int i = 0; i < chars.size(); ++i) { | ||
printf("%d", chars[i]); | ||
if (i != chars.size() - 1) { | ||
printf(", "); | ||
} | ||
} | ||
printf("\n"); | ||
|
||
if (mode == CHAR_MSG_UTF_16) { | ||
chars.push_back(0); | ||
input_strings_w.push_back(chars); | ||
} else { | ||
std::vector<char> str; | ||
for (int i = 0; i < chars.size(); ++i) { | ||
str.push_back((char)chars[i]); | ||
} | ||
str.push_back(0); | ||
input_strings.push_back(str); | ||
} | ||
} | ||
|
||
// draw to screen | ||
ege::cleardevice(); | ||
if (mode == CHAR_MSG_UTF_16) { | ||
if (input_strings_w.size() * FONT_HEIGHT > HEIGHT) { | ||
input_strings_w.erase(input_strings_w.begin()); | ||
} | ||
for (int i = 0; i < input_strings_w.size(); ++i) { | ||
ege::outtextxy(5, i * FONT_HEIGHT, &input_strings_w[i][0]); | ||
} | ||
} else { | ||
if (input_strings.size() * FONT_HEIGHT > HEIGHT) { | ||
input_strings.erase(input_strings.begin()); | ||
} | ||
for (int i = 0; i < input_strings.size(); ++i) { | ||
ege::outtextxy(5, i * FONT_HEIGHT, &input_strings[i][0]); | ||
} | ||
} | ||
|
||
ege::delay_fps(60); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
int main() | ||
{ | ||
setcodepage(EGE_CODEPAGE_UTF8); | ||
initgraph(400, 300); | ||
setfont(24, 12, "宋体"); | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.