diff options
Diffstat (limited to 'utils/wpseditor/libwps/src/api.c')
-rw-r--r-- | utils/wpseditor/libwps/src/api.c | 268 |
1 files changed, 268 insertions, 0 deletions
diff --git a/utils/wpseditor/libwps/src/api.c b/utils/wpseditor/libwps/src/api.c new file mode 100644 index 0000000000..485efa8e00 --- /dev/null +++ b/utils/wpseditor/libwps/src/api.c | |||
@@ -0,0 +1,268 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include "sound.h" | ||
4 | #include "api.h" | ||
5 | #include "proxy.h" | ||
6 | #include "dummies.h" | ||
7 | #include "scroll_engine.h" | ||
8 | #include "wpsstate.h" | ||
9 | #include <string.h> | ||
10 | |||
11 | struct proxy_api *xapi; | ||
12 | |||
13 | void get_current_vp(struct viewport_api *avp); | ||
14 | /************************************************************* | ||
15 | |||
16 | *************************************************************/ | ||
17 | #ifdef HAVE_LCD_BITMAP | ||
18 | void screen_clear_area(struct screen * display, int xstart, int ystart, | ||
19 | int width, int height) { | ||
20 | display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); | ||
21 | display->fillrect(xstart, ystart, width, height); | ||
22 | display->set_drawmode(DRMODE_SOLID); | ||
23 | } | ||
24 | #endif | ||
25 | |||
26 | bool load_wps_backdrop(char* filename) { | ||
27 | return xapi->load_wps_backdrop(filename); | ||
28 | } | ||
29 | |||
30 | bool load_remote_wps_backdrop(char* filename) { | ||
31 | return xapi->load_remote_wps_backdrop(filename); | ||
32 | } | ||
33 | |||
34 | int read_bmp_file(const char* filename,struct bitmap *bm, int maxsize,int format) { | ||
35 | if (!xapi->read_bmp_file) | ||
36 | { | ||
37 | DEBUGF1("can't read bmp file! NULL api!\n"); | ||
38 | return -1; | ||
39 | } | ||
40 | bm->format = 3;//FORMAT_ANY? | ||
41 | bm->data = (unsigned char*)malloc(255); | ||
42 | memset(bm->data,0,255); | ||
43 | strcpy((char*)bm->data,filename); | ||
44 | //bm->data[strlen(filename)] = '\0'; | ||
45 | xapi->read_bmp_file(filename,&bm->width, &bm->height); | ||
46 | return 1; | ||
47 | } | ||
48 | |||
49 | bool load_wps_backdrop2(char* filename) { | ||
50 | DEBUGF1("load_wps_backdrop(char* filename='%s')",filename); | ||
51 | return true; | ||
52 | } | ||
53 | |||
54 | bool load_remote_wps_backdrop2(char* filename) { | ||
55 | DEBUGF1("load_remote_wps_backdrop2(char* filename='%s')",filename); | ||
56 | return true; | ||
57 | } | ||
58 | |||
59 | void stop_scroll() { | ||
60 | DEBUGF3("stop_scroll\n"); | ||
61 | return; | ||
62 | } | ||
63 | |||
64 | void puts_scroll(int x, int y, const unsigned char *string) { | ||
65 | DEBUGF2("puts_scroll(int x=%d, int y=%d, const unsigned char *string='%s'\n",x,y,string); | ||
66 | } | ||
67 | |||
68 | void putsxy(int x, int y, const unsigned char *str) { | ||
69 | DEBUGF2("putsxy(int =%d, int y=%d, const unsigned char *str='%s')\n",x,y,str); | ||
70 | } | ||
71 | |||
72 | void lcd_update() { | ||
73 | DEBUGF3("update\n"); | ||
74 | } | ||
75 | |||
76 | void clear_viewport(int x, int y, int w, int h, int color) { | ||
77 | DEBUGF3("clear_viewport(int x=%d, int y=%d, int w=%d, int h=%d, int color=%d)\n", x, y, w, h, color); | ||
78 | }; | ||
79 | |||
80 | int getstringsize(const unsigned char *str, int *w, int *h) { | ||
81 | //DEBUGF1("getstringsize(const unsigned char *str=\"%s\", int *w=%d, int *h=%d \n",str,*w,*h); | ||
82 | *w=strlen((char*)str)*sysfont.maxwidth; | ||
83 | *h=sysfont.height; | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | void set_wpsstate(struct wpsstate state){ | ||
88 | sysfont.height = state.fontheight; | ||
89 | sysfont.maxwidth = state.fontwidth; | ||
90 | global_settings.volume = state.volume; | ||
91 | battery_percent = state.battery_level; | ||
92 | _audio_status = state.audio_status; | ||
93 | } | ||
94 | |||
95 | void set_trackstate(struct trackstate state){ | ||
96 | gui_wps[0].state->id3->title = state.title; | ||
97 | gui_wps[0].state->id3->artist = state.artist; | ||
98 | gui_wps[0].state->id3->album = state.album; | ||
99 | gui_wps[0].state->id3->elapsed = state.elapsed; | ||
100 | gui_wps[0].state->id3->length = state.length; | ||
101 | } | ||
102 | |||
103 | void set_next_trackstate(struct trackstate state) | ||
104 | { | ||
105 | gui_wps[0].state->nid3->title = state.title; | ||
106 | gui_wps[0].state->nid3->artist = state.artist; | ||
107 | gui_wps[0].state->nid3->album = state.album; | ||
108 | gui_wps[0].state->nid3->elapsed = state.elapsed; | ||
109 | gui_wps[0].state->nid3->length = state.length; | ||
110 | } | ||
111 | |||
112 | enum api_playmode playmodes[PLAYMODES_NUM] = { | ||
113 | API_STATUS_PLAY, | ||
114 | API_STATUS_STOP, | ||
115 | API_STATUS_PAUSE, | ||
116 | API_STATUS_FASTFORWARD, | ||
117 | API_STATUS_FASTBACKWARD | ||
118 | }; | ||
119 | |||
120 | const char *playmodeNames[] = { | ||
121 | "Play", "Stop", "Pause", "FastForward", "FastBackward" | ||
122 | }; | ||
123 | |||
124 | |||
125 | void set_audio_status(int status){ | ||
126 | DEBUGF1("%s",playmodeNames[status]); | ||
127 | switch(status){ | ||
128 | case API_STATUS_PLAY: | ||
129 | _audio_status = AUDIO_STATUS_PLAY; | ||
130 | status_set_ffmode(STATUS_PLAY); | ||
131 | break; | ||
132 | case API_STATUS_STOP: | ||
133 | _audio_status = 0; | ||
134 | status_set_ffmode(STATUS_STOP); | ||
135 | break; | ||
136 | case API_STATUS_PAUSE: | ||
137 | _audio_status = AUDIO_STATUS_PAUSE; | ||
138 | status_set_ffmode(STATUS_PLAY); | ||
139 | break; | ||
140 | case API_STATUS_FASTFORWARD: | ||
141 | status_set_ffmode(STATUS_FASTFORWARD); | ||
142 | break; | ||
143 | case API_STATUS_FASTBACKWARD: | ||
144 | status_set_ffmode(STATUS_FASTBACKWARD); | ||
145 | break; | ||
146 | default: | ||
147 | DEBUGF1("ERR: Unknown status"); | ||
148 | } | ||
149 | } | ||
150 | |||
151 | void test_api(struct proxy_api *api) { | ||
152 | if (!api->stop_scroll) | ||
153 | api->stop_scroll=stop_scroll; | ||
154 | if (!api->set_viewport) | ||
155 | api->set_viewport=lcd_set_viewport; | ||
156 | if (!api->clear_viewport) | ||
157 | api->clear_viewport=clear_viewport; | ||
158 | if (!api->getstringsize) | ||
159 | api->getstringsize=getstringsize; | ||
160 | if (!api->getwidth) | ||
161 | api->getwidth=lcd_getwidth; | ||
162 | if (!api->getheight) | ||
163 | api->getheight=lcd_getheight; | ||
164 | if (!api->set_drawmode) | ||
165 | api->set_drawmode=lcd_set_drawmode; | ||
166 | if (!api->puts_scroll) | ||
167 | api->puts_scroll=puts_scroll; | ||
168 | if (!api->update) | ||
169 | api->update=lcd_update; | ||
170 | if (!api->clear_display) | ||
171 | api->clear_display=lcd_clear_display; | ||
172 | if (!api->getfont) | ||
173 | api->getfont=lcd_getfont; | ||
174 | if (!api->putsxy) | ||
175 | api->putsxy=putsxy; | ||
176 | |||
177 | #if LCD_DEPTH > 1 | ||
178 | if (!api->get_foreground) | ||
179 | api->get_foreground=lcd_get_foreground; | ||
180 | if (!api->get_background) | ||
181 | api->get_background=lcd_get_background; | ||
182 | #endif | ||
183 | if (!api->load_remote_wps_backdrop) | ||
184 | api->load_remote_wps_backdrop = load_remote_wps_backdrop2; | ||
185 | if (!api->load_wps_backdrop) | ||
186 | api->load_wps_backdrop = load_wps_backdrop2; | ||
187 | //dbgf = printf; | ||
188 | } | ||
189 | |||
190 | /************************************************************** | ||
191 | |||
192 | **************************************************************/ | ||
193 | |||
194 | int set_api(struct proxy_api* api) { | ||
195 | if (api->debugf) | ||
196 | dbgf = api->debugf; | ||
197 | screens[0].screen_type=SCREEN_MAIN; | ||
198 | screens[0].lcdwidth=LCD_WIDTH; | ||
199 | screens[0].lcdheight=LCD_HEIGHT; | ||
200 | screens[0].depth=LCD_DEPTH; | ||
201 | #ifdef HAVE_LCD_COLOR | ||
202 | screens[0].is_color=true; | ||
203 | #else | ||
204 | screens[0].is_color=false; | ||
205 | #endif | ||
206 | if (api->getwidth) | ||
207 | screens[0].getwidth = api->getwidth; | ||
208 | if (api->stop_scroll) | ||
209 | screens[0].stop_scroll=api->stop_scroll; | ||
210 | screens[0].scroll_stop = lcd_scroll_stop; | ||
211 | if (api->set_viewport) | ||
212 | screens[0].set_viewport=api->set_viewport; | ||
213 | if (api->clear_viewport) | ||
214 | screens[0].clear_viewport=lcd_clear_viewport; | ||
215 | if (api->getstringsize) | ||
216 | screens[0].getstringsize=api->getstringsize; | ||
217 | if (api->getwidth) | ||
218 | screens[0].getwidth=api->getwidth; | ||
219 | if (api->getheight) | ||
220 | screens[0].getheight=api->getheight; | ||
221 | if (api->set_drawmode) | ||
222 | screens[0].set_drawmode=api->set_drawmode; | ||
223 | if (api->fillrect) | ||
224 | screens[0].fillrect=api->fillrect; | ||
225 | if (api->puts_scroll) | ||
226 | screens[0].puts_scroll=api->puts_scroll; | ||
227 | if (api->transparent_bitmap_part) | ||
228 | screens[0].transparent_bitmap_part=api->transparent_bitmap_part; | ||
229 | if (api->update) | ||
230 | screens[0].update=api->update; | ||
231 | if (api->clear_display) | ||
232 | screens[0].clear_display=api->clear_display; | ||
233 | if (api->getfont) | ||
234 | screens[0].getfont=api->getfont; | ||
235 | if (api->hline) | ||
236 | screens[0].hline=api->hline; | ||
237 | if (api->vline) | ||
238 | screens[0].vline=api->vline; | ||
239 | if (api->drawpixel) | ||
240 | screens[0].drawpixel=api->drawpixel; | ||
241 | if (api->putsxy) | ||
242 | screens[0].putsxy=api->putsxy; | ||
243 | #if LCD_DEPTH > 1 | ||
244 | if (api->get_foreground) | ||
245 | screens[0].get_foreground=api->get_foreground; | ||
246 | if (api->get_background) | ||
247 | screens[0].get_background=api->get_background; | ||
248 | #endif | ||
249 | |||
250 | screens[0].bitmap_part = api->bitmap_part; | ||
251 | /************************** | ||
252 | * OUT * | ||
253 | **************************/ | ||
254 | api->get_model_name = get_model_name; | ||
255 | api->get_current_vp = get_current_vp; | ||
256 | api->set_wpsstate = set_wpsstate; | ||
257 | api->set_trackstate = set_trackstate; | ||
258 | api->set_next_trackstate= set_next_trackstate; | ||
259 | api->set_audio_status= set_audio_status; | ||
260 | xapi = api; | ||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | |||
265 | |||
266 | |||
267 | |||
268 | |||