Changeset 669


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

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

Location:
abuse/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/TODO

    r668 r669  
    6565Jwindow::_x1 _x2
    6666
    67 sprite::x,y -> m_pos
    6867console::draw_char : vec2i
    6968VolumeWindow::draw_vol plus grand !!
  • abuse/trunk/src/imlib/event.cpp

    r656 r669  
    6060    f.Apply(im);
    6161
    62     m_sprite = new sprite(screen, im, 100, 100);
     62    m_sprite = new Sprite(screen, im, vec2i(100, 100));
    6363    m_pos = screen->Size() / 2;
    6464    m_center = vec2i(0, 0);
  • abuse/trunk/src/imlib/event.h

    r656 r669  
    2626#define RIGHT_BUTTON   2
    2727#define MIDDLE_BUTTON  4
     28
    2829#include "keys.h"
    2930#include "sprite.h"
     
    8182    void SetMouseShape(image *im, vec2i center)
    8283    {
    83         m_sprite->change_visual(im, 1);
     84        m_sprite->SetVisual(im, 1);
    8485        m_center = center;
    8586    }
     
    9495    linked_list m_events;
    9596    int m_pending, last_key;
    96     sprite_controller sc;
    9797
    9898    image *m_screen;
     
    100100protected:
    101101    /* Mouse information */
    102     sprite *m_sprite;
     102    Sprite *m_sprite;
    103103    vec2i m_pos, m_center;
    104104    int m_button;
  • abuse/trunk/src/imlib/jwindow.cpp

    r668 r669  
    334334    {
    335335        m1 = m_pos - m_center;
    336         vec2i m2 = m1 + m_sprite->visual->Size();
    337 
    338         m_sprite->save->PutPart(m_surf, vec2i(0, 0), m1, m2);
    339         m_surf->PutImage(m_sprite->visual, m1, 1);
     336        vec2i m2 = m1 + m_sprite->m_visual->Size();
     337
     338        m_sprite->m_save->PutPart(m_surf, vec2i(0, 0), m1, m2);
     339        m_surf->PutImage(m_sprite->m_visual, m1, 1);
    340340    }
    341341
     
    346346
    347347    if (has_mouse())
    348         m_surf->PutImage(m_sprite->save, m1);
     348        m_surf->PutImage(m_sprite->m_save, m1);
    349349
    350350    for (Jwindow *p = m_first; p; p = p->next)
     
    355355        if (has_mouse())
    356356        {
    357             m_sprite->save->PutPart(p->m_surf, vec2i(0, 0), m1 - p->m_pos,
    358                                     m1 - p->m_pos + m_sprite->visual->Size());
    359             p->m_surf->PutImage(m_sprite->visual, m1 - p->m_pos, 1);
     357            m_sprite->m_save->PutPart(p->m_surf, vec2i(0, 0), m1 - p->m_pos,
     358                                      m1 - p->m_pos + m_sprite->m_visual->Size());
     359            p->m_surf->PutImage(m_sprite->m_visual, m1 - p->m_pos, 1);
    360360        }
    361361
     
    368368        update_dirty(p->m_surf, p->m_pos.x, p->m_pos.y);
    369369        if (has_mouse())
    370             p->m_surf->PutImage(m_sprite->save, m1 - p->m_pos, 0);
     370            p->m_surf->PutImage(m_sprite->m_save, m1 - p->m_pos, 0);
    371371    }
    372372}
  • 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 
  • abuse/trunk/src/imlib/sprite.h

    r555 r669  
    1111#ifndef __SPRITE_HPP
    1212#define __SPRITE_HPP
     13
    1314#include "image.h"
    1415#include "linked.h"
    1516
    16 class sprite : public linked_node
     17class Sprite : public linked_node
    1718{
    1819public:
    19   image *visual,*screen,*save;
    20   int x,y;
    21   sprite(image *Screen, image *Visual, int X, int Y);
    22   void get_background();
    23   void restore_background();
    24   void draw();
    25   void change_visual(image *Visual, int delete_old=0);
    26   ~sprite();
    27 } ;
     20    Sprite(image *screen, image *visual, vec2i pos);
     21    ~Sprite();
    2822
    29 class sprite_controller
    30 {
    31 public :
    32   linked_list sprites;
    33   void add_sprite(sprite *sp);
    34   void remove_sprites();
    35   void get_backgrounds();
    36   void put_sprites();
    37   void bring_front(sprite *sp);
    38   void delete_sprite(sprite *sp);
    39 } ;
     23    void SetVisual(image *visual, int delete_old = 0);
     24
     25    image *m_visual, *m_screen, *m_save;
     26
     27private:
     28    vec2i m_pos;
     29};
     30
    4031#endif
    4132
Note: See TracChangeset for help on using the changeset viewer.