Logo Search packages:      
Sourcecode: adonthell version File versions  Download package

void mapview::draw ( s_int16  x,
s_int16  y,
const drawing_area da_opt = NULL,
surface target = NULL 
) const [virtual]

Draw the object on the screen.

Parameters:
x X position where to draw.
y Y position where to draw.
da_opt optional drawing_area to use during the drawing operation.
target pointer to the surface where to draw the drawable. If NULL, draw on the screen.

Implements drawable.

Definition at line 270 of file mapview.cc.

References mapsquare_area::area, mapsquare_area::area_height(), mapsquare_area::area_length(), drawing_area::assign_drawing_area(), drawing_area::detach_drawing_area(), drawable::height(), drawable::length(), MAPSQUARE_SIZE, drawing_area::move(), offx(), offy(), drawing_area::setup_rects(), landmap::submap, and u_int16.

{
    static u_int16 i, j;
    static u_int16 i0, j0, ie, je;
    static list <mapsquare_tile>::iterator it;
    static list <mapsquare_char>::iterator itc;
    static list <mapcharacter *>::iterator itb;
    static mapsquare_area *l;
    static u_int16 offx, offy; 

    static list <mapsquare_tile> critical_draw;
    static list <mapsquare_char> characters_draw;
    static list <mapcharacter *> bubbles_draw; 
    
    if (!m_map)
        return;

    static SDL_Rect trect; 
    static drawing_area tda;
     
    da.move (x, y);
    if (da_opt) da.assign_drawing_area (da_opt);
    
    trect = da.setup_rects ();
    tda = trect;
    
    l = m_map->submap[currentsubmap_];
    if (!l->area_length () || !l->area_height ())
        return;

    i0 = posx_;
    j0 = posy_;
    ie = i0 + d_length + (offx_ != 0) < l->area_length () ? i0 + d_length + (offx_ !=
                                                                    0) : l->area_length ();
    je = j0 + d_height + (offy_ != 0) < l->area_height () ? j0 + d_height + (offy_ !=
                                                                    0) : l->area_height ();

    offx = l->area_length () * MAPSQUARE_SIZE < length () ?
        (length () - l->area_length () * MAPSQUARE_SIZE) >> 1 : 0; 

    offy = l->area_height () * MAPSQUARE_SIZE < height () ?
        (height () - l->area_height () * MAPSQUARE_SIZE) >> 1 : 0; 

    x += offx;
    y += offy; 
    
    // 1st horizontal parse to check top overflows
    // Top-left corner
    for (it = l->area[i0][j0].tiles.begin ();
         it != l->area[i0][j0].tiles.end () && *(it->base_tile) < *it; it++)
        if (it->x > it->base_tile->x && it->y > it->base_tile->y)
            critical_draw.push_back (*(it->base_tile));

    for (itc = l->area[i0][j0].mapchars.begin ();
         itc != l->area[i0][j0].mapchars.end (); itc++)
        if (itc->x > itc->base_tile->x && itc->y > itc->base_tile->y)
            characters_draw.push_back (*itc);
    
    // Top line
    for (i = i0; i < ie && i < l->area_length (); i++)
    {
        for (it = l->area[i][j0].tiles.begin ();
             it != l->area[i][j0].tiles.end (); it++)
            if (it->x == it->base_tile->x && it->y > it->base_tile->y)
                critical_draw.push_back (*(it->base_tile));

        for (itc = l->area[i][j0].mapchars.begin ();
             itc != l->area[i][j0].mapchars.end (); itc++)
            if (itc->x == itc->base_tile->x && itc->y > itc->base_tile->y)
                characters_draw.push_back (*itc);
    }

    // Top right corner
    for (it = l->area[ie - 1][j0].tiles.begin ();
         it != l->area[ie - 1][j0].tiles.end (); it++)
        if (it->x < it->base_tile->x && it->y > it->base_tile->y)
            critical_draw.push_back (*(it->base_tile));

    for (itc = l->area[ie - 1][j0].mapchars.begin ();
         itc != l->area[ie - 1][j0].mapchars.end (); itc++)
        if (itc->x < itc->base_tile->x && itc->y > itc->base_tile->y)
            characters_draw.push_back (*itc);

    // Drawing characters and top overflowing gfx
    critical_draw.sort ();
    characters_draw.sort ();

    it = critical_draw.begin ();
    itc = characters_draw.begin ();
    while (itc != characters_draw.end () || it != critical_draw.end ())
    {
        if (itc != characters_draw.end ())
        {
            if (it != critical_draw.end ())
            {
                if (it->base_tile->y <= itc->base_tile->y)
                {
                    draw_tile (x, y, &tda, target, it);
                    it++;
                }
                else
                {
                    draw_mapchar (x, y, &tda, target, itc);
                    if (itc->mchar->is_speaking ())
                            bubbles_draw.push_back (itc->mchar); 
                    itc++;
                }
            }
            else
            {
                draw_mapchar (x, y, &tda, target, itc); 
                if (itc->mchar->is_speaking ()) 
                        bubbles_draw.push_back (itc->mchar); 
                itc++;
            }
        }
        else
        {
            draw_tile (x, y, &tda, target, it);
            it++;
        }
    }
    critical_draw.clear ();
    characters_draw.clear ();

    // Now drawing objects without any top or bottom overflow
    for (j = j0; j < je; j++)
    {
        // Left overflow
        for (it = l->area[i0][j].tiles.begin ();
             it != l->area[i0][j].tiles.end () && *(it->base_tile) <= *it;
             it++)
            if (it->y == it->base_tile->y && it->x > it->base_tile->x)
                draw_tile (x, y, &tda, target, it); 

        for (itc = l->area[i0][j].mapchars.begin ();
             itc != l->area[i0][j].mapchars.end (); itc++)
            if (itc->y == itc->base_tile->y && itc->x > itc->base_tile->x)
                characters_draw.push_back (*itc);

        // Objects which base tile is visible on the map view
        for (i = i0; i < ie; i++)
        {
            for (it = l->area[i][j].base_begin;
                 it != l->area[i][j].tiles.end () && *(it->base_tile) < *it;
                 it++);
            for (; it != l->area[i][j].tiles.end () && *(it->base_tile) == *it;
                 it++)
                draw_tile (x, y, &tda, target, it);
                
            for (itc = l->area[i][j].mapchars.begin ();
                 itc != l->area[i][j].mapchars.end (); itc++)
                if (*itc == *(itc->base_tile) &&
                    itc->x == itc->mchar->posx () &&
                    itc->y == itc->mchar->posy ())
                    characters_draw.push_back (*itc);
        }
        
        // Right overflow
        for (it = l->area[ie - 1][j].tiles.begin ();
             it != l->area[ie - 1][j].tiles.end (); it++)
            if (it->y == it->base_tile->y && it->x < it->base_tile->x)
                draw_tile (x, y, &tda, target, it); 

        for (itc = l->area[ie - 1][j].mapchars.begin ();
             itc != l->area[ie - 1][j].mapchars.end (); itc++)
            if (itc->y == itc->base_tile->y && itc->x < itc->base_tile->x)
                characters_draw.push_back (*itc);

        // Drawing characters
        for (itc = characters_draw.begin (); itc != characters_draw.end ();
             itc++)
          {
            draw_mapchar (x, y, &tda, target, itc);
            if (itc->mchar->is_speaking ()) 
                    bubbles_draw.push_back (itc->mchar); 
          }
        characters_draw.clear ();
    }

    // Last horizontal parse to check bottom overflows
    // Bottom left overflow
    if (!l->area[i0][je - 1].tiles.empty ())
        for (it = --l->area[i0][je - 1].tiles.end ();
             it->y < it->base_tile->y; it--)
        {
            if (it->x > it->base_tile->x && it->y < it->base_tile->y)
                critical_draw.push_front (*(it->base_tile));
            if (it == l->area[i0][je - 1].tiles.begin ())
                break;
        }

    for (itc = l->area[i0][je - 1].mapchars.begin ();
         itc != l->area[i0][je - 1].mapchars.end (); itc++)
        if (itc->x > itc->base_tile->x && itc->y < itc->base_tile->y)
            characters_draw.push_back (*itc);

    // Bottom line
    for (i = i0; i < ie && i < l->area_length (); i++)
    {
        if (!l->area[i][je - 1].tiles.empty ())
            for (it = --l->area[i][je - 1].tiles.end ();
                 it->y < it->base_tile->y; it--)
            {
                if (it->x == it->base_tile->x && it->y < it->base_tile->y)
                    critical_draw.push_front (*(it->base_tile));
                if (it == l->area[i][je - 1].tiles.begin ())
                    break;
            }

        for (itc = l->area[i][je - 1].mapchars.begin ();
             itc != l->area[i][je - 1].mapchars.end (); itc++)
        {
            if (itc->x == itc->base_tile->x && itc->y < itc->base_tile->y)
            {
                characters_draw.push_back (*itc);
            }
        }
    }

    // Bottom right corner
    if (!l->area[ie - 1][je - 1].tiles.empty ())
        for (it = --l->area[ie - 1][je - 1].tiles.end ();
             it->y < it->base_tile->y; it--)
        {
            if (it->x < it->base_tile->x && it->y < it->base_tile->y)
                critical_draw.push_front (*(it->base_tile));
            if (it == l->area[ie - 1][je - 1].tiles.begin ())
                break;
        }

    for (itc = l->area[ie - 1][je - 1].mapchars.begin ();
         itc != l->area[ie - 1][je - 1].mapchars.end (); itc++)
        if (itc->x < itc->base_tile->x && itc->y < itc->base_tile->y)
            characters_draw.push_back (*itc);


    // Drawing characters and bottom overflowing gfx
    critical_draw.sort ();
    characters_draw.sort ();

    it = critical_draw.begin ();
    itc = characters_draw.begin ();
    while (itc != characters_draw.end () || it != critical_draw.end ())
    {
        if (itc != characters_draw.end ())
        {
            if (it != critical_draw.end ())
            {
                if (it->base_tile->y <= itc->base_tile->y)
                {
                    draw_tile (x, y, &tda, target, it);
                    it++;
                }
                else
                {
                    draw_mapchar (x, y, &tda, target, itc); 
                    if (itc->mchar->is_speaking ())
                            bubbles_draw.push_back (itc->mchar); 
                    itc++;
                }
            }
            else
            {
                draw_mapchar (x, y, &tda, target, itc); 
                if (itc->mchar->is_speaking ()) 
                        bubbles_draw.push_back (itc->mchar); 
                itc++;
            }
        }
        else
        {
            draw_tile (x, y, &tda, target, it);
            it++;
        }
    }

    for (itb = bubbles_draw.begin (); itb != bubbles_draw.end (); itb++)
        draw_bubble (x, y, &tda, target, itb); 
 
    critical_draw.clear ();
    characters_draw.clear ();
    bubbles_draw.clear (); 
    
    if (da_opt) da.detach_drawing_area ();
}


Generated by  Doxygen 1.6.0   Back to index