Skip to content

Commit

Permalink
add a start signal
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Sep 18, 2024
1 parent 0e02200 commit 76951f4
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 21 deletions.
15 changes: 0 additions & 15 deletions demos/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,7 @@ static int callback(float *buffer, int frames, void *user_data) {
return frames;
}

static void open_empty(void *user_data) {

}

static void open_file(char const *path, void *user_data) {

}

static void quit(void *user_data) {

}

int main() {
struct gral_application_interface interface = {&open_empty, &open_file, &quit};
struct gral_application *application = gral_application_create("com.github.eyelash.libgral.demos.audio", &interface, NULL);
gral_audio_play(&callback, NULL);
gral_application_delete(application);
return 0;
}
6 changes: 5 additions & 1 deletion demos/clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ static void create_window(void *user_data) {
demo->window = gral_window_create(demo->application, 800, 600, "gral clipboard demo", &interface, demo);
}

static void start(void *user_data) {

}

static void open_empty(void *user_data) {
create_window(user_data);
}
Expand All @@ -115,7 +119,7 @@ static void quit(void *user_data) {

int main(int argc, char **argv) {
struct demo demo;
struct gral_application_interface interface = {&open_empty, &open_file, &quit};
struct gral_application_interface interface = {&start, &open_empty, &open_file, &quit};
demo.application = gral_application_create("com.github.eyelash.libgral.demos.clipboard", &interface, &demo);
int result = gral_application_run(demo.application, argc, argv);
gral_window_delete(demo.window);
Expand Down
6 changes: 5 additions & 1 deletion demos/cursors.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ static void create_window(void *user_data) {
demo->cursor = GRAL_CURSOR_DEFAULT;
}

static void start(void *user_data) {

}

static void open_empty(void *user_data) {
create_window(user_data);
}
Expand All @@ -142,7 +146,7 @@ static void quit(void *user_data) {

int main(int argc, char **argv) {
struct demo demo;
struct gral_application_interface interface = {&open_empty, &open_file, &quit};
struct gral_application_interface interface = {&start, &open_empty, &open_file, &quit};
demo.application = gral_application_create("com.github.eyelash.libgral.demos.cursors", &interface, &demo);
int result = gral_application_run(demo.application, argc, argv);
gral_window_delete(demo.window);
Expand Down
6 changes: 5 additions & 1 deletion demos/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ static void create_window(void *user_data) {
gral_window_set_minimum_size(demo->window, 600, 400);
}

static void start(void *user_data) {

}

static void open_empty(void *user_data) {
create_window(user_data);
}
Expand All @@ -184,7 +188,7 @@ static void quit(void *user_data) {

int main(int argc, char **argv) {
struct demo demo;
struct gral_application_interface interface = {&open_empty, &open_file, &quit};
struct gral_application_interface interface = {&start, &open_empty, &open_file, &quit};
demo.application = gral_application_create("com.github.eyelash.libgral.demos.draw", &interface, &demo);
int result = gral_application_run(demo.application, argc, argv);
gral_window_delete(demo.window);
Expand Down
6 changes: 5 additions & 1 deletion demos/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ static void create_window(void *user_data) {
demo->midi = gral_midi_create(demo->application, "gral events demo", &midi_interface, demo);
}

static void start(void *user_data) {
printf("start\n");
}

static void open_empty(void *user_data) {
printf("open empty\n");
create_window(user_data);
Expand All @@ -165,7 +169,7 @@ static void quit(void *user_data) {

int main(int argc, char **argv) {
struct demo demo;
struct gral_application_interface interface = {&open_empty, &open_file, &quit};
struct gral_application_interface interface = {&start, &open_empty, &open_file, &quit};
demo.application = gral_application_create("com.github.eyelash.libgral.demos.events", &interface, &demo);
int result = gral_application_run(demo.application, argc, argv);
gral_midi_delete(demo.midi);
Expand Down
6 changes: 5 additions & 1 deletion demos/file_dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ static void create_window(void *user_data) {
demo->window = gral_window_create(demo->application, 600, 400, "gral file dialog demo", &interface, demo);
}

static void start(void *user_data) {

}

static void open_empty(void *user_data) {
create_window(user_data);
}
Expand All @@ -126,7 +130,7 @@ static void quit(void *user_data) {

int main(int argc, char **argv) {
struct demo demo;
struct gral_application_interface interface = {&open_empty, &open_file, &quit};
struct gral_application_interface interface = {&start, &open_empty, &open_file, &quit};
demo.application = gral_application_create("com.github.eyelash.libgral.demos.file_dialogs", &interface, &demo);
int result = gral_application_run(demo.application, argc, argv);
gral_window_delete(demo.window);
Expand Down
6 changes: 5 additions & 1 deletion demos/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ static void create_window(void *user_data) {
gral_font_delete(font);
}

static void start(void *user_data) {

}

static void open_empty(void *user_data) {
create_window(user_data);
}
Expand All @@ -138,7 +142,7 @@ static void quit(void *user_data) {

int main(int argc, char **argv) {
struct demo demo;
struct gral_application_interface interface = {&open_empty, &open_file, &quit};
struct gral_application_interface interface = {&start, &open_empty, &open_file, &quit};
demo.application = gral_application_create("com.github.eyelash.libgral.demos.text", &interface, &demo);
int result = gral_application_run(demo.application, argc, argv);
gral_text_delete(demo.text);
Expand Down
1 change: 1 addition & 0 deletions gral.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum {

struct gral_application;
struct gral_application_interface {
void (*start)(void *user_data);
void (*open_empty)(void *user_data);
void (*open_file)(char const *path, void *user_data);
void (*quit)(void *user_data);
Expand Down
6 changes: 6 additions & 0 deletions gral_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ struct _GralApplication {
};
G_DEFINE_TYPE(GralApplication, gral_application, GTK_TYPE_APPLICATION)

static void gral_application_startup(GApplication *gapplication) {
G_APPLICATION_CLASS(gral_application_parent_class)->startup(gapplication);
GralApplication *application = GRAL_APPLICATION(gapplication);
application->interface.start(application->user_data);
}
static void gral_application_activate(GApplication *gapplication) {
GralApplication *application = GRAL_APPLICATION(gapplication);
application->interface.open_empty(application->user_data);
Expand All @@ -52,6 +57,7 @@ static void gral_application_init(GralApplication *application) {
}
static void gral_application_class_init(GralApplicationClass *class) {
GApplicationClass *application_class = G_APPLICATION_CLASS(class);
application_class->startup = gral_application_startup;
application_class->activate = gral_application_activate;
application_class->open = gral_application_open;
application_class->shutdown = gral_application_shutdown;
Expand Down
3 changes: 3 additions & 0 deletions gral_macos.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ @implementation GralApplication
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
return YES;
}
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
interface.start(user_data);
}
- (BOOL)applicationOpenUntitledFile:(NSApplication *)sender {
interface.open_empty(user_data);
return YES;
Expand Down
1 change: 1 addition & 0 deletions gral_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ void gral_application_delete(gral_application *application) {

int gral_application_run(gral_application *application, int argc_, char **argv_) {
main_thread_id = GetCurrentThreadId();
application->iface.start(application->user_data);
int argc;
LPWSTR *argv = CommandLineToArgvW(GetCommandLine(), &argc);
if (argc > 1) {
Expand Down

0 comments on commit 76951f4

Please sign in to comment.