Advanced Strategic Command
mainscreenwidget.cpp
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  ***************************************************************************/
10 
11 
12 #include "global.h"
13 
14 #include <stdio.h>
15 #include <cstring>
16 #include <stdlib.h>
17 #include <new>
18 #include <cstdlib>
19 #include <ctype.h>
20 #include <algorithm>
21 #include <memory>
22 #include <SDL_image.h>
23 #include <SDL_mixer.h>
24 
25 #include "paradialog.h"
26 
27 #include "mainscreenwidget.h"
28 #include "misc.h"
29 #include "iconrepository.h"
30 #include "graphics/blitter.h"
31 #include "graphics/drawing.h"
32 #include "overviewmappanel.h"
33 #include "spfst.h"
34 #include "itemrepository.h"
35 #include "mapdisplay.h"
36 #include "events.h"
37 
38 
39 
40 MainScreenWidget::StandardActionLocker::StandardActionLocker( MainScreenWidget* mainScreenWidget, int options ) : widget( mainScreenWidget ), locked(false)
41 {
42  this->options = options;
43  lock();
44 };
45 
47 {
48  widget = locker.widget;
49  options = locker.options;
50  lock();
51 }
52 
53 
54 
56 {
57  if ( !widget )
58  return;
59 
60  widget->lockStandardActions(1, options );
61  locked = true;
62 };
63 
65 {
66  if ( !widget )
67  return;
68 
69  if ( locked ) {
70  widget->lockStandardActions(-1);
71  locked = false;
72  }
73 };
74 
76 {
77  unlock();
78 };
79 
80 
81 MainScreenWidget::MainScreenWidget( PG_Application& application )
82  : PG_Widget(NULL, PG_Rect ( 0, 0, app.GetScreen()->w, app.GetScreen()->h ), false),
83  app ( application ) , lastMessageTime(0), lastMouseScrollTime(0), overviewMapPanel(NULL), lockOptions(0), messageLine(NULL)
84 {
85 }
86 
87 
88 void MainScreenWidget::setup( bool messageLine, const PG_Rect& mapView )
89 {
90  displayLogMessage ( 5, "MainScreenWidget: initializing panels:\n");
91 
93 
94  displayLogMessage ( 7, " Mapdisplay ");
95  mapDisplay = new MapDisplayPG( this, mapView );
98 
99  SetID( ASC_PG_App::mainScreenID );
100 
101  displayLogMessage ( 5, "done\nMainScreenWidget completed\n");
103 
104  repaintDisplay.connect ( sigc::bind( sigc::mem_fun( *this, &MainScreenWidget::Update ), true ));
105 
106  buildBackgroundImage( messageLine );
108 
109  PG_Application::GetApp()->sigAppIdle.connect( sigc::hide( sigc::mem_fun( *this, &MainScreenWidget::idleHandler )));
110 
111  mapChanged.connect( sigc::ptr_fun( &OverviewMapHolder::clearmap ));
113 
114  MessagingHub::Instance().statusInformation.connect( sigc::mem_fun( *this, &MainScreenWidget::displayMessage ));
115  MessagingHub::Instance().messageWindowFactory.connect( sigc::mem_fun( *this, &MainScreenWidget::createStatusWindow ));
116 }
117 
118 
119 
120 void MainScreenWidget :: activateMapLayer( const ASCString& name, bool active )
121 {
122  if ( mapDisplay )
123  mapDisplay->activateMapLayer( name , active );
124 }
125 
127 {
128  if ( mapDisplay )
129  mapDisplay->toggleMapLayer( name );
130 }
131 
132 
134 {
135  if ( ticker > lastMessageTime + 500 ) {
136  displayMessage( "" );
137  lastMessageTime = 0xfffffff;
138  }
139 
141  return true;
142 }
143 
145 {
146  if ( getPGApplication().isFullscreen() && IsMouseInside() ) {
147 
148  if ( ticker > lastMouseScrollTime + 30 ) {
149  int x,y;
150  SDL_GetMouseState( &x, &y);
151 
152  if ( y <= 0 ) {
153  if ( x <= 0 ) {
154  mapDisplay->scrollMap( 7 );
155  return;
156  }
157 
158  if ( x >= PG_Application::GetScreenWidth() - 1 ) {
159  mapDisplay->scrollMap( 1 );
160  return;
161  }
162 
163  mapDisplay->scrollMap(0);
164  return;
165  }
166 
167  if ( y >= PG_Application::GetScreenHeight() - 1 ) {
168  if ( x <= 0 ) {
169  mapDisplay->scrollMap( 5 );
170  return;
171  }
172 
173  if ( x >= PG_Application::GetScreenWidth() - 1 ) {
174  mapDisplay->scrollMap( 3 );
175  return;
176  }
177 
178  mapDisplay->scrollMap(4);
179  return;
180  }
181 
182  if ( x >= PG_Application::GetScreenWidth() - 1 ) {
183  mapDisplay->scrollMap( 2 );
184  return;
185  }
186 
187  if ( x <= 0 ) {
188  mapDisplay->scrollMap( 6 );
189  return;
190  }
191  }
192  }
193 }
194 
195 
196 
197 void MainScreenWidget::buildBackgroundImage( bool messageLine )
198 {
199  if ( !backgroundImage.valid() ) {
200  backgroundImage = Surface::createSurface( Width(), Height(), 32 );
201 
203 
205  blitter.setSize( source.w(), source.h(), Width(), Height(), false );
206 
208  blitter.blit( source, backgroundImage, SPoint(0,0) );
209 
211 
212  assert( mapDisplay );
213  PG_Rect r = *mapDisplay;
214 
215  const int borderWidth = 5;
216  for ( int i = 0; i <= borderWidth; ++i )
217  rectangle<4> ( backgroundImage, SPoint(r.x-i, r.y-i), r.w+2*i, r.h+2*i, ColorMerger_Brightness<4>( 0.6 ), ColorMerger_Brightness<4>( 1.5 ));
218 
219  int x1 = r.x + 1;
220  int y1 = r.y + 1;
221  int x2 = r.x + r.Width() - 1;
222  int y2 = r.y + r.Height() -1;
223 
224  blitRects[0] = PG_Rect( 0, 0, Width(), y1 );
225  blitRects[1] = PG_Rect( 0, y1, x1, y2 );
226  blitRects[2] = PG_Rect( x2, y1, Width() - x2, y2 );
227  blitRects[3] = PG_Rect( 0, y2, Width(), Height() - y2 );
228 
229  if ( messageLine ) {
230 
231  Surface& msgstart = IconRepository::getIcon("msgline1.png");
232  Surface& msgmid = IconRepository::getIcon("msgline2.png");
233  Surface& msgend = IconRepository::getIcon("msgline3.png");
234 
236 
237  int mx1 = x1 - borderWidth;
238  int mx2 = x2 + borderWidth;
239  int my1 = y2 + 10;
240 
241  int msglength = mx2 - mx1;
242  int midlength = msglength - msgend.w();
243 
244  backgroundImage.Blit( msgstart, SPoint( mx1, my1 ));
245 
246  int x = msgstart.w();
247  while ( x + msgmid.w() < midlength ) {
248  backgroundImage.Blit( msgmid, SPoint( mx1 + x, my1 ));
249  x += msgmid.w();
250  }
252  backgroundImage.Blit( msgmid, SPoint( mx1 + msglength - msgend.w() - msgmid.w(), my1 ));
253 
255  backgroundImage.Blit( msgend, SPoint( mx1 + msglength - msgend.w(), my1) );
256 
257  this->messageLine = new PG_Label ( this, PG_Rect( mx1 + 20, my1 + 9, msglength - 30, msgend.h() - 18), "", "ThemeWidget" );
258  this->messageLine->SetFontSize(11);
260  }
261 
262  }
263 }
264 
266 {
267  if ( messageLine ) {
268  messageLine->SetText( message );
269  lastMessageTime = ticker;
270  }
271 }
272 
273 
274 
275 void MainScreenWidget::eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
276 {
277  SDL_Rect dstrect;
278  Surface s = Surface::Wrap( PG_Application::GetScreen() );
279  dstrect.x = blitRects[0].x;
280  dstrect.y = blitRects[0].y;
281  s.Blit( backgroundImage, blitRects[0], dstrect );
282 
283  dstrect.x = blitRects[1].x;
284  dstrect.y = blitRects[1].y;
285  s.Blit( backgroundImage, blitRects[1], dstrect );
286 
287  dstrect.x = blitRects[2].x;
288  dstrect.y = blitRects[2].y;
289  s.Blit( backgroundImage, blitRects[2], dstrect );
290 
291  dstrect.x = blitRects[3].x;
292  dstrect.y = blitRects[3].y;
293  s.Blit( backgroundImage, blitRects[3], dstrect );
294 }
295 
296 StatusMessageWindowHolder MainScreenWidget::createStatusWindow( const ASCString& msg )
297 {
299 }
300 
302 {
303  assert( mapDisplay);
304  overviewMapPanel = new OverviewMapPanel( this, PG_Rect(Width()-170, 0, 170, 160), mapDisplay, panelName );
305  overviewMapPanel->Show();
306 }
307 
308 
sigc::signal< void, GameMap * > mapChanged
Definition: spfst.cpp:52
void eventBlit(SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
map accessing and usage routines used by ASC and the mapeditor
miscellaneous functions which are used by ASC and all its tools
sigc::signal< void > repaintDisplay
Definition: spfst.cpp:46
void toggleMapLayer(const ASCString &name)
void blit(const Surface &src, Surface &dst, SPoint dstPos)
Definition: blitter.h:349
Instanciating this class will disable the Controls for interacting with the map or the main menu...
sigc::signal< void > dataLoaderTicker
void toggleMapLayer(const ASCString &name)
static Surface createSurface(int width, int height, SDLmm::Color color=255)
Definition: surface.cpp:387
Global platform dependant definitions. This file just branches to the platform specific files in thei...
void activateMapLayer(const ASCString &name, bool active)
A class that hols a MessageWindow. This class ensures that the window is removed if the last copy of ...
Definition: messaginghub.h:34
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
MainScreenWidget(PG_Application &application)
ASC_PG_App & getPGApplication()
Definition: paradialog.cpp:294
PG_Label * messageLine
void displayLogMessage(int msgVerbosity, const char *message,...)
MapDisplayPG * mapDisplay
virtual ASCString getBackgroundImageFilename()=0
Dialog classes based on the Paragui library.
void scrollMap(int dir)
SDLmm::SPoint SPoint
Definition: surface.h:27
void displayMessage(const ASCString &message)
void activateMapLayer(const ASCString &name, bool active)
static Surface & getIcon(const ASCString &name)
ASC_MainScreenWidget * mainScreenWidget
static const int mapDisplayID
Definition: paradialog.h:87
static Surface Wrap(SDL_Surface *surface)
Definition: surface.h:76
void spawnOverviewMapPanel(const ASCString &panelName="OverviewMap")
void setup(bool messageLine, const PG_Rect &mapView)
static const int mainScreenID
Definition: paradialog.h:88
StandardActionLocker(MainScreenWidget *mainScreenWidget, int options)
Disables certain controls on the game's screen.
volatile int ticker
Definition: events.cpp:234
static void clearmap(GameMap *actmap)
Definition: gamemap.cpp:216