Advanced Strategic Command
overviewmappanel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  paradialog.cpp - description
3  -------------------
4  begin : Thu Feb 21 2002
5  copyright : (C) 2002 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 
20 #include "overviewmappanel.h"
21 #include "spfst.h"
22 #include "graphics/blitter.h"
23 #include "graphics/drawing.h"
24 #include "mapdisplay.h"
25 #include "spfst-legacy.h"
26 
27 
28 OverviewMapPanel::OverviewMapPanel( PG_Widget *parent, const PG_Rect &r, MapDisplayPG* mapDisplay, const ASCString& widgetName )
29  : LayoutablePanel ( parent, r, widgetName, true ), mapDisplayWidget( mapDisplay), currentZoom( 1 ), locked(false)
30 {
31  SpecialDisplayWidget* sdw = dynamic_cast<SpecialDisplayWidget*>( FindChild( "overviewmap", true ) );
32  if ( sdw ) {
33  sdw->display.connect( sigc::mem_fun( *this, &OverviewMapPanel::painter ));
34  sdw->sigMouseMotion.connect( sigc::mem_fun( *this, &OverviewMapPanel::mouseMotion ));
35  sdw->sigMouseButtonDown.connect( sigc::mem_fun( *this, &OverviewMapPanel::mouseButtonDown ));
36  }
37 
38  ovmap = sdw;
39  assert( ovmap );
40 
41  OverviewMapHolder::generationComplete.connect ( sigc::mem_fun( *this, &OverviewMapPanel::redraw ));
42  viewChanged.connect ( sigc::mem_fun( *this, &OverviewMapPanel::redraw ));
43 
44  lockMapdisplay.connect( sigc::mem_fun( *this, &OverviewMapPanel::lockPanel ));
45  unlockMapdisplay.connect( sigc::mem_fun( *this, &OverviewMapPanel::unlockPanel ));
46 
47 
48 }
49 
50 
51 template<int pixelsize>
53 {
54  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
55  SDLmm::Color col;
56  public:
57 
58  void assign ( PixelType src, PixelType* dest ) const
59  {
60  *dest = (col & 0xff000000) + (0xffffff - (*dest & 0xffffff));
61  // *dest = col;
62  };
63 
64 
66  {
67  col = color;
68  };
69 };
70 
71 
72 void OverviewMapPanel::painter ( const PG_Rect &src, const ASCString& name, const PG_Rect &dst)
73 {
74  Surface screen = Surface::Wrap( PG_Application::GetScreen() );
75  if ( name == "overviewmap" && actmap && !locked ) {
77 
79  blitter.setSize( s.w(), s.h(), dst.w, dst.h );
80 
81  PG_Rect clip= dst.IntersectRect( PG_Application::GetScreen()->clip_rect );
82  blitter.setTargetRect( clip );
83 
84 
85  currentZoom = blitter.getZoomX();
86  blitter.blit( s, screen, SPoint(dst.x, dst.y) );
87 
88  SPoint ul = OverviewMapImage::map2surface( mapDisplayWidget->upperLeftCorner());
89  SPoint lr = OverviewMapImage::map2surface( mapDisplayWidget->lowerRightCorner());
90  ul.x = int( float( ul.x) * currentZoom );
91  ul.y = int( float( ul.y) * currentZoom );
92  lr.x = int( float( lr.x) * currentZoom );
93  lr.y = int( float( lr.y) * currentZoom );
94 
95  if ( ul.x < 0 )
96  ul.x = 0;
97  if ( ul.y < 0 )
98  ul.y = 0;
99  if ( lr.x >= src.Width() )
100  lr.x = src.Width() -1;
101  if ( lr.y >= src.Height() )
102  lr.y = src.Height() -1;
103 
104  rectangle<4>(screen, SPoint(dst.x + ul.x, dst.y + ul.y), lr.x-ul.x, lr.y-ul.y, ColorMerger_Invert<4>(0xff), ColorMerger_Invert<4>(0xff) );
105  }
106 }
107 
108 
109 void OverviewMapPanel::lockPanel()
110 {
111  locked = true;
112  Update();
113 }
114 
115 void OverviewMapPanel::unlockPanel()
116 {
117  locked = false;
118  Redraw();
119 }
120 
122 {
123  SPoint unscaledPos = SPoint(int( float(pos.x) / currentZoom), int(float(pos.y) / currentZoom ));
124  MapCoordinate mc = OverviewMapImage::surface2map( unscaledPos );
125 
126  if ( !(mc.valid() && mc.x < actmap->xsize && mc.y < actmap->ysize ))
127  return false;
128 
129  mapDisplayWidget->centerOnField( mc );
130  return true;
131 }
132 
133 
134 bool OverviewMapPanel::mouseButtonDown ( PG_MessageObject* o, const SDL_MouseButtonEvent *button)
135 {
136  if ( ovmap->IsMouseInside() )
137  if ( button->type == SDL_MOUSEBUTTONDOWN && button->button == 1 ) {
138  PG_Point p = ovmap->ScreenToClient( button->x, button->y );
139  return mouseClick( SPoint( p.x, p.y ));
140  }
141 
142  return false;
143 }
144 
145 bool OverviewMapPanel::mouseMotion ( PG_MessageObject* o, const SDL_MouseMotionEvent *motion)
146 {
147  if ( ovmap->IsMouseInside() )
148  if ( motion->type == SDL_MOUSEMOTION && (motion->state & 1 ) ) {
149  PG_Point p = ovmap->ScreenToClient( motion->x, motion->y );
150  return mouseClick( SPoint( p.x, p.y ));
151  }
152 
153  return false;
154 }
155 
int xsize
the size of the map
Definition: gamemap.h:201
DisplayHook display
Definition: paradialog.h:182
static sigc::signal< void > generationComplete
Definition: gamemap.h:168
map accessing and usage routines used by ASC and the mapeditor
bool valid() const
Definition: typen.h:221
void blit(const Surface &src, Surface &dst, SPoint dstPos)
Definition: blitter.h:349
MapCoordinate lowerRightCorner()
Definition: mapdisplay.cpp:952
static SPoint map2surface(const MapCoordinate &pos)
OverviewMapPanel(PG_Widget *parent, const PG_Rect &r, MapDisplayPG *mapDisplay, const ASCString &widgetName)
const Surface & getOverviewMap(bool complete=true)
returns the overview surface for the map.
Definition: gamemap.cpp:180
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
sigc::signal< void > lockMapdisplay
Definition: mapdisplay.cpp:67
Coordinate on the twodimensional map.
Definition: typen.h:202
void assign(PixelType src, PixelType *dest) const
sigc::signal< void > unlockMapdisplay
Definition: mapdisplay.cpp:68
bool mouseClick(SPoint pos)
SDLmm::Color Color
Definition: blitter.h:35
MapCoordinate upperLeftCorner()
Definition: mapdisplay.cpp:947
SDLmm::SPoint SPoint
Definition: surface.h:27
bool mouseMotion(PG_MessageObject *o, const SDL_MouseMotionEvent *motion)
int ysize
Definition: gamemap.h:201
sigc::signal< void > viewChanged
the view of the player onto the map changed, for example because he scrolled the map ...
Definition: spfst.cpp:51
bool mouseButtonDown(PG_MessageObject *o, const SDL_MouseButtonEvent *button)
OverviewMapHolder overviewMapHolder
Definition: gamemap.h:532
void painter(const PG_Rect &src, const ASCString &name, const PG_Rect &dst)
static MapCoordinate surface2map(const SPoint &pos)
GameMap * actmap
Definition: spfst.cpp:64
static Surface Wrap(SDL_Surface *surface)
Definition: surface.h:76
this Panel saves its position in the gameoptions and loads it on construction
Definition: windowing.h:121
SDL_Surface * screen
Definition: graphics.cpp:31
bool centerOnField(const MapCoordinate &mc)
Definition: mapdisplay.cpp:958
ColorMerger_Invert(SDLmm::Color color)