mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-13 20:04:01 +02:00
URI handling for MacOS
This commit is contained in:
@@ -161,6 +161,8 @@ typedef unsigned int pixel;
|
||||
|
||||
typedef unsigned char uint8;
|
||||
|
||||
extern int saveURIOpen;
|
||||
|
||||
extern int amd;
|
||||
|
||||
extern int FPSB;
|
||||
|
@@ -293,6 +293,8 @@ void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt);
|
||||
|
||||
void info_box(pixel *vid_buf, char *msg);
|
||||
|
||||
void info_box_overlay(pixel *vid_buf, char *msg);
|
||||
|
||||
char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shadow);
|
||||
|
||||
int confirm_ui(pixel *vid_buf, char *top, char *msg, char *btn);
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include "SDLMain.h"
|
||||
#include <sys/param.h> /* for MAXPATHLEN */
|
||||
#include <unistd.h>
|
||||
#include "defines.h"
|
||||
|
||||
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
|
||||
but the method still is there and works. To avoid warnings, we declare
|
||||
@@ -282,6 +283,21 @@ static void CustomApplicationMain (int argc, char **argv)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
|
||||
{
|
||||
NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
|
||||
int tempSaveOpen = [[url host] intValue];
|
||||
if(tempSaveOpen > 0)
|
||||
saveURIOpen = tempSaveOpen;
|
||||
}
|
||||
|
||||
-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
|
||||
{
|
||||
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
|
||||
[appleEventManager setEventHandler:self
|
||||
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
|
||||
forEventClass:kInternetEventClass andEventID:kAEGetURL];
|
||||
}
|
||||
|
||||
/* Called when the internal event loop has just started running */
|
||||
- (void) applicationDidFinishLaunching: (NSNotification *) note
|
||||
|
@@ -1298,7 +1298,7 @@ void info_box(pixel *vid_buf, char *msg)
|
||||
{
|
||||
int w = textwidth(msg)+16;
|
||||
int x0=(XRES-w)/2,y0=(YRES-24)/2;
|
||||
|
||||
|
||||
clearrect(vid_buf, x0-2, y0-2, w+4, 28);
|
||||
drawrect(vid_buf, x0, y0, w, 24, 192, 192, 192, 255);
|
||||
drawtext(vid_buf, x0+8, y0+8, msg, 192, 192, 240, 255);
|
||||
@@ -1310,6 +1310,16 @@ void info_box(pixel *vid_buf, char *msg)
|
||||
#endif
|
||||
}
|
||||
|
||||
void info_box_overlay(pixel *vid_buf, char *msg)
|
||||
{
|
||||
int w = textwidth(msg)+16;
|
||||
int x0=(XRES-w)/2,y0=(YRES-24)/2;
|
||||
|
||||
clearrect(vid_buf, x0-2, y0-2, w+4, 28);
|
||||
drawrect(vid_buf, x0, y0, w, 24, 192, 192, 192, 255);
|
||||
drawtext(vid_buf, x0+8, y0+8, msg, 192, 192, 240, 255);
|
||||
}
|
||||
|
||||
void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt)
|
||||
{
|
||||
int state = 0;
|
||||
|
29
src/main.c
29
src/main.c
@@ -202,6 +202,8 @@ static const char *old_ver_msg = "A new version is available - click here!";
|
||||
char new_message_msg[255];
|
||||
float mheat = 0.0f;
|
||||
|
||||
int saveURIOpen = 0;
|
||||
|
||||
int do_open = 0;
|
||||
int sys_pause = 0;
|
||||
int sys_shortcuts = 1;
|
||||
@@ -777,6 +779,7 @@ int main(int argc, char *argv[])
|
||||
part_vbuf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); //Extra video buffer
|
||||
part_vbuf_store = part_vbuf;
|
||||
pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
|
||||
int saveOpenError = 0;
|
||||
|
||||
gravity_init();
|
||||
GSPEED = 1;
|
||||
@@ -831,6 +834,7 @@ int main(int argc, char *argv[])
|
||||
svf_filename[0] = 0;
|
||||
svf_fileopen = 1;
|
||||
} else {
|
||||
saveOpenError = 1;
|
||||
svf_last = NULL;
|
||||
svf_lsize = 0;
|
||||
free(file_data);
|
||||
@@ -839,7 +843,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
load_presets();
|
||||
@@ -916,6 +919,11 @@ int main(int argc, char *argv[])
|
||||
error_ui(vid_buf, 0, "Unsupported CPU. Try another version.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(saveOpenError)
|
||||
{
|
||||
error_ui(vid_buf, 0, "Unable to open save file.");
|
||||
}
|
||||
|
||||
http_ver_check = http_async_req_start(NULL, "http://" SERVER "/Update.api?Action=CheckVersion", NULL, 0, 0);
|
||||
if (svf_login) {
|
||||
@@ -1128,6 +1136,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if (!do_s_check && http_async_req_status(http_session_check))
|
||||
{
|
||||
char saveURIOpenString[512];
|
||||
check_data = http_async_req_stop(http_session_check, &http_s_ret, NULL);
|
||||
if (http_ret==200 && check_data)
|
||||
{
|
||||
@@ -1212,7 +1221,15 @@ int main(int argc, char *argv[])
|
||||
svf_messages = 0;
|
||||
}
|
||||
http_session_check = NULL;
|
||||
if(saveURIOpen)
|
||||
{
|
||||
sprintf(saveURIOpenString, "%d", saveURIOpen);
|
||||
open_ui(vid_buf, saveURIOpenString, NULL);
|
||||
saveURIOpen = 0;
|
||||
}
|
||||
} else {
|
||||
if(saveURIOpen)
|
||||
info_box_overlay(vid_buf, "Waiting for login...");
|
||||
clearrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14);
|
||||
drawrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14, 255, 255, 255, 255);
|
||||
drawtext(vid_buf, XRES-122+BARSIZE/*388*/, YRES+(MENUSIZE-13), "\x84", 255, 255, 255, 255);
|
||||
@@ -1231,6 +1248,16 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
do_s_check = (do_s_check+1) & 15;
|
||||
}
|
||||
else
|
||||
{
|
||||
char saveURIOpenString[512];
|
||||
if(saveURIOpen)
|
||||
{
|
||||
sprintf(saveURIOpenString, "%d", saveURIOpen);
|
||||
open_ui(vid_buf, saveURIOpenString, NULL);
|
||||
saveURIOpen = 0;
|
||||
}
|
||||
}
|
||||
#ifdef LUACONSOLE
|
||||
if(sdl_key){
|
||||
if(!luacon_keyevent(sdl_key, sdl_mod, LUACON_KDOWN))
|
||||
|
Reference in New Issue
Block a user