Skip to content

Commit b2e423d

Browse files
committed
EMCC: Emscripten version wip
1 parent 5c512b2 commit b2e423d

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/platform/emcc/canvas.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ EM_JS(void, draw_line, (int id, int x1, int y1, int x2, int y2, const char *colo
9797
var canvas = document.getElementById(id == -1 ? "canvas" : "canvas_" + id);
9898
var ctx = canvas.getContext("2d");
9999
ctx.beginPath();
100-
ctx.moveTo(x1, y1);
101-
ctx.lineTo(x2, y2);
100+
ctx.moveTo(x1, y1 + 1);
101+
ctx.lineTo(x2, y2 + 1);
102102
ctx.lineWidth = 1;
103103
ctx.strokeStyle = UTF8ToString(color);
104104
ctx.stroke();
@@ -153,7 +153,7 @@ strlib::String get_color() {
153153
uint8_t sR, sG, sB;
154154
GET_RGB(c, sR, sG, sB);
155155
char buf[8];
156-
sprintf(buf, "#%x%x%x", sR, sG, sB);
156+
sprintf(buf, "#%02x%02x%02x", sR, sG, sB);
157157
result.append(buf);
158158
}
159159
return result;

src/platform/emcc/runtime.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ Runtime::~Runtime() {
9595
}
9696

9797
void Runtime::alert(const char *title, const char *message) {
98+
EM_ASM_({
99+
window.alert(UTF8ToString($0) + "\n" + UTF8ToString($1));
100+
}, title, message);
98101
}
99102

100103
int Runtime::ask(const char *title, const char *prompt, bool cancel) {
@@ -103,9 +106,9 @@ int Runtime::ask(const char *title, const char *prompt, bool cancel) {
103106
}
104107

105108
void Runtime::browseFile(const char *url) {
106-
}
107-
108-
void Runtime::enableCursor(bool enabled) {
109+
EM_ASM_({
110+
window.open(UTF8ToString($0));
111+
}, url);
109112
}
110113

111114
char *Runtime::getClipboardText() {
@@ -124,6 +127,7 @@ char *Runtime::loadResource(const char *fileName) {
124127
}
125128

126129
void Runtime::optionsBox(StringList *items) {
130+
127131
}
128132

129133
void Runtime::pause(int timeout) {
@@ -207,6 +211,13 @@ void Runtime::setClipboardText(const char *text) {
207211
}
208212

209213
void Runtime::showCursor(CursorType cursorType) {
214+
static CursorType _cursorType;
215+
if (_cursorType != cursorType) {
216+
_cursorType = cursorType;
217+
EM_ASM_({
218+
document.body.style.cursor = UTF8ToString($0);
219+
}, cursorType == kIBeam ? "text" : cursorType == kArrow ? "auto" : "pointer");
220+
}
210221
}
211222

212223
//

src/platform/emcc/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Runtime : public System {
2020
void browseFile(const char *url);
2121
char *getClipboardText();
2222
int getFontSize() { return _output->getFontSize(); }
23-
void enableCursor(bool enabled);
23+
void enableCursor(bool enabled) {}
2424
int handle(int event);
2525
char *loadResource(const char *fileName);
2626
void optionsBox(StringList *items);

0 commit comments

Comments
 (0)