Add support for dropping files onto the window to mount them as a disk
This commit is contained in:
parent
8b5472519e
commit
14dc43710f
10
src/bus.c
10
src/bus.c
|
@ -258,3 +258,13 @@ int bus_io_write(void *user, uint32_t value, uint32_t port) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drop_file(char *filename) {
|
||||||
|
int last_id = 0;
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (disk_controller.disks[i].size != 0) {
|
||||||
|
last_id++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new_disk(filename, last_id);
|
||||||
|
}
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
|
|
||||||
int bus_io_read(void *user, uint32_t *value, uint32_t port);
|
int bus_io_read(void *user, uint32_t *value, uint32_t port);
|
||||||
int bus_io_write(void *user, uint32_t value, uint32_t port);
|
int bus_io_write(void *user, uint32_t value, uint32_t port);
|
||||||
|
void drop_file(char *filename);
|
||||||
|
|
|
@ -88,7 +88,8 @@ int main(int argc, char *argv[]) {
|
||||||
key_released,
|
key_released,
|
||||||
mouse_pressed,
|
mouse_pressed,
|
||||||
mouse_released,
|
mouse_released,
|
||||||
mouse_moved
|
mouse_moved,
|
||||||
|
drop_file
|
||||||
);
|
);
|
||||||
|
|
||||||
ScreenInit();
|
ScreenInit();
|
||||||
|
|
13
src/screen.c
13
src/screen.c
|
@ -115,7 +115,6 @@ int ScreenProcessEvents() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONUP: {
|
case SDL_MOUSEBUTTONUP: {
|
||||||
if (MainScreen.MouseReleased)
|
if (MainScreen.MouseReleased)
|
||||||
MainScreen.MouseReleased(event.button.button);
|
MainScreen.MouseReleased(event.button.button);
|
||||||
|
@ -131,6 +130,14 @@ int ScreenProcessEvents() {
|
||||||
if (MainScreen.KeyReleased)
|
if (MainScreen.KeyReleased)
|
||||||
MainScreen.KeyReleased(event.key.keysym.scancode);
|
MainScreen.KeyReleased(event.key.keysym.scancode);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_DROPFILE:
|
||||||
|
if (MainScreen.DropFile) {
|
||||||
|
char *file = event.drop.file;
|
||||||
|
MainScreen.DropFile(file);
|
||||||
|
SDL_free(file);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +167,8 @@ void ScreenCreate(
|
||||||
ScreenKeyReleasedF keyreleased,
|
ScreenKeyReleasedF keyreleased,
|
||||||
ScreenMousePressedF mousepressed,
|
ScreenMousePressedF mousepressed,
|
||||||
ScreenMouseReleasedF mousereleased,
|
ScreenMouseReleasedF mousereleased,
|
||||||
ScreenMouseMovedF mousemoved
|
ScreenMouseMovedF mousemoved,
|
||||||
|
ScreenDropFileF dropfile
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (w > WindowWidth)
|
if (w > WindowWidth)
|
||||||
|
@ -178,4 +186,5 @@ void ScreenCreate(
|
||||||
MainScreen.MousePressed = mousepressed;
|
MainScreen.MousePressed = mousepressed;
|
||||||
MainScreen.MouseReleased = mousereleased;
|
MainScreen.MouseReleased = mousereleased;
|
||||||
MainScreen.MouseMoved = mousemoved;
|
MainScreen.MouseMoved = mousemoved;
|
||||||
|
MainScreen.DropFile = dropfile;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ typedef void (*ScreenKeyReleasedF)(int sdl_scancode);
|
||||||
typedef void (*ScreenMousePressedF)(int button);
|
typedef void (*ScreenMousePressedF)(int button);
|
||||||
typedef void (*ScreenMouseReleasedF)(int button);
|
typedef void (*ScreenMouseReleasedF)(int button);
|
||||||
typedef void (*ScreenMouseMovedF)(int dx, int dy);
|
typedef void (*ScreenMouseMovedF)(int dx, int dy);
|
||||||
|
typedef void (*ScreenDropFileF)(char *filename);
|
||||||
|
|
||||||
struct Screen {
|
struct Screen {
|
||||||
int Width;
|
int Width;
|
||||||
|
@ -22,6 +23,7 @@ struct Screen {
|
||||||
ScreenMousePressedF MousePressed;
|
ScreenMousePressedF MousePressed;
|
||||||
ScreenMouseReleasedF MouseReleased;
|
ScreenMouseReleasedF MouseReleased;
|
||||||
ScreenMouseMovedF MouseMoved;
|
ScreenMouseMovedF MouseMoved;
|
||||||
|
ScreenDropFileF DropFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ScreenInit();
|
void ScreenInit();
|
||||||
|
@ -39,5 +41,6 @@ void ScreenCreate(
|
||||||
ScreenKeyReleasedF keyreleased,
|
ScreenKeyReleasedF keyreleased,
|
||||||
ScreenMousePressedF mousepressed,
|
ScreenMousePressedF mousepressed,
|
||||||
ScreenMouseReleasedF mousereleased,
|
ScreenMouseReleasedF mousereleased,
|
||||||
ScreenMouseMovedF mousemoved
|
ScreenMouseMovedF mousemoved,
|
||||||
|
ScreenDropFileF dropfile
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user