/[enigma]/enigma/src/display.cc
ViewVC logotype

Diff of /enigma/src/display.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by dheck, Thu Jan 9 18:29:01 2003 UTC revision 1.7 by dheck, Sun Jan 12 19:47:19 2003 UTC
# Line 100  namespace Line 100  namespace
100          ~Sprite() { delete model; }          ~Sprite() { delete model; }
101      };      };
102    
103        struct Rubber {
104            V2 start,end;
105            V2 oldstart, oldend;
106    
107            Rubber(const V2 &s, const V2 &e) :start(s), end(e) {}
108            Rubber() {}
109        };
110    
111      typedef Array2<Field>   FieldArray;      typedef Array2<Field>   FieldArray;
112      typedef list<Model*>   ModelList;      typedef list<Model*>   ModelList;
113    
114      //typedef map<SpriteId, Sprite*> SpriteList;      //typedef map<SpriteId, Sprite*> SpriteList;
115      typedef vector<Sprite*> SpriteList;      typedef vector<Sprite*> SpriteList;
116        typedef vector<Rubber> RubberList;
117  }  }
118    
119    
120  //======================================================================  //======================================================================
121  // STATUS BAR  // STATUS BAR
122  //======================================================================  //======================================================================
# Line 386  static int MaxEffectSprites = 10; Line 396  static int MaxEffectSprites = 10;
396    
397  namespace  namespace
398  {  {
399        typedef AssocList<unsigned, Rubber> RubberMap;
400    
401      // Do not change the order of the following two variables!      // Do not change the order of the following two variables!
402      ModelList       active_models;      ModelList       active_models;
403      FieldArray      fields(0,0);      FieldArray      fields(0,0);
404      SpriteList      sprites;      SpriteList      sprites;
405      SpriteList      effects;      SpriteList      effects;
406        RubberMap       rubbers;
407  //     ImageArray      imagearray(0,0);  //     ImageArray      imagearray(0,0);
408    
409      StatusBarImpl   *status_bar = 0;      StatusBarImpl   *status_bar = 0;
# Line 400  namespace Line 413  namespace
413      ScreenArea inventoryarea(0, 480-64, 640, 64);      ScreenArea inventoryarea(0, 480-64, 640, 64);
414  }  }
415    
   
