Ignore:
Timestamp:
May 16, 2011, 2:37:23 AM (11 years ago)
Author:
Sam Hocevar
Message:

imlib: clean up the Sprite class and get rid of the dead sprite
controller code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/imlib/sprite.cpp

    r662 r669  
    2323#include "sprite.h"
    2424
     25Sprite::Sprite(image *screen, image *visual, vec2i pos)
     26{
     27    CHECK(visual && screen);
     28    m_pos = pos;
     29    m_visual = visual;
     30    m_screen = screen;
     31    m_save = new image(visual->Size());
    2532
    26 void sprite::restore_background()
    27 { if (x+save->Size().x>=0 && y+save->Size().y>=0 && x<=xres && y<=yres)
    28       screen->PutImage(save, vec2i(x, y)); }
    29 
    30 void sprite::get_background()
    31 { if (x+visual->Size().x>=0 && y+visual->Size().y>=0 && x<=xres && y<=yres)
    32    save->PutPart(screen,vec2i(0,0), vec2i(x,y), vec2i(x+save->Size().x,y+save->Size().y)); }
    33 
    34 void sprite::draw()
    35 { if (x+visual->Size().x>=0 && y+visual->Size().y>=0 && x<=xres && y<=yres)
    36    screen->PutImage(visual, vec2i(x, y), 1); }
    37 
    38 sprite::sprite(image *Screen, image *Visual, int X, int Y)
    39 {
    40   CHECK(Visual && Screen);
    41   x=X; y=Y; visual=Visual; screen=Screen;
    42   save = new image(visual->Size());
    43   get_background();
     33    if (m_pos + visual->Size() >= 0 && m_pos < vec2i(xres, yres))
     34        m_save->PutPart(m_screen, vec2i(0,0), m_pos, m_pos + m_save->Size());
    4435}
    4536
    46 sprite::~sprite()
     37Sprite::~Sprite()
    4738{
    48   delete save;
     39    delete m_save;
    4940}
    5041
    51 void sprite_controller::add_sprite(sprite *sp)
    52 { sprites.add_end(sp); }
     42void Sprite::SetVisual(image *visual, int delete_old)
     43{
     44    if (delete_old)
     45        delete m_visual;
     46    m_visual = visual;
     47    if (m_save->Size() != visual->Size())
     48    {
     49        delete m_save;
     50        m_save = new image(visual->Size());
     51    }
    5352
    54 #define loopt(type,controll,first,inside) { controll=(type *)(first); \
    55   if (first) do { inside controll=(type *)(controll->Next()); } \
    56   while (controll!=(type *)(first)); }
    57 
    58 void sprite_controller::remove_sprites()
    59 { sprite *sp; loopt(sprite,sp,sprites.first(),sp->restore_background(); ); }
    60 
    61 void sprite_controller::put_sprites()
    62 { sprite *sp; loopt(sprite,sp,sprites.first(),sp->draw(); ); }
    63 
    64 void sprite_controller::get_backgrounds()
    65 { sprite *sp; loopt(sprite,sp,sprites.first(),sp->get_background(); ); }
    66 
    67 void sprite::change_visual(image *Visual, int delete_old)
    68 { if (delete_old)
    69     delete visual;
    70   visual=Visual;
    71   if (save->Size() != Visual->Size())
    72   {
    73     delete save;
    74     save = new image(visual->Size());
    75   }
    76   get_background();
     53    if (m_pos + visual->Size() >= 0 && m_pos < vec2i(xres, yres))
     54        m_save->PutPart(m_screen, vec2i(0,0), m_pos, m_pos + m_save->Size());
    7755}
    7856
    79 void sprite_controller::bring_front(sprite *sp)
    80 {
    81   ERROR(sprites.unlink(sp),"unlink failure");
    82   sprites.add_end(sp);
    83 }
    84 
    85 void sprite_controller::delete_sprite(sprite *sp)
    86 {
    87   ERROR(sprites.unlink(sp),"unlink failure");
    88   delete sp;
    89 }
    90 
Note: See TracChangeset for help on using the changeset viewer.