216 |
if (visible > 0) { |
if (visible > 0) { |
217 |
grab_bg(); |
grab_bg(); |
218 |
|
|
219 |
GC gc(screen); |
GC gc(screen->get_surface()); |
220 |
blit (gc, x-hotx, y-hoty, cursor); |
blit (gc, x-hotx, y-hoty, cursor); |
221 |
screen->update_rect (get_rect()); |
screen->update_rect (get_rect()); |
222 |
|
|
230 |
if (visible > 0 && changedp) |
if (visible > 0 && changedp) |
231 |
{ |
{ |
232 |
if (background) { |
if (background) { |
233 |
screen->blit (oldx-hotx, oldy-hoty, background); |
GC gc(screen->get_surface()); |
234 |
|
blit (gc, oldx-hotx, oldy-hoty, background); |
235 |
screen->update_rect (get_oldrect()); |
screen->update_rect (get_oldrect()); |
236 |
} |
} |
237 |
draw(); |
draw(); |
258 |
{ |
{ |
259 |
if (--visible == 0) { |
if (--visible == 0) { |
260 |
changedp = true; |
changedp = true; |
261 |
if (background) |
if (background) { |
262 |
screen->blit(oldx-hotx, oldy-hoty, background); |
GC gc(screen->get_surface()); |
263 |
|
blit (gc, oldx-hotx, oldy-hoty, background); |
264 |
|
} |
265 |
delete background; |
delete background; |
266 |
background=0; |
background=0; |
267 |
} |
} |
287 |
MouseCursor::grab_bg () |
MouseCursor::grab_bg () |
288 |
{ |
{ |
289 |
if (background == 0) |
if (background == 0) |
290 |
background = Grab(screen, get_rect()); |
background = Grab(screen->get_surface(), get_rect()); |
291 |
else |
else { |
292 |
background->blit(0,0, screen, get_rect()); |
GC gc(background); |
293 |
|
blit (gc, 0,0, screen->get_surface(), get_rect()); |
294 |
|
} |
295 |
oldx=x; |
oldx=x; |
296 |
oldy=y; |
oldy=y; |
297 |
} |
} |
370 |
void |
void |
371 |
video::SetPalette(const char *palname) |
video::SetPalette(const char *palname) |
372 |
{ |
{ |
373 |
Screen *scr=GetScreen(); |
if (GetColorDepth() != 8) |
|
if (scr->bipp() != 8) |
|
374 |
return; |
return; |
375 |
|
|
376 |
|
SDL_Surface *s = GetScreen()->get_surface()->get_surface(); |
377 |
string filename = enigma::FindDataFile("gfx", palname); |
string filename = enigma::FindDataFile("gfx", palname); |
378 |
ifstream f(filename.c_str()); |
ifstream f(filename.c_str()); |
379 |
|
|
396 |
// palette[255].r = 0xff; |
// palette[255].r = 0xff; |
397 |
// palette[255].g = 0; |
// palette[255].g = 0; |
398 |
// palette[255].b = 0xff; |
// palette[255].b = 0xff; |
399 |
printf ("palette: %d entries\n", n); |
SDL_SetColors (s, palette,0,n); |
|
SDL_SetColors (scr->get_surface(), palette,0,n); |
|
|
// SDL_SetColors (scr->get_surface(), &palette[255],255,1); |
|
400 |
} |
} |
401 |
|
|
402 |
int |
int |
403 |
video::GetColorDepth() |
video::GetColorDepth() |
404 |
{ |
{ |
405 |
SDL_Surface *s = GetScreen()->get_surface(); |
return GetScreen()->get_surface()->bipp(); |
|
return s->format->BitsPerPixel; |
|
406 |
} |
} |
407 |
|
|
408 |
Surface* |
Surface* |
409 |
video::BackBuffer() |
video::BackBuffer() |
410 |
{ |
{ |
411 |
if (back_buffer==0) { |
if (back_buffer==0) { |
412 |
back_buffer= Duplicate(GetScreen()); |
back_buffer= Duplicate(GetScreen()->get_surface()); |
413 |
} |
} |
414 |
return back_buffer; |
return back_buffer; |
415 |
} |
} |
519 |
|
|
520 |
void fade_alpha(FadeMode mode) |
void fade_alpha(FadeMode mode) |
521 |
{ |
{ |
522 |
const double fadesec = 0.6; |
// const double fadesec = 0.6; |
523 |
double v = 255/fadesec; |
// double v = 255/fadesec; |
524 |
|
|
525 |
px::Screen *screen = GetScreen(); |
// px::Screen *screen = GetScreen(); |
526 |
px::Surface *buffer = Duplicate(screen); |
// px::Surface *buffer = Duplicate(screen); |
527 |
double dt; |
// double dt; |
528 |
|
|
529 |
double a = mode==FADEIN ? 0 : 255; |
// double a = mode==FADEIN ? 0 : 255; |
530 |
Drawable *d = screen->get_drawable(); |
// Drawable *d = screen->get_drawable(); |
531 |
while (true) { |
// while (true) { |
532 |
Uint32 otime = SDL_GetTicks(); |
// Uint32 otime = SDL_GetTicks(); |
533 |
|
|
534 |
d->box(0,0,640,480, 0); |
// d->box(0,0,640,480, 0); |
535 |
buffer->set_alpha(int(a)); |
// buffer->set_alpha(int(a)); |
536 |
d->blit(0,0,buffer); |
// d->blit(0,0,buffer); |
537 |
screen->update_all(); |
// screen->update_all(); |
538 |
screen->flush_updates(); |
// screen->flush_updates(); |
539 |
|
|
540 |
dt = (SDL_GetTicks()-otime)/1000.0; |
// dt = (SDL_GetTicks()-otime)/1000.0; |
541 |
if (mode==FADEIN && (a+=v*dt) > 255) |
// if (mode==FADEIN && (a+=v*dt) > 255) |
542 |
break; |
// break; |
543 |
else if (mode==FADEOUT && (a-=v*dt) < 0) |
// else if (mode==FADEOUT && (a-=v*dt) < 0) |
544 |
break; |
// break; |
545 |
} |
// } |
546 |
|
|
547 |
if (mode==FADEIN) { |
// if (mode==FADEIN) { |
548 |
buffer->set_alpha(255); |
// buffer->set_alpha(255); |
549 |
d->blit(0,0,buffer); |
// d->blit(0,0,buffer); |
550 |
} else |
// } else |
551 |
d->box(0,0,640,480, 0); |
// d->box(0,0,640,480, 0); |
552 |
screen->update_all(); |
// screen->update_all(); |
553 |
screen->flush_updates(); |
// screen->flush_updates(); |
554 |
delete buffer; |
// delete buffer; |
555 |
} |
} |
556 |
} |
} |
557 |
void |
void |
558 |
video::FX_Fade(FadeMode mode) |
video::FX_Fade(FadeMode mode) |
559 |
{ |
{ |
560 |
SDL_Surface *s = GetScreen()->get_surface(); |
SDL_Surface *s = GetScreen()->get_surface()->get_surface(); |
561 |
if (s->format->palette) |
if (s->format->palette) |
562 |
fade_pal(mode); |
fade_pal(mode); |
563 |
else |
else |
576 |
double origy = originy; |
double origy = originy; |
577 |
|
|
578 |
Screen *scr = GetScreen(); |
Screen *scr = GetScreen(); |
579 |
|
GC scrgc(scr->get_surface()); |
580 |
|
|
581 |
while (rest_time > 0) |
while (rest_time > 0) |
582 |
{ |
{ |
583 |
Uint32 otime = SDL_GetTicks(); |
Uint32 otime = SDL_GetTicks(); |
585 |
Rect r(static_cast<int>(origx), |
Rect r(static_cast<int>(origx), |
586 |
static_cast<int>(origy), |
static_cast<int>(origy), |
587 |
scr->width(), scr->height()); |
scr->width(), scr->height()); |
588 |
scr->blit (r.x, r.y, newscr); |
blit (scrgc, r.x, r.y, newscr); |
589 |
|
|
590 |
scr->update_rect(r); |
scr->update_rect(r); |
591 |
scr->flush_updates(); |
scr->flush_updates(); |
614 |
double y = originy; |
double y = originy; |
615 |
|
|
616 |
Screen *scr = GetScreen(); |
Screen *scr = GetScreen(); |
617 |
|
GC scrgc(scr->get_surface()); |
618 |
|
|
619 |
Surface *oldscr = Duplicate(scr); |
Surface *oldscr = Duplicate(scr->get_surface()); |
620 |
|
|
621 |
Uint32 otime = SDL_GetTicks(); |
Uint32 otime = SDL_GetTicks(); |
622 |
double t=0; |
double t=0; |
632 |
x = (accx*t + velx)*t + originx; |
x = (accx*t + velx)*t + originx; |
633 |
y = (accy*t + vely)*t + originy; |
y = (accy*t + vely)*t + originy; |
634 |
|
|
635 |
scr->blit ((int)x-originx, (int)y, oldscr); |
blit (scrgc, (int)x-originx, (int)y, oldscr); |
636 |
scr->blit ((int)x, (int)y-originy, oldscr); |
blit (scrgc, (int)x, (int)y-originy, oldscr); |
637 |
scr->blit ((int)x-originx, (int)y-originy, oldscr); |
blit (scrgc, (int)x-originx, (int)y-originy, oldscr); |
638 |
|
|
639 |
scr->blit ((int)x, (int) y, newscr); |
blit (scrgc, (int)x, (int) y, newscr); |
640 |
|
|
641 |
scr->update_all(); |
scr->update_all(); |
642 |
scr->flush_updates(); |
scr->flush_updates(); |
643 |
} |
} |
644 |
delete oldscr; |
delete oldscr; |
645 |
scr->blit(0,0, newscr); |
blit(scrgc, 0,0, newscr); |
646 |
scr->update_all(); |
scr->update_all(); |
647 |
scr->flush_updates(); |
scr->flush_updates(); |
648 |
} |
} |
687 |
void |
void |
688 |
video::Screenshot(const char *fname) |
video::Screenshot(const char *fname) |
689 |
{ |
{ |
690 |
SDL_Surface *s = GetScreen()->get_surface(); |
SDL_Surface *s = GetScreen()->get_surface()->get_surface(); |
691 |
SDL_SaveBMP(s, fname); |
SDL_SaveBMP(s, fname); |
692 |
enigma::Log << "screenshot: "<<s->w << "x"<<s->h<<endl; |
enigma::Log << "screenshot: "<<s->w << "x"<<s->h<<endl; |
693 |
} |
} |