Skip to content

Commit 570abdb

Browse files
committed
SDL: Update editor popup appearance
1 parent 2233074 commit 570abdb

File tree

6 files changed

+61
-22
lines changed

6 files changed

+61
-22
lines changed

src/platform/sdl/editor.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "ui/textedit.h"
1414
#include "platform/sdl/runtime.h"
1515
#include "platform/sdl/settings.h"
16+
#include "platform/sdl/syswm.h"
1617

1718
using namespace strlib;
1819

@@ -120,11 +121,11 @@ void onlineHelp(Runtime *runtime, TextEditInput *widget) {
120121
}
121122

122123
void showHelpPopup(TextEditHelpWidget *helpWidget) {
123-
helpWidget->showPopup(-20, -8);
124+
helpWidget->showPopup(-12, -4);
124125
}
125126

126-
void showHelpLineInput(TextEditHelpWidget *helpWidget) {
127-
helpWidget->showPopup(40, 1);
127+
void showHelpLineInput(TextEditHelpWidget *helpWidget, int width = 35) {
128+
helpWidget->showPopup(width, 1);
128129
}
129130

130131
void showHelpSideabar(TextEditHelpWidget *helpWidget) {
@@ -319,7 +320,10 @@ void System::editSource(String loadPath, bool restoreOnExit) {
319320
onlineHelp((Runtime *)this, editWidget);
320321
break;
321322
case SB_KEY_F(4):
322-
if (editWidget->getTextLength() && !g_exportAddr.empty() && !g_exportToken.empty()) {
323+
if (editWidget->getTextLength() && !g_exportAddr.empty() && g_exportAddr.indexOf("sbasic", 0) != -1) {
324+
launch(g_exportAddr, loadPath);
325+
break;
326+
} else if (editWidget->getTextLength() && !g_exportAddr.empty() && !g_exportToken.empty()) {
323327
exportBuffer(_output, editWidget->getText(), g_exportAddr, g_exportToken);
324328
break;
325329
}
@@ -331,7 +335,7 @@ void System::editSource(String loadPath, bool restoreOnExit) {
331335
_output->setStatus("Export to SmallBASIC. Enter <IP>:<Port> | <sbasic command>");
332336
widget = helpWidget;
333337
helpWidget->createLineEdit(g_exportAddr);
334-
showHelpLineInput(helpWidget);
338+
showHelpLineInput(helpWidget, 60);
335339
inputMode = kExportAddr;
336340
}
337341
break;
@@ -395,7 +399,7 @@ void System::editSource(String loadPath, bool restoreOnExit) {
395399
_output->setStatus("Goto line. Esc=Close");
396400
widget = helpWidget;
397401
helpWidget->createGotoLine();
398-
showHelpLineInput(helpWidget);
402+
showHelpLineInput(helpWidget, 5);
399403
break;
400404
case SB_KEY_CTRL(' '):
401405
_output->setStatus("Auto-complete. Esc=Close");
@@ -488,9 +492,16 @@ void System::editSource(String loadPath, bool restoreOnExit) {
488492
switch (inputMode) {
489493
case kExportAddr:
490494
g_exportAddr = helpWidget->getText();
491-
inputMode = kExportToken;
492-
helpWidget->createLineEdit(g_exportToken);
493-
_output->setStatus("Enter token. Esc=Close");
495+
if (g_exportAddr.indexOf("sbasic", 0) == -1) {
496+
inputMode = kExportToken;
497+
helpWidget->createLineEdit(g_exportToken);
498+
_output->setStatus("Enter token. Esc=Close");
499+
} else {
500+
inputMode = kInit;
501+
widget = editWidget;
502+
helpWidget->hide();
503+
launch(g_exportAddr, loadPath);
504+
}
494505
break;
495506
case kExportToken:
496507
g_exportToken = helpWidget->getText();
@@ -501,6 +512,7 @@ void System::editSource(String loadPath, bool restoreOnExit) {
501512
break;
502513
case kCommand:
503514
strlcpy(opt_command, helpWidget->getText(), sizeof(opt_command));
515+
statusMessage._dirty = !editWidget->isDirty();
504516
inputMode = kInit;
505517
widget = editWidget;
506518
helpWidget->hide();
@@ -509,11 +521,11 @@ void System::editSource(String loadPath, bool restoreOnExit) {
509521
break;
510522
}
511523
} else if (helpWidget->closeOnEnter() && helpWidget->isVisible()) {
524+
statusMessage._dirty = !editWidget->isDirty();
512525
widget = editWidget;
513526
helpWidget->hide();
514527
helpWidget->cancelMode();
515528
}
516-
statusMessage._dirty = !editWidget->isDirty();
517529
redraw = true;
518530
} else if (helpWidget->replaceDoneMode()) {
519531
statusMessage._dirty = !editWidget->isDirty();

src/platform/sdl/runtime.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,12 @@ SDL_Rect Runtime::getWindowRect() {
779779
result = _windowRect;
780780
} else {
781781
setWindowRect(result);
782+
#if defined(__linux__)
783+
int top, left,bottom, right;
784+
SDL_GetWindowBordersSize(_window, &top, &left, &bottom, &right);
785+
// subtract the X11 border
786+
result.y -= top;
787+
#endif
782788
}
783789
return result;
784790
}

src/platform/sdl/syswm.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ void launchDebug(const char *file) {
5858
}
5959
}
6060

61-
void launchExec(const char *file) {
61+
void launch(const char *command, const char *file) {
6262
STARTUPINFO info = {sizeof(info)};
6363
PROCESS_INFORMATION processInfo;
6464
char cmd[1024];
65-
sprintf(cmd, "%s -x %s", g_appPath, file);
66-
if (!CreateProcess(g_appPath, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo)) {
67-
appLog("failed to start %d %s %s\n", GetLastError(), g_appPath, cmd);
65+
sprintf(cmd, "%s -x %s", command, file);
66+
if (!CreateProcess(command, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo)) {
67+
appLog("failed to start %d %s %s\n", GetLastError(), command, cmd);
6868
}
6969
}
7070

@@ -126,7 +126,7 @@ void launchDebug(const char *file) {
126126
}
127127
}
128128

129-
void launchExec(const char *file) {
129+
void launch(const char *command, const char *file) {
130130
pid_t pid = fork();
131131

132132
switch (pid) {
@@ -135,8 +135,8 @@ void launchExec(const char *file) {
135135
break;
136136
case 0:
137137
// child process
138-
if (execl(g_appPath, g_appPath, "-x", file, (char *)0) == -1) {
139-
fprintf(stderr, "exec failed [%s] %s\n", strerror(errno), g_appPath);
138+
if (execl(command, command, "-x", file, (char *)0) == -1) {
139+
fprintf(stderr, "exec failed [%s] %s\n", strerror(errno), command);
140140
exit(1);
141141
}
142142
break;
@@ -166,3 +166,7 @@ void browseFile(SDL_Window *window, const char *url) {
166166
}
167167

168168
#endif
169+
170+
void launchExec(const char *file) {
171+
launch(g_appPath, file);
172+
}

src/platform/sdl/syswm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void loadIcon(SDL_Window *window);
1515
int getStartupFontSize(SDL_Window *window);
1616
void launchDebug(const char *file);
1717
void launchExec(const char *file);
18+
void launch(const char *command, const char *file);
1819
void browseFile(SDL_Window *window, const char *url);
1920

2021
#endif

src/ui/audio.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C" {
3030
#define MILLIS_TO_MICROS(n) (n * 1000)
3131

3232
struct Sound;
33+
static ma_context context;
3334
static ma_device device;
3435
static ma_device_config config;
3536
static strlib::Queue<Sound *> queue;
@@ -124,7 +125,7 @@ static void setup_format(ma_format format, ma_uint32 channels, ma_uint32 sampleR
124125
config.sampleRate != sampleRate) {
125126
audio_close();
126127
setup_config(format, channels, sampleRate);
127-
ma_result result = ma_device_init(nullptr, &config, &device);
128+
ma_result result = ma_device_init(&context, &config, &device);
128129
if (result != MA_SUCCESS) {
129130
err_throw("Failed to prepare sound device [%d]", result);
130131
}
@@ -141,14 +142,29 @@ static void device_start() {
141142
}
142143

143144
bool audio_open() {
144-
setup_config(DEFAULT_FORMAT, DEFAULT_CHANNELS, DEFAULT_SAMPLE_RATE);
145-
queuePos = 0;
146-
return (ma_device_init(nullptr, &config, &device) == MA_SUCCESS);
145+
bool result;
146+
ma_backend backends[] = {
147+
// uncomment for audio in linux
148+
//ma_backend_alsa,
149+
//ma_backend_jack,
150+
//ma_backend_pulseaudio,
151+
ma_backend_wasapi,
152+
ma_backend_dsound
153+
};
154+
if (ma_context_init(backends, sizeof(backends)/sizeof(backends[0]), NULL, &context) != MA_SUCCESS) {
155+
result = false;
156+
} else {
157+
queuePos = 0;
158+
setup_config(DEFAULT_FORMAT, DEFAULT_CHANNELS, DEFAULT_SAMPLE_RATE);
159+
result = (ma_device_init(&context, &config, &device) == MA_SUCCESS);
160+
}
161+
return result;
147162
}
148163

149164
void audio_close() {
150165
osd_clear_sound_queue();
151166
ma_device_uninit(&device);
167+
ma_context_uninit(&context);
152168
}
153169

154170
void osd_audio(const char *path) {

src/ui/textedit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ void TextEditHelpWidget::showPopup(int cols, int rows) {
23842384
}
23852385
_x = (_editor->_width - _width) / 2;
23862386
if (rows == 1) {
2387-
_y = _editor->_height - (_charHeight * 3);
2387+
_y = _editor->_height - (_charHeight * 2.5);
23882388
} else {
23892389
_y = (_editor->_height - _height) / 2;
23902390
}

0 commit comments

Comments
 (0)