Browse code

Minor fix: spelling

Dario Rodriguez authored on 28/12/2023 12:18:57
Showing 1 changed files
... ...
@@ -1,8 +1,8 @@
1 1
 /*
2 2
  * annotator.c
3 3
  *
4
- *  Annotates a image file containg a piano music sheet with the help of a human
5
- * for use in the main program.
4
+ *  Annotates an image file containg a piano music sheet with
5
+ * the help of a human for use in the main program.
6 6
  *
7 7
  * Author: Dario Rodriguez <antartica@whereismybit.com>
8 8
  * Please see the file LICENSE.txt in the sources root directory
Browse code

Create main window using boxui

Dario Rodriguez authored on 28/12/2023 12:16:42
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,139 @@
1
+/*
2
+ * annotator.c
3
+ *
4
+ *  Annotates a image file containg a piano music sheet with the help of a human
5
+ * for use in the main program.
6
+ *
7
+ * Author: Dario Rodriguez <antartica@whereismybit.com>
8
+ * Please see the file LICENSE.txt in the sources root directory
9
+ */
10
+
11
+#ifdef EMSCRIPTEN
12
+#include <emscripten.h>
13
+#endif
14
+#include <stdio.h>
15
+#include <stdlib.h>
16
+#include <unistd.h>
17
+#include <string.h>
18
+#include <time.h>
19
+#include <signal.h>
20
+#include "boxui.h"
21
+
22
+#define DEFAULT_SCREENW 640
23
+#define DEFAULT_SCREENH 480
24
+
25
+typedef struct mydata_t {
26
+        int flag_exit;
27
+        boxui_t *boxui;
28
+} mydata_t;
29
+
30
+volatile int flag_sigint;
31
+static void sigint(int n);
32
+static int install_signal(int n,void (*f)(int));
33
+
34
+mydata_t *mydata_init(void);
35
+void mydata_free(mydata_t *mydata);
36
+int main_loop_iteration(mydata_t *mydata);
37
+
38
+int
39
+main(int argc, char *argv[])
40
+{
41
+        mydata_t *mydata;
42
+        if((mydata=mydata_init())==NULL) {
43
+                DEBUG_FPRINTF((stderr,"Couldn't init\n"));
44
+                return(-1); /* couldn't init */
45
+        }
46
+        flag_sigint=0;
47
+        install_signal(SIGINT,sigint);
48
+        while(flag_sigint==0 && mydata->flag_exit==0 && mydata->boxui!=NULL) {
49
+#ifdef EMSCRIPTEN
50
+                emscripten_set_main_loop_arg((void (*)(void *))main_loop_iteration,(void *) mydata,boxui_getfps(mydata->boxui),1);
51
+#else
52
+                main_loop_iteration(mydata);
53
+#endif
54
+        }
55
+        mydata_free(mydata),mydata=NULL;
56
+        return(0);
57
+}
58
+
59
+static int
60
+install_signal(int n,void (*f)(int))
61
+{
62
+#ifndef LINUX
63
+        return(-1);
64
+#else
65
+        struct sigaction sact;
66
+        sact.sa_handler=f;
67
+        sigemptyset(&sact.sa_mask);
68
+        sact.sa_flags=0;
69
+        return(sigaction(n,&sact,0));
70
+#endif
71
+}
72
+
73
+static void
74
+sigint(int n)
75
+{
76
+        flag_sigint++;
77
+}
78
+
79
+mydata_t *
80
+mydata_init(void)
81
+{
82
+        boxui_t *boxui;
83
+        mydata_t *mydata;
84
+        char *p;
85
+        if((mydata=malloc(sizeof(mydata_t)))==NULL)
86
+                return(NULL);
87
+        memset(mydata,0,sizeof(mydata_t));
88
+        if((mydata->boxui=boxui=boxui_init("Presto! Sight-Reading - Annotator",DEFAULT_SCREENW,DEFAULT_SCREENH,0))==NULL
89
+          || boxui_setuserptr(boxui,mydata)!=0) {
90
+                mydata_free(mydata),mydata=NULL;
91
+                return(NULL);
92
+        }
93
+        /* initial UI config */
94
+        p=boxui_add(boxui,_F,_L,"label:.l","-text \"(Here goes the music sheet)\"");
95
+        boxui_pack(boxui,_F,_L,p,"-side top -fill both -expand true");
96
+        return(mydata);
97
+}
98
+
99
+void
100
+mydata_free(mydata_t *mydata)
101
+{
102
+        boxui_t *boxui;
103
+        if(mydata==NULL)
104
+                return;
105
+        if((boxui=mydata->boxui)!=NULL) {
106
+                boxui_setuserptr(boxui,NULL);
107
+                boxui_free(boxui),boxui=NULL,mydata->boxui=NULL;
108
+        }
109
+        free(mydata),mydata=NULL;
110
+        return;
111
+}
112
+
113
+int
114
+main_loop_iteration(mydata_t *mydata)
115
+{
116
+        boxui_t *boxui;
117
+        SDL_Event event;
118
+        int keycode,neww,newh;
119
+        char *actionstr,*actionparams;
120
+        if(mydata==NULL || (boxui=mydata->boxui)==NULL)
121
+                return(-1);
122
+        boxui_tick(boxui);
123
+        boxui_refreshevents(boxui);
124
+        while(boxui_getevent(boxui,&event)==0) {
125
+                /* standard events */
126
+                if(boxui_event_isquit(boxui,&event))
127
+                        mydata->flag_exit=1;
128
+                if(boxui_event_iskeydown(boxui,&event,&keycode) && keycode==SDLK_ESCAPE)
129
+                        mydata->flag_exit=1;
130
+                if(boxui_event_isresize(boxui,&event,&neww,&newh))
131
+                        boxui_resize(boxui,neww,newh);
132
+        }
133
+        while((actionstr=boxui_getactionstr(boxui,&actionparams))!=NULL) {
134
+                if(strcmp(actionstr,"exit")==0)
135
+                        mydata->flag_exit=1;
136
+        }
137
+        return(0);
138
+}
139
+