3 #pragma RcB2 LINK "-lSDL"
9 #include "../sprites/flame.c"
10 #include "../palpic.h"
11 const struct palpic
* pic
= &flame
.header
;
16 static void init_video() {
17 SDL_Init(SDL_INIT_VIDEO
);
18 surface
= SDL_SetVideoMode(VMODE_W
, VMODE_H
, 32, SDL_RESIZABLE
| SDL_HWPALETTE
);
19 video
.mem
= surface
->pixels
;
20 video
.pitch
= surface
->pitch
;
21 video
.width
= VMODE_W
;
22 video
.height
= VMODE_H
;
28 int fullscreen_active
;
30 #include "../sdl_rgb.h"
32 static void update_screen() {
33 uint_fast16_t w
= palpic_getspritewidth(pic
);
34 uint_fast16_t h
= palpic_getspriteheight(pic
);
35 SDL_UpdateRect(surface
, 0, 0, w
* SCALE
, h
*SCALE
);
39 uint_fast16_t x
, w
= palpic_getspritewidth(pic
);
40 uint_fast16_t y
, h
= palpic_getspriteheight(pic
);
41 sdl_rgb_t
*pix
, *ptr
= pix
= (sdl_rgb_t
*) surface
->pixels
;
42 uint_fast32_t pitch
= surface
->pitch
/ 4, inc
= pitch
- w
*SCALE
;
43 for(y
=0;y
<h
*SCALE
;y
++) {
44 for(x
=0;x
<w
*SCALE
;x
++) *ptr
++ = SRGB(0,0,0);
49 static float rounddot5(float f
) {
51 if (f
-r
>= 0.5) return r
+ 0.5;
55 static void sprint_tag(char* buf
) {
56 sprintf(buf
, "[%d] = { %.1f, %.1f },\n", activesprite
, rounddot5(tag
.x
/ SCALE
), rounddot5(tag
.y
/ SCALE
));
59 static void print_spriteinfo() {
63 snprintf(buf
, sizeof buf
, "sprite %d/%u mouse: %u,%u scale:%dX ::: %s",
64 activesprite
, palpic_getspritecount(pic
),
65 (int) (mousepos
.x
/ SCALE
), (int) (mousepos
.y
/ SCALE
), SCALE
, buf2
);
66 SDL_WM_SetCaption(buf
, 0);
70 static void print_tag() {
76 /* draws a grid around each pixel. if SCALE == 1, the entire sprite will be overpainted */
77 static void draw_grid() {
78 int x
, w
= palpic_getspritewidth(pic
);
79 int y
, h
= palpic_getspriteheight(pic
);
80 sdl_rgb_t
*pix
= (sdl_rgb_t
*) surface
->pixels
;
81 unsigned pitch
= surface
->pitch
/ 4;
82 /* draw horizontal lines */
83 for(y
= 0; y
<= h
* SCALE
; y
+= SCALE
) for(x
= 0; x
<= w
* SCALE
; x
++)
84 pix
[y
* pitch
+ x
] = SRGB(255,255,255);
85 /* draw vertical lines */
86 for(y
= 0; y
<= h
* SCALE
; y
++) for(x
= 0; x
<= w
* SCALE
; x
+= SCALE
)
87 pix
[y
* pitch
+ x
] = SRGB(255,0,255);
90 static int grid_enabled
= 0;
93 int x
, w
= palpic_getspritewidth(pic
);
94 int y
, h
= palpic_getspriteheight(pic
);
95 sdl_rgb_t
*pix
= (sdl_rgb_t
*) surface
->pixels
;
96 unsigned pitch
= surface
->pitch
/ 4;
100 blit_sprite(0, 0, &video
, SCALE
, pic
, activesprite
, 0);
102 if(grid_enabled
) draw_grid();
104 if(tag
.x
>= 0 && tag
.y
>= 0)
105 pix
[(int) (tag
.y
* pitch
) + (int) (tag
.x
)] = SRGB(255, 0, 0);
110 static void switch_sprite(int dir
) {
112 if(activesprite
< 0) activesprite
= pic
->spritecount
- 1;
113 else if(activesprite
>= pic
->spritecount
) activesprite
= 0;
119 static void tick(unsigned need_redraw
) {
120 if(need_redraw
) draw();
125 //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
126 SDL_EnableKeyRepeat(100, 20);
130 unsigned need_redraw
= 0;
131 while (SDL_PollEvent(&sdl_event
)) {
132 switch (sdl_event
.type
) {
133 case SDL_MOUSEMOTION
:
134 mousepos
.x
= sdl_event
.motion
.x
;
135 mousepos
.y
= sdl_event
.motion
.y
;
138 case SDL_MOUSEBUTTONDOWN
:
139 mousepos
.x
= sdl_event
.button
.x
;
140 mousepos
.y
= sdl_event
.button
.y
;
141 if(sdl_event
.button
.button
== SDL_BUTTON_WHEELUP
) {
143 if(SCALE
* palpic_getspritewidth(pic
) < VMODE_W
&&
144 SCALE
* palpic_getspriteheight(pic
) < VMODE_H
); else SCALE
--;
145 } else if(sdl_event
.button
.button
== SDL_BUTTON_WHEELDOWN
) {
149 if (SCALE
== 0) SCALE
= 1;
155 case SDL_MOUSEBUTTONUP
:
156 mousepos
.x
= sdl_event
.button
.x
;
157 mousepos
.y
= sdl_event
.button
.y
;
162 // restore desktop video mode correctly...
163 if(fullscreen_active
)
164 SDL_WM_ToggleFullScreen(surface
);
167 switch(sdl_event
.key
.keysym
.sym
) {
169 grid_enabled
= !grid_enabled
;
174 case SDLK_w
: case SDLK_a
: case SDLK_s
: case SDLK_d
:
180 if((sdl_event
.key
.keysym
.mod
& KMOD_LALT
) ||
181 (sdl_event
.key
.keysym
.mod
& KMOD_RALT
)) {
182 SDL_WM_ToggleFullScreen(surface
);
183 fullscreen_active
= !fullscreen_active
;
199 switch(sdl_event
.key
.keysym
.sym
) {
200 case SDLK_w
: case SDLK_a
: case SDLK_s
: case SDLK_d
: