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
34 //pineapple_tune tune;
36 int main(int argc
, char **argv
){
39 //------------------------------------------------------------------\\
41 //------------------------------------------------------------------//
43 tune
= pt_empty_tune();
45 tune
= lft_loadfile(argv
[1]);
48 if(SDL_Init(SDL_INIT_VIDEO
)!=0)
52 colh
= WINH
-voffs
-SP
-BOXW
;
55 signal(SIGTERM
,breakhandler
);
56 signal(SIGINT
,breakhandler
);
58 screen
= SDL_SetVideoMode(WINW
,WINH
,32,SDL_SWSURFACE
);
60 fprintf(stderr
,"video init failed");
64 fprintf(stdout
,"initialized the surface\n");
67 boxcolor
= SDL_MapRGB(screen
->format
, 255, 0, 255);
68 SDL_WM_SetCaption("pineapple-tracker","pineapple.ico");
69 if(gui_open(screen
) != 0){
70 fprintf(stderr
, "Couldn't start GUI!\n");
78 //last_tick=SDL_GetTicks();
81 tick
= SDL_GetTicks();
82 //int dt = tick - last_tick;
85 /* Handle GUI events */
86 while(SDL_PollEvent(&ev
)){
91 handle_key_normal(&ev
);
113 //update_main(screen);
114 if((SDL_GetTicks() - tick
) < 1000/FPS
){
115 SDL_Delay( (1000/FPS
) - (SDL_GetTicks() - tick
));
124 static void breakhandler(int a
){
128 static void draw_songed(const int x
, const int y
, const int w
, const int h
){
138 &&(j
< tune
->songlen
);
143 snprintf(buf
, sizeof(buf
), "%02x| ", j
);
145 /*for(i=0; (i+y < h) &&(i < h/FONT_CH) &&(i < tune->songlen); i+=(FONT_CH))
150 snprintf(buf, sizeof(buf),
151 "%02x:__ __:__ __:__ __:__", pos);
153 gui_text(x
+SP
,i
+y
+SP
,buf
,screen
);
154 for(k
= 0; k
< 4; k
++){
155 snprintf(buf
, sizeof(buf
),
156 "%02x:%02x", tune
->sng
[j
].track
[k
], tune
->sng
[j
].transp
[k
]);
157 gui_text(x
+(space
+=40),i
+y
+SP
,buf
,screen
);
160 fprintf(stderr
,"tune->songlen: %i\n", tune
->songlen
);
161 fprintf(stderr
,"i: %i\n", i
);
162 fprintf(stderr
,"j: %i\n", j
);
164 fprintf(stderr
, "i: %i\n", i
);
165 fprintf(stderr
, "pos: %i\n", pos
);
166 fprintf(stderr
, "songlen: %i\n", tune
->songlen
);
168 // draw a box if selected
170 gui_box(x
,i
,w
,FONT_CH
+(SP
*2),boxcolor
,screen
);
174 gui_box(x
,y
,w
,h
,boxcolor
,screen
);
177 static void draw_tracked(const int x
, const int y
, const int w
, const int h
){
178 gui_box(x
,y
,w
,h
,boxcolor
,screen
);
181 static void draw_instred(const int x
, const int y
, const int w
, const int h
){
182 gui_box(x
,y
,w
,h
,boxcolor
,screen
);
185 static void draw_main(void){
186 gui_text(2,2,"PINEAPPLEtRACKER",screen
);
187 draw_songed(SP
,voffs
,(23*FONT_CW
)+(SP
*2),colh
);
188 draw_tracked((23*FONT_CW
)+(SP
*4)+(BOXW
*2),voffs
,(18*FONT_CW
)+(SP
*2),
190 draw_instred((41*FONT_CW
)+(SP
*7)+(BOXW
*4),voffs
,(9*FONT_CW
)+(SP
*2),
194 static void handle_key_normal(SDL_Event
*ev
){
195 switch(ev
->key
.keysym
.sym
){
203 fprintf(stderr
,"H\n");
204 fprintf(stderr
,"pos: %d, %d\n", songx
, songy
);
209 fprintf(stderr
,"J\n");
210 fprintf(stderr
,"pos: %d, %d\n", songx
, songy
);
215 fprintf(stderr
,"K\n");
216 fprintf(stderr
,"pos: %d, %d\n", songx
, songy
);
221 fprintf(stderr
,"L\n");
222 fprintf(stderr
,"pos: %d, %d\n", songx
, songy
);
274 //static void update_main(SDL_Surface *screen){
277 //draw_songed(SP,voffs,230+(SP*2),colh);
278 //draw_tracked(230+(SP*4),voffs,100,colh);
279 //draw_instred(230+100*(SP*8),voffs,100,colh);
284 // gui_* functions //
287 void gui_bar(int x
, int y
, int w
, int h
, Uint32 c
, SDL_Surface
*dst
){
293 SDL_FillRect(dst
, &r
, SDL_MapRGB(dst
->format
, 0, 0, 0));
294 gui_box(x
, y
, w
, h
, c
, dst
);
297 void gui_box(int x
, int y
, int w
, int h
, Uint32 c
, SDL_Surface
*dst
){
303 SDL_FillRect(dst
, &r
, c
);
309 SDL_FillRect(dst
, &r
, c
);
315 SDL_FillRect(dst
, &r
, c
);
321 SDL_FillRect(dst
, &r
, c
);
330 void gui_close(void){
331 SDL_FreeSurface(font
);
335 SDL_Surface
*gui_load_image(const char *fn
){
337 SDL_Surface
*img
= SDL_LoadBMP(fn
);
341 cvt
= SDL_DisplayFormat(img
);
342 SDL_FreeSurface(img
);
346 int gui_open(SDL_Surface
*scrn
){
348 font
= gui_load_image("font.bmp");
350 fprintf(stderr
, "Couldn't load font!\n");
353 SDL_EnableKeyRepeat(250, 25);
354 //memset(activity, 0, sizeof(activity));
358 void gui_refresh(void){
362 void gui_text(int x
, int y
, const char *txt
, SDL_Surface
*dst
){
365 const char *stxt
= txt
;
373 case 0: /* terminator */
375 case '\n': /* newline */
385 case '\001': /* red highlight */
386 case '\002': /* green highlight */
387 case '\003': /* yellow highlight */
388 case '\004': /* blue highlight */
389 case '\005': /* purple highlight */
390 case '\006': /* cyan highlight */
391 case '\007': /* white highlight */
397 case '\021': /* red bullet */
398 case '\022': /* green bullet */
399 case '\023': /* yellow bullet */
400 case '\024': /* blue bullet */
401 case '\025': /* purple bullet */
402 case '\026': /* cyan bullet */
403 case '\027': /* white bullet */
406 int hlr
= c
& 1 ? 255 : 0;
407 int hlg
= c
& 2 ? 255 : 0;
408 int hlb
= c
& 4 ? 255 : 0;
409 Uint32 hlc
= SDL_MapRGB(dst
->format
, hlr
, hlg
, hlb
);
414 SDL_FillRect(dst
, &r
,
415 SDL_MapRGB(dst
->format
, 0, 0, 0));
421 SDL_FillRect(dst
, &r
, hlc
);
425 default: /* printables */
428 if(c
< ' ' || c
> 127)
431 sr
.x
= (c
% (font
->w
/ FONT_CW
)) * FONT_CW
;
432 sr
.y
= (c
/ (font
->w
/ FONT_CW
)) * FONT_CH
;
435 SDL_BlitSurface(font
, &sr
, dst
, &dr
);
451 case 0: /* terminator */
453 case '\n': /* newline */
463 case '\001': /* red highlight */
464 case '\002': /* green highlight */
465 case '\003': /* yellow highlight */
466 case '\004': /* blue highlight */
467 case '\005': /* purple highlight */
468 case '\006': /* cyan highlight */
469 case '\007': /* white highlight */
471 int hlr
= c
& 1 ? 255 : 0;
472 int hlg
= c
& 2 ? 255 : 0;
473 int hlb
= c
& 4 ? 255 : 0;
474 Uint32 hlc
= SDL_MapRGB(screen
->format
, hlr
, hlg
, hlb
);
480 gui_box(x
- 2, y
- 2,
481 FONT_CW
* hlw
+ 2, FONT_CH
+ 2,
485 default: /* printables */