2 * (C) David Olofson, 2003, 2006
3 * modified by the pineapple team, 2009
11 #include "pineapple.h"
12 #include "filetypes.h"
15 static SDL_Surface
*screen
;
16 static SDL_Surface
*font
= NULL
;
17 static Uint32 boxcolor
;
23 #define SP 2 //spacing
24 #define BOXW 1 //box width
28 // these aren't #define's because doing this in the preprocessor:
29 // #define COLW = (WINW/3)-3
36 int main(int argc
, char *args
[]){
39 //------------------------------------------------------------------\\
41 //------------------------------------------------------------------//
43 tune
= pt_empty_tune();
47 if(SDL_Init(SDL_INIT_VIDEO
)!=0)
51 colh
= WINH
-voffs
-SP
-BOXW
;
54 signal(SIGTERM
,breakhandler
);
55 signal(SIGINT
,breakhandler
);
57 screen
= SDL_SetVideoMode(WINW
,WINH
,32,SDL_SWSURFACE
);
59 fprintf(stderr
,"video init failed");
63 fprintf(stdout
,"initialized the surface\n");
66 boxcolor
= SDL_MapRGB(screen
->format
, 255, 0, 255);
67 SDL_WM_SetCaption("pineapple-tracker","pineapple.ico");
68 if(gui_open(screen
) != 0){
69 fprintf(stderr
, "Couldn't start GUI!\n");
77 //last_tick=SDL_GetTicks();
80 tick
= SDL_GetTicks();
81 //int dt = tick - last_tick;
84 /* Handle GUI events */
85 while(SDL_PollEvent(&ev
)){
90 handle_key_normal(&ev
);
112 //update_main(screen);
113 if((SDL_GetTicks() - tick
) < 1000/FPS
){
114 SDL_Delay( (1000/FPS
) - (SDL_GetTicks() - tick
));
123 static void breakhandler(int a
){
127 static void draw_songed(const int x
, const int y
, const int w
, const int h
){
133 &&(i
< tune
->songlen
); i
+=(FONT_CH
+2))
136 snprintf(buf
, sizeof(buf
),
137 "%02x:__ __:__ __:__ __:__", pos
);
138 gui_text(x
+SP
,i
+y
+SP
,buf
,screen
);
140 // draw a box if selected
142 gui_box(x
,i
,w
,FONT_CH
+(SP
*2),boxcolor
,screen
);
145 gui_box(x
,y
,w
,h
,boxcolor
,screen
);
148 static void draw_tracked(const int x
, const int y
, const int w
, const int h
){
149 gui_box(x
,y
,w
,h
,boxcolor
,screen
);
152 static void draw_instred(const int x
, const int y
, const int w
, const int h
){
153 gui_box(x
,y
,w
,h
,boxcolor
,screen
);
156 static void draw_main(void){
157 gui_text(2,2,"PINEAPPLEtRACKER",screen
);
158 draw_songed(SP
,voffs
,(23*FONT_CW
)+(SP
*2),colh
);
159 draw_tracked((23*FONT_CW
)+(SP
*4)+(BOXW
*2),voffs
,(18*FONT_CW
)+(SP
*2),
161 draw_instred((41*FONT_CW
)+(SP
*7)+(BOXW
*4),voffs
,(9*FONT_CW
)+(SP
*2),
165 static void handle_key_normal(SDL_Event
*ev
){
166 switch(ev
->key
.keysym
.sym
){
174 fprintf(stderr
,"H\n");
175 fprintf(stderr
,"pos: %d, %d\n", songx
, songy
);
180 fprintf(stderr
,"J\n");
181 fprintf(stderr
,"pos: %d, %d\n", songx
, songy
);
186 fprintf(stderr
,"K\n");
187 fprintf(stderr
,"pos: %d, %d\n", songx
, songy
);
192 fprintf(stderr
,"L\n");
193 fprintf(stderr
,"pos: %d, %d\n", songx
, songy
);
245 static void update_main(SDL_Surface
*screen
){
248 //draw_songed(SP,voffs,230+(SP*2),colh);
249 //draw_tracked(230+(SP*4),voffs,100,colh);
250 //draw_instred(230+100*(SP*8),voffs,100,colh);
255 // gui_* functions //
258 void gui_bar(int x
, int y
, int w
, int h
, Uint32 c
, SDL_Surface
*dst
){
264 SDL_FillRect(dst
, &r
, SDL_MapRGB(dst
->format
, 0, 0, 0));
265 gui_box(x
, y
, w
, h
, c
, dst
);
268 void gui_box(int x
, int y
, int w
, int h
, Uint32 c
, SDL_Surface
*dst
){
274 SDL_FillRect(dst
, &r
, c
);
280 SDL_FillRect(dst
, &r
, c
);
286 SDL_FillRect(dst
, &r
, c
);
292 SDL_FillRect(dst
, &r
, c
);
301 void gui_close(void){
302 SDL_FreeSurface(font
);
306 SDL_Surface
*gui_load_image(const char *fn
){
308 SDL_Surface
*img
= SDL_LoadBMP(fn
);
312 cvt
= SDL_DisplayFormat(img
);
313 SDL_FreeSurface(img
);
317 int gui_open(SDL_Surface
*scrn
){
319 font
= gui_load_image("font.bmp");
321 fprintf(stderr
, "Couldn't load font!\n");
324 SDL_EnableKeyRepeat(250, 25);
325 //memset(activity, 0, sizeof(activity));
329 void gui_refresh(void){
333 void gui_text(int x
, int y
, const char *txt
, SDL_Surface
*dst
){
336 const char *stxt
= txt
;
344 case 0: /* terminator */
346 case '\n': /* newline */
356 case '\001': /* red highlight */
357 case '\002': /* green highlight */
358 case '\003': /* yellow highlight */
359 case '\004': /* blue highlight */
360 case '\005': /* purple highlight */
361 case '\006': /* cyan highlight */
362 case '\007': /* white highlight */
368 case '\021': /* red bullet */
369 case '\022': /* green bullet */
370 case '\023': /* yellow bullet */
371 case '\024': /* blue bullet */
372 case '\025': /* purple bullet */
373 case '\026': /* cyan bullet */
374 case '\027': /* white bullet */
377 int hlr
= c
& 1 ? 255 : 0;
378 int hlg
= c
& 2 ? 255 : 0;
379 int hlb
= c
& 4 ? 255 : 0;
380 Uint32 hlc
= SDL_MapRGB(dst
->format
, hlr
, hlg
, hlb
);
385 SDL_FillRect(dst
, &r
,
386 SDL_MapRGB(dst
->format
, 0, 0, 0));
392 SDL_FillRect(dst
, &r
, hlc
);
396 default: /* printables */
399 if(c
< ' ' || c
> 127)
402 sr
.x
= (c
% (font
->w
/ FONT_CW
)) * FONT_CW
;
403 sr
.y
= (c
/ (font
->w
/ FONT_CW
)) * FONT_CH
;
406 SDL_BlitSurface(font
, &sr
, dst
, &dr
);
422 case 0: /* terminator */
424 case '\n': /* newline */
434 case '\001': /* red highlight */
435 case '\002': /* green highlight */
436 case '\003': /* yellow highlight */
437 case '\004': /* blue highlight */
438 case '\005': /* purple highlight */
439 case '\006': /* cyan highlight */
440 case '\007': /* white highlight */
442 int hlr
= c
& 1 ? 255 : 0;
443 int hlg
= c
& 2 ? 255 : 0;
444 int hlb
= c
& 4 ? 255 : 0;
445 Uint32 hlc
= SDL_MapRGB(screen
->format
, hlr
, hlg
, hlb
);
451 gui_box(x
- 2, y
- 2,
452 FONT_CW
* hlw
+ 2, FONT_CH
+ 2,
456 default: /* printables */