416  StatusBar *  StatusBar *
417  display::GetStatusBar()  display::GetStatusBar()
418  {  {
# Line 470  world_to_screen (const V3 & pos, int *x, Line 482  world_to_screen (const V3 & pos, int *x,
482  // DISPLAY ENGINE  // DISPLAY ENGINE
483  //======================================================================  //======================================================================
484    
485    //----------------------------------------
486    // Rubber bands
487    //----------------------------------------
488    
489    /* Mark the screen region occupied by a rubber band for redraw.
490       Problem is: what region is that exactly?  What pixels on the screen
491       will the line rasterizer touch?  Hard to tell, especially when
492       anti-aliasing is used.
493    
494       This function constructs a list of rectangles that completely
495       enclose the line by subdividing the line into n segments and
496       constructing the bounding box for each of these segments.  To
497       account for the (effective) finite width of the line, these boxes
498       need to be enlarged by a small amount to make them overlap a bit.
499    
500       The number n of subdivision depends on the length of the line.  n=1
501       would of course do, but we want to redraw as little of the screen
502       as possible.  'maxboxsize'
503    */
504    static void
505    mark_redraw_rubber (const Rubber &r)
506    {
507        const double maxboxsize = 1.0; //0.5;
508    
509        double w0 = r.start[0]-r.end[0];
510        double h0 = r.start[1]-r.end[1];
511        int n = int (max(abs(w0),abs(h0)) / maxboxsize)+1;
512    
513        double w = w0/n;
514        double h = h0/n;
515    
516        double overlap = 0.5;
517    
518        double x = r.end[0];
519        double y = r.end[1];
520        
521        WorldArea wa(x-overlap, y-overlap,
522                     int(abs(w)+2*overlap+1), int(abs(h)+2*overlap+1));
523    
524        for (int i=0; i<n; ++i) {
525            wa.x = int(x-overlap);
526            wa.y = int(y-overlap);
527    //         if (wa.x != int(x) || wa.y !=int(y))
528    //             wa.w = wa.h = 2;
529    //         else
530    //             wa.w = wa.h = 1;
531    
532            mark_redraw_area (wa);
533    
534            x += w;
535            y += h;
536        }
537    }
538    
539    
540    RubberID
541    display::AddRubber (const V2 &p1, const V2 &p2)
542    {
543        static unsigned id=1;
544        rubbers[id] = Rubber(p1, p2);
545        mark_redraw_rubber (rubbers[id]);
546        return RubberID(id++);
547    }
548    
549    RubberID::RubberID(unsigned id_): id(id_)
550    {
551    }
552    
553    void
554    RubberID::update_first(const V2 &p1)
555    {
556    //    assert(0 <= id && id < rubbers.size());
557        mark_redraw_rubber (rubbers[id]);
558        rubbers[id].start = p1;
559        mark_redraw_rubber (rubbers[id]);
560    }
561    
562    void
563    RubberID::update_second(const V2 &p2)
564    {
565    //    assert(0 <= id && id < rubbers.size());
566        mark_redraw_rubber (rubbers[id]);
567        rubbers[id].end = p2;
568        mark_redraw_rubber (rubbers[id]);
569    }
570    
571    void RubberID::kill()
572    {
573    //    assert(0 <= id && id < rubbers.size());
574        mark_redraw_rubber (rubbers[id]);
575        RubberMap::iterator i=rubbers.find(id);
576        if (i != rubbers.end())
577            rubbers.erase(i);
578    }
579    
580    //----------------------------------------
581    // Shadow rendering
582    //----------------------------------------
583    
584  namespace  namespace
585  {  {
586      class ShadowLayer {      class ShadowLayer {
# Line 1273  draw_sprites(SpriteLayer l, bool shades, Line 1384  draw_sprites(SpriteLayer l, bool shades,
1384      }      }
1385  }  }
1386    
1387    #include "SDL_gfxPrimitives.h"
1388    
1389    static void
1390    draw_rubbers (GC &gc)
1391    {
1392        SDL_Surface *surf = video::GetScreen()->get_surface();
1393    //    Uint32 color = SDL_MapRGB(surf->format, 255,255,225);
1394    
1395        for (RubberMap::iterator i=rubbers.begin(); i!= rubbers.end(); ++i)
1396        {
1397            lineRGBA(surf,
1398                     int ((i->second.start[0]-ScrollX)*TileWidth),
1399                     int ((i->second.start[1]-ScrollY)*TileHeight),
1400                     int ((i->second.end[0]-ScrollX)*TileWidth),
1401                     int ((i->second.end[1]-ScrollY)*TileHeight),
1402                     240,200,90,255);
1403        }
1404    }
1405    
1406  void  void
1407  display::ToggleFlag(DisplayFlags flag)  display::ToggleFlag(DisplayFlags flag)
1408  {  {
# Line 1301  draw_field(GC &gc, Field &f, int x, int Line 1431  draw_field(GC &gc, Field &f, int x, int
1431      if (display_flags & SHOW_SPRITES) draw_sprites(SPRITE_ACTOR, false, gc);      if (display_flags & SHOW_SPRITES) draw_sprites(SPRITE_ACTOR, false, gc);
1432      if (display_flags & SHOW_STONES) draw_model(gc, xpos, ypos, f.layers[GRID_STONES]);      if (display_flags & SHOW_STONES) draw_model(gc, xpos, ypos, f.layers[GRID_STONES]);
1433      if (display_flags & SHOW_SPRITES) draw_sprites(SPRITE_EFFECT, false, gc);      if (display_flags & SHOW_SPRITES) draw_sprites(SPRITE_EFFECT, false, gc);
1434        draw_rubbers (gc);
1435  }  }
1436    
1437    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26