Advanced Strategic Command
windowing.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 #include <SDL_image.h>
20 #include <signal.h>
21 
22 
23 #include <paragui.h>
24 #include <pgapplication.h>
25 #include <pgmessagebox.h>
26 #include <pgdropdown.h>
27 #include "pgbutton.h"
28 #include "pgwidgetlist.h"
29 #include "pglabel.h"
30 #include "pgwindow.h"
31 #include "pgmaskedit.h"
32 #include "pgscrollbar.h"
33 #include "pgprogressbar.h"
34 #include "pgradiobutton.h"
35 #include "pgthemewidget.h"
36 #include "pgcheckbutton.h"
37 #include "pgslider.h"
38 #include "pglistbox.h"
39 #include "pgcolumnitem.h"
40 #include "pgpopupmenu.h"
41 #include "pgspinnerbox.h"
42 #include "pglog.h"
43 #include "pgmenubar.h"
44 #include "pgimage.h"
45 #include "pgmessagebox.h"
46 #include "pgwindow.h"
47 #include "pgrichedit.h"
48 #include "pgsdleventsupplier.h"
49 #include "pgmultilineedit.h"
50 #include "pgtooltiphelp.h"
51 
52 
53 #include "global.h"
54 
55 #include "windowing.h"
56 
57 #include "gameoptions.h"
58 #include "spfst.h"
59 
60 
61 #include "resourceplacement.h"
62 
63 #include "iconrepository.h"
64 #include "graphics/drawing.h"
65 #include "widgets/textrenderer.h"
66 
67 #include "util/messaginghub.h"
68 
69 
70 const int widgetTypeNum = 17;
71 const char* widgetTypes[widgetTypeNum]
72 =
73  { "image",
74  "area",
75  "statictext",
76  "textoutput",
77  "bargraph",
78  "specialDisplay",
79  "specialInput",
80  "dummy",
81  "multilinetext",
82  "scrollarea",
83  "button",
84  "radiobutton",
85  "checkbox",
86  "lineedit",
87  "slider",
88  "plain",
89  "listbox"
90  };
91 
109 
110 const int imageModeNum = 5;
111 const char* imageModes[imageModeNum]
112  = { "tile",
113  "stretch",
114  "tile3h",
115  "tile3v",
116  "tile9" };
117 
118 
119 const int textAlignNum = 3;
120 const char* textAlignment[textAlignNum]
121 =
122  { "left",
123  "center",
124  "right"
125  };
126 
127 
128 const int barDirectionNum = 4;
129 const char* barDirections[barDirectionNum]
130 =
131  { "left2right",
132  "right2left",
133  "top2buttom",
134  "buttom2top"
135  };
136 
137 const int sliderDirectionNum = 2;
139 =
140  { "vertical",
141  "horizontal"
142  };
143 
144 
145 
147  : backgroundMode(PG_Draw::TILE),
148  textAlign( PG_Label::LEFT ), textAlign_defined(false),
149  fontColor(0xffffff), fontColor_defined(false),
150  fontAlpha(255), fontAlpha_defined(false),
151  fontSize(8), fontSize_defined(false),
152  backgroundColor_defined(false),
153  transparency(0), transparency_defined(false),
154  bordersize(1), bordersize_defined(false),
155  hidden(false)
156 {
157 }
158 
160 {
161  WindowCounter wc;
162  return PG_Window::RunModal();
163 }
164 
165 
167 {
168  if ( pc.find( "BackgroundImage" )) {
169  pc.addString( "BackgroundImage", backgroundImage, backgroundImage );
170  int i = backgroundMode;
171  pc.addNamedInteger( "BackgroundMode", i, imageModeNum, imageModes, i);
172  backgroundMode = PG_Draw::BkMode( i );
173  }
174 
175  if ( pc.find( "TextAlign" )) {
176  int ta = textAlign;
177  pc.addNamedInteger( "TextAlign", ta, textAlignNum, textAlignment, ta );
178  textAlign = PG_Label::TextAlign( ta );
179  textAlign_defined = true;
180  }
181 
182  if ( pc.find( "FontColor")) {
183  pc.addInteger("FontColor", fontColor, fontColor );
184  fontColor_defined = true;
185  }
186 
187  pc.addString("FontName", fontName, fontName );
188 
189  if ( pc.find( "FontAlpha")) {
190  pc.addInteger("FontAlpha", fontAlpha, fontAlpha );
191  fontAlpha_defined = true;
192  }
193 
194  if ( pc.find( "FontSize")) {
195  pc.addInteger("FontSize", fontSize, fontSize );
196  fontSize_defined = true;
197  }
198 
199  if ( pc.find( "BackgroundColor" )) {
200  pc.addInteger("BackgroundColor", backgroundColor, backgroundColor );
201  backgroundImage.clear();
202  backgroundColor_defined = true;
203  };
204 
205  if ( pc.find("Transparency")) {
206  pc.addInteger("Transparency", transparency, transparency );
207  transparency_defined = true;
208  }
209 
210  if ( pc.find("Bordersize")) {
211  pc.addInteger("Bordersize", bordersize, bordersize );
212  bordersize_defined = true;
213  }
214 
215  pc.addBool( "hidden", hidden, hidden );
216  pc.addString("Style", style, style );
217 }
218 
219 
221 {
222  if ( !widget )
223  return;
224 
225  if ( backgroundColor_defined )
226  widget->setColor( backgroundColor );
227 
228  assign( (PG_ThemeWidget*)widget );
229 
230 }
231 
232 
233 bool hasTransparency( const Surface& surf )
234 {
235  if ( surf.GetPixelFormat().BytesPerPixel() == 4 ) {
236  const Uint32* p = (const Uint32*) surf.pixels();
237  int aMask = surf.GetPixelFormat().Amask();
238  int aShift = surf.GetPixelFormat().Ashift();
239  for ( int y = 0; y < surf.h() ; ++y ) {
240  for ( int x = 0; x < surf.w() ; ++x)
241  if ( ((p[x] & aMask) >> aShift ) != Surface::opaque )
242  return true;
243  p += surf.pitch() / 4;
244  }
245  }
246  return false;
247 }
248 
249 
250 void ASCGUI_Window::WidgetParameters::assign( PG_ThemeWidget* widget )
251 {
252  if ( !widget )
253  return;
254 
255 
256  if ( !backgroundImage.empty() ) {
257  widget->SetBackground( IconRepository::getIcon(backgroundImage).getBaseSurface(), backgroundMode );
258  widget->SetDirtyUpdate( !hasTransparency( IconRepository::getIcon(backgroundImage) ));
259  } else {
260  if ( backgroundColor_defined ) {
261  widget->SetBackground( NULL );
262  widget->SetSimpleBackground( true );
263  }
264  }
265 
266  if ( backgroundColor_defined )
267  widget->SetBackgroundColor( backgroundColor );
268 
269  assign( (PG_Widget*)widget );
270 }
271 
273 {
274  if ( !widget )
275  return;
276 
277  if ( textAlign_defined )
278  widget->SetAlignment( textAlign );
279 
280  assign( (PG_Widget*)widget );
281 }
282 
283 
285 {
286  if ( !widget )
287  return;
288 
289  if ( fontColor_defined )
290  widget->SetFontColor( fontColor, true );
291 
292  if ( !fontName.empty() )
293  widget->SetFontName( fontName, true );
294 
295  if ( fontAlpha_defined )
296  widget->SetFontAlpha( fontAlpha, true );
297 
298  if ( fontSize_defined )
299  widget->SetFontSize( fontSize, true );
300 
301  if ( transparency_defined )
302  widget->SetTransparency( transparency, true );
303 
304  if( bordersize_defined )
305  widget->SetBorderSize( bordersize );
306 
307  if ( hidden )
308  widget->Hide(false);
309 }
310 
311 
312 ASCGUI_Window::ASCGUI_Window ( PG_Widget *parent, const PG_Rect &r, const ASCString& panelName_, const ASCString& baseStyle, bool loadTheme )
313  : PG_Window ( parent, ASC_PG_Dialog::centerRectangle(r), "", DEFAULT, baseStyle, 9 ), panelName( panelName_ ), textPropertyGroup(NULL)
314 {
315  // FIXME Hide button does not delete Panel
316 }
317 
318 
319 PG_Rect ASCGUI_Window::parseRect ( PropertyReadingContainer& pc, PG_Widget* parent )
320 {
321  int x,y,w,h,x2,y2;
322  // pc.openBracket( "position" );
323  pc.addInteger( "x", x );
324  pc.addInteger( "y", y );
325  pc.addInteger( "width", w, 0 );
326  pc.addInteger( "height", h, 0 );
327  pc.addInteger( "x2", x2, 0 );
328  pc.addInteger( "y2", y2, 0 );
329  // pc.closeBracket();
330 
331  PG_Rect r ( x,y,w,h);
332 
333  if ( x < 0 )
334  r.x = parent->Width() - w + x;
335 
336  if ( r.y < 0 )
337  r.y = parent->Height() - h + y;
338 
339  if ( x2 != 0 ) {
340  if ( x2 < 0 )
341  x2 = parent->Width() + x2;
342 
343  w = x2 - r.x;
344  }
345 
346  if ( y2 != 0 ) {
347  if ( y2 < 0 )
348  y2 = parent->Height() + y2;
349 
350  h = y2 - r.y;
351  }
352 
353 
354  if ( w <= 0 )
355  r.w = parent->Width() - r.x;
356  else
357  r.w = w;
358 
359  if ( h <= 0 )
360  r.h = parent->Height() - r.y;
361  else
362  r.h = h;
363 
364  return r;
365 }
366 
367 
368 
369 
370 void ASCGUI_Window::parsePanelASCTXT ( PropertyReadingContainer& pc, PG_Widget* parent, WidgetParameters widgetParams )
371 {
372  ASCString name;
373  pc.addString( "name", name, "" );
374  parent->SetName( name );
375 
376  int transparency;
377  pc.addInteger("localtransparency", transparency, -1 );
378  if ( transparency != -1 ) {
379  parent->SetTransparency( transparency );
380  }
381 
382  if ( pc.find( "userHandler" )) {
383  ASCString label;
384  pc.addString( "userHandler", label);
385  userHandler( label, pc, parent, widgetParams );
386  }
387 
388 
389  vector<ASCString> childNames;
390 
391 
392  if ( pc.find( "ChildWidgets" ))
393  pc.addStringArray( "ChildWidgets", childNames );
394 
395 
396  int widgetNum;
397  pc.addInteger( "WidgetNum", widgetNum, 0 );
398 
399  for ( int i = 0; i < widgetNum; ++i)
400  childNames.push_back( ASCString("Widget") + ASCString::toString( i ));
401 
402 
403  PG_RadioButton* radioButtonGroup = NULL;
404 
405 
406  WidgetParameters originalWidgetParams = widgetParams;
407 
408  for ( int i = 0; i < childNames.size(); ++i) {
409 
410  widgetParams = originalWidgetParams;
411 
412  pc.openBracket( childNames[i] );
413 
414  ASCString toolTipHelp;
415  pc.addString( "ToolTipHelp", toolTipHelp, "" );
416 
417 
418  PG_Rect r = parseRect( pc, parent );
419 
420  widgetParams.runTextIO( pc );
421 
422  bool hasStyle = pc.find( "style" );
423  ASCString style;
424  pc.addString( "style", style, "Panel" );
425 
426 
427  int type;
428  pc.addNamedInteger( "type", type, widgetTypeNum, widgetTypes );
429 
430  PG_Widget* newWidget = NULL;
431 
432  if ( type == Image ) {
433  ASCString filename;
434  pc.addString( "FileName", filename, "" );
435  int imgMode;
436  pc.addNamedInteger( "mode", imgMode, imageModeNum, imageModes, 0 );
437 
438 
439  if ( !filename.empty() ) {
440  try {
441  Surface& surf = IconRepository::getIcon(filename);
442  PG_Image* img = new PG_Image( parent, PG_Point(r.x, r.y ), surf.getBaseSurface(), false, PG_Draw::BkMode(imgMode) );
443  newWidget = img;
444  img->SetDirtyUpdate( !hasTransparency( surf ));
445 
446  widgetParams.assign ( img );
447  parsePanelASCTXT( pc, img, widgetParams );
448  } catch ( tfileerror ) {
449  warningMessage( "unable to load " + filename );
450  }
451  } else {
452  PG_Image* img = new PG_Image( parent, PG_Point(r.x, r.y ), NULL, false, PG_Draw::BkMode(imgMode) );
453  newWidget = img;
454  widgetParams.assign ( img );
455  parsePanelASCTXT( pc, img, widgetParams );
456  }
457  } else
458  if ( type == Area ) {
459  bool mode;
460  pc.addBool( "in", mode, true );
461 
462  Emboss* tw = new Emboss ( parent, r, mode );
463  // PG_ThemeWidget* tw = new PG_ThemeWidget ( parent, r, style );
464  widgetParams.assign ( tw );
465  parsePanelASCTXT( pc, tw, widgetParams );
466  newWidget = tw;
467  } else
468  if ( type == StaticLabel ) {
469  ASCString text;
470  pc.addString( "text", text );
471 
472  PG_Label* lb = new PG_Label ( parent, r, text, style );
473  if ( !hasStyle )
474  widgetParams.assign ( lb );
475  parsePanelASCTXT( pc, lb, widgetParams );
476  newWidget = lb;
477  } else
478  if ( type == TextOutput ) {
479  PG_Label* lb = new PG_Label ( parent, r, PG_NULLSTR, style );
480 
481  if ( !hasStyle )
482  widgetParams.assign ( lb );
483  parsePanelASCTXT( pc, lb, widgetParams );
484  newWidget = lb;
485  } else
486  if ( type == MultiLineText ) {
487  /*
488  PG_MultiLineEdit* lb = new PG_MultiLineEdit ( parent, r, style );
489 
490  lb->SetEditable(false);
491  if ( !hasStyle ) {
492  lb->SetBorderSize(0);
493  widgetParams.assign ( lb );
494  }
495  */
496 
497  TextRenderer* tr = new TextRenderer( parent, r, "", style );
498  if ( !hasStyle )
499  widgetParams.assign ( tr );
500 
501  parsePanelASCTXT( pc, tr, widgetParams );
502  newWidget = tr;
503  } else
504  if ( type == BarGraph ) {
505  int dir;
506  pc.addNamedInteger( "direction", dir, barDirectionNum, barDirections, 0 );
507 
508  int cnum;
509  pc.addInteger("Colors",cnum, 0 );
510  BarGraphWidget::Colors colorRange;
511  for ( int i = 0; i < cnum; ++i ) {
512  pc.openBracket("Color" + ASCString::toString(i));
513  int col;
514  pc.addInteger("color", col);
515  double f;
516  pc.addDFloat("fraction", f );
517  colorRange.push_back( make_pair(f,col) );
518  pc.closeBracket();
519  }
520 
521  BarGraphWidget* bg = new BarGraphWidget ( parent, r, BarGraphWidget::Direction(dir) );
522  bg->setColor( colorRange );
523  widgetParams.assign ( bg );
524  parsePanelASCTXT( pc, bg, widgetParams );
525  newWidget = bg;
526  } else
527  if ( type == SpecialDisplay ) {
528  SpecialDisplayWidget* sw = new SpecialDisplayWidget ( parent, r );
529  widgetParams.assign ( sw );
530 
531  parsePanelASCTXT( pc, sw, widgetParams );
532  newWidget = sw;
533  } else
534  if ( type == SpecialInput ) {
535  SpecialInputWidget* sw = new SpecialInputWidget ( parent, r );
536 
537  parsePanelASCTXT( pc, sw, widgetParams );
538  newWidget = sw;
539  } else
540  if ( type == Dummy ) {
541  SpecialInputWidget* sw = new SpecialInputWidget ( parent, r );
542  parsePanelASCTXT( pc, sw, widgetParams );
543  newWidget = sw;
544  } else
545  if ( type == ScrollArea ) {
546  PG_ScrollWidget* sw = new PG_ScrollWidget( parent, r, style );
547  ASCString scrollbar;
548  pc.addString( "horizontal_scollbar", scrollbar, "true" );
549  if ( scrollbar.compare_ci( "false" ) == 0)
550  sw->EnableScrollBar(false, PG_ScrollBar::HORIZONTAL );
551 
552  pc.addString( "vertical_scollbar", scrollbar, "true" );
553  if ( scrollbar.compare_ci( "false" ) == 0)
554  sw->EnableScrollBar(false, PG_ScrollBar::VERTICAL );
555 
556  if ( !hasStyle )
557  widgetParams.assign ( sw );
558 
559  parsePanelASCTXT( pc, sw, widgetParams );
560  newWidget = sw;
561  } else
562  if ( type == Button ) {
563  PG_Button* sw = new PG_Button( parent, r, style );
564 
565  ASCString text;
566  pc.addString( "text", text, "" );
567 
568  // if ( !text.empty() )
569  sw->SetText( text );
570 
571 
572  if ( !hasStyle )
573  widgetParams.assign ( sw );
574 
575  parsePanelASCTXT( pc, sw, widgetParams );
576  newWidget = sw;
577  } else
578  if ( type == RadioButton ) {
579  PG_RadioButton* sw = new PG_RadioButton( parent, r, style );
580  if ( radioButtonGroup )
581  radioButtonGroup->AddToGroup( sw );
582 
583  radioButtonGroup = sw;
584 
585  ASCString text;
586  pc.addString( "text", text );
587 
588  if ( !text.empty() )
589  sw->SetText( text );
590 
591  if ( !hasStyle )
592  widgetParams.assign ( sw );
593 
594  parsePanelASCTXT( pc, sw, widgetParams );
595  newWidget = sw;
596  } else
597  if ( type == CheckBox ) {
598  PG_CheckButton* sw = new PG_CheckButton( parent, r, style );
599 
600  ASCString text;
601  pc.addString( "text", text );
602 
603  if ( !text.empty() )
604  sw->SetText( text );
605 
606  if ( !hasStyle )
607  widgetParams.assign ( sw );
608 
609  parsePanelASCTXT( pc, sw, widgetParams );
610  newWidget = sw;
611  } else
612  if ( type == LineEdit ) {
613  PG_LineEdit* sw = new PG_LineEdit( parent, r, style );
614 
615  ASCString text;
616  pc.addString( "text", text, "" );
617 
618  if ( !text.empty() )
619  sw->SetText( text );
620 
621  if ( !hasStyle )
622  widgetParams.assign ( sw );
623 
624  parsePanelASCTXT( pc, sw, widgetParams );
625  newWidget = sw;
626  } else
627  if ( type == Slider ) {
628 
629  int direction = 0;
630  pc.addNamedInteger( "Orientation", direction, sliderDirectionNum, sliderDirections, direction);
631 
632 
633  PG_ScrollBar* sb = new PG_Slider( parent, r, PG_ScrollBar::ScrollDirection(direction), -1, style );
634 
635  if ( !hasStyle )
636  widgetParams.assign ( sb );
637 
638  parsePanelASCTXT( pc, sb, widgetParams );
639  newWidget = sb;
640  } else
641  if ( type == Plain ) {
642 
643  PG_ThemeWidget* w = new PG_ThemeWidget( parent, r );
644 
645  if ( !hasStyle )
646  widgetParams.assign ( w );
647 
648  parsePanelASCTXT( pc, w, widgetParams );
649  newWidget = w;
650  } else
651  if ( type == ListBox) {
652  PG_ListBox* l = new PG_ListBox( parent, r );
653 
654  if ( !hasStyle )
655  widgetParams.assign ( l );
656 
657  parsePanelASCTXT( pc, l, widgetParams );
658  newWidget = l;
659  }
660 
661  if ( newWidget && newWidget->GetName().empty() )
662  newWidget->SetName( childNames[i] );
663 
664  if ( newWidget && newWidget->GetName() == "$pos" )
665  newWidget->SetName( pc.getNameStack() );
666 
667 
668  if ( newWidget && !toolTipHelp.empty() )
669  new PG_ToolTipHelp( newWidget, toolTipHelp );
670 
671  pc.closeBracket();
672  }
673 }
674 
675 void ASCGUI_Window::rename( const ASCString& widgetName, const ASCString& newname, PG_Widget* parent )
676 {
677  if ( !parent )
678  parent = this;
679 
680  PG_Widget* w = parent->FindChild( widgetName, true );
681  if ( w )
682  w->SetName( newname );
683 }
684 
685 void ASCGUI_Window::setLabelText ( const ASCString& widgetName, const ASCString& text, PG_Widget* parent )
686 {
687  if ( !parent )
688  parent = this;
689 
690  PG_Label* l = dynamic_cast<PG_Label*>( parent->FindChild( widgetName, true ) );
691  if ( l )
692  l->SetText( text );
693  else {
694  PG_LineEdit* l = dynamic_cast<PG_LineEdit*>( parent->FindChild( widgetName, true ) );
695  if ( l )
696  l->SetText( text );
697  else {
698  PG_MultiLineEdit* l = dynamic_cast<PG_MultiLineEdit*>( parent->FindChild( widgetName, true ) );
699  if ( l )
700  l->SetText( text );
701  else {
702  TextRenderer* l = dynamic_cast<TextRenderer*>( parent->FindChild( widgetName, true ) );
703  if ( l )
704  l->SetText( text );
705  }
706  }
707  }
708 }
709 
710 void ASCGUI_Window::setLabelColor ( const ASCString& widgetName, PG_Color color, PG_Widget* parent )
711 {
712  if ( !parent )
713  parent = this;
714 
715  PG_Label* l = dynamic_cast<PG_Label*>( parent->FindChild( widgetName, true ) );
716  if ( l )
717  l->SetFontColor ( color );
718  else {
719  PG_MultiLineEdit* l = dynamic_cast<PG_MultiLineEdit*>( parent->FindChild( widgetName, true ) );
720  if ( l )
721  l->SetFontColor ( color );
722  }
723 }
724 
725 
726 void ASCGUI_Window::setLabelText ( const ASCString& widgetName, int i, PG_Widget* parent )
727 {
729  setLabelText ( widgetName, s, parent );
730 }
731 
732 
733 void ASCGUI_Window::setImage ( const ASCString& widgetName, const ASCString& filename, PG_Widget* parent )
734 {
735  setImage( widgetName, IconRepository::getIcon( filename ), parent );
736 }
737 
738 
739 void ASCGUI_Window::setImage ( const ASCString& widgetName, Surface& image, PG_Widget* parent )
740 {
741  setImage( widgetName, image.getBaseSurface(), parent);
742 }
743 
744 void ASCGUI_Window::setImage ( const ASCString& widgetName, SDL_Surface* image, PG_Widget* parent )
745 {
746  if ( !parent )
747  parent = this;
748 
749  PG_Image* i = dynamic_cast<PG_Image*>( parent->FindChild( widgetName, true ) );
750  if ( i ) {
751  i->SetImage( image, false );
752  if ( image )
753  i->SizeWidget( image->w, image->h);
754  }
755 }
756 
757 void ASCGUI_Window::setWidgetTransparency ( const ASCString& widgetName, int transparency, PG_Widget* parent )
758 {
759  if ( !parent )
760  parent = this;
761 
762  PG_Widget* i = parent->FindChild( widgetName, true );
763  if ( i )
764  i->SetTransparency( transparency );
765 }
766 
767 
768 void ASCGUI_Window::hide ( const ASCString& widgetName, PG_Widget* parent )
769 {
770  if ( !parent )
771  parent = this;
772 
773  PG_Widget* i = parent->FindChild( widgetName, true );
774  if ( i )
775  i->Hide();
776 }
777 
778 void ASCGUI_Window::show ( const ASCString& widgetName, PG_Widget* parent )
779 {
780  if ( !parent )
781  parent = this;
782 
783  PG_Widget* i = parent->FindChild( widgetName, true );
784  if ( i )
785  i->Show();
786 }
787 
788 
789 
790 void ASCGUI_Window::setBargraphValue( const ASCString& widgetName, float fraction, PG_Widget* parent )
791 {
792  if ( !parent )
793  parent = this;
794 
795  BarGraphWidget* bgw = dynamic_cast<BarGraphWidget*>( parent->FindChild( widgetName, true ) );
796  if ( bgw )
797  bgw->setFraction( fraction );
798 }
799 
800 
801 void ASCGUI_Window::setBarGraphColor( const ASCString& widgetName, PG_Color color, PG_Widget* parent )
802 {
803  if ( !parent )
804  parent = this;
805 
806  BarGraphWidget* bgw = dynamic_cast<BarGraphWidget*>( parent->FindChild( widgetName, true ) );
807  if ( bgw )
808  bgw->setColor( color );
809 }
810 
811 
812 
814 
815 
817 {
818  try {
819  WidgetParameters widgetParameters = getDefaultWidgetParams();
820 
821  panelName.toLower();
822 
823  if ( !CGameOptions::Instance()->cacheASCGUI || guiCache.find(panelName) == guiCache.end() ) {
824  tnfilestream s ( panelName + ".ascgui", tnstream::reading );
825 
826  TextFormatParser tfp ( &s );
827  textPropertyGroup = tfp.run();
828 
829  if ( CGameOptions::Instance()->cacheASCGUI )
830  guiCache[panelName] = textPropertyGroup;
831  } else
832  textPropertyGroup = guiCache[panelName];
833 
835 
836 
837 
838  int w = 0;
839  int h = 0;
840  pc.addInteger( "width", w, 0 );
841  pc.addInteger( "height", h, 0 );
842 
843  if ( w > 0 && h > 0 )
844  SizeWidget( w, h, false );
845  else
846  if ( h > 0 )
847  SizeWidget( Width(), h, false );
848  else
849  if ( w > 0 )
850  SizeWidget( w, Height(), false );
851 
852 
853  if ( pc.find("x") && pc.find("y" )) {
854  int x1,y1;
855  pc.addInteger( "x", x1 );
856  pc.addInteger( "y", y1 );
857 
858  if ( x1 < 0 && GetParent() )
859  x1 = GetParent()->Width() - Width() + x1;
860 
861  if ( y1 < 0 && GetParent() )
862  y1 = GetParent()->Height() - Height() + y1;
863 
864  int xofs = GetParent() ? GetParent()->my_xpos : 0;
865  int yofs = GetParent() ? GetParent()->my_ypos : 0;
866 
867  if ( x1 + xofs + Width() > PG_Application::GetScreenWidth() )
868  x1 = max ( PG_Application::GetScreenWidth() - Width() - xofs, 0 );
869 
870  if ( y1 + yofs + Height() > PG_Application::GetScreenHeight() )
871  y1 = max ( PG_Application::GetScreenHeight() - Height() - yofs, 0 );
872 
873  MoveWidget( x1, y1, false );
874  }
875 
876  int w2 = Width();
877  int h2 = Height();
878 
879  if ( w == 0 ) {
880  int x2 ;
881  pc.addInteger( "x2", x2, 0 );
882 
883  if ( x2 < 0 )
884  w2 = PG_Application::GetScreenWidth() - my_xpos + x2;
885  else
886  if ( x2 > 0 )
887  w2 = my_xpos + x2;
888  }
889 
890  if ( h == 0 ) {
891  int y2;
892  pc.addInteger( "y2", y2, 0 );
893  if ( y2 < 0 )
894  h2 = PG_Application::GetScreenHeight() - my_ypos + y2;
895  else
896  if ( y2 > 0 )
897  h2 = my_ypos + y2;
898  }
899 
900  if ( h2 != Height() || w2 != Width() )
901  SizeWidget( w2, h2, false );
902 
903 
904 
905  int titlebarHeight;
906  pc.addInteger("Titlebarheight", titlebarHeight, -1 );
907  if ( titlebarHeight != -1 )
908  SetTitlebarHeight( titlebarHeight );
909 
910  ASCString title;
911  pc.addString("Title", title, "" );
912  if ( !title.empty() )
913  SetTitle( title );
914 
915  widgetParameters.runTextIO( pc );
916  widgetParameters.assign ( this );
917 
918  parsePanelASCTXT( pc, this, widgetParameters );
919 
920  return true;
921  } catch ( ParsingError err ) {
922  warningMessage( "parsing error: " + err.getMessage());
923  } catch ( tfileerror err ) {
924  warningMessage( "could not acces file: " + err.getFileName() );
925  }
926  return false;
927 
928 }
929 
930 
931 void ASCGUI_Window::destruct()
932 {
933  if ( textPropertyGroup ) {
934  for ( GuiCache::iterator i = guiCache.begin(); i != guiCache.end(); ++i )
935  if ( i->second == textPropertyGroup )
936  return;
937 
938  delete textPropertyGroup;
939  }
940 }
941 
943 {
944  destruct();
945 }
946 
947 
948 Panel :: Panel ( PG_Widget *parent, const PG_Rect &r, const ASCString& panelName_, bool loadTheme )
949  : ASCGUI_Window( parent, r, panelName_, "Panel", loadTheme )
950 {
951  if ( loadTheme )
952  setup();
953 
954  BringToFront();
955 }
956 
958 {
959  static WidgetParameters defaultWidgetParameters;
960  static ASCString panelBackgroundImage;
961  static bool defaultsLoaded = false;
962  if ( !defaultsLoaded ) {
963  tnfilestream s ( "default.ascgui", tnstream::reading );
964 
965  TextFormatParser tfp ( &s );
966  auto_ptr<TextPropertyGroup> tpg ( tfp.run());
967 
968  PropertyReadingContainer pc ( "panel", tpg.get() );
969 
970  defaultWidgetParameters.runTextIO ( pc );
971  pc.addString("PanelBackgroundImage", panelBackgroundImage );
972  defaultsLoaded = true;
973  }
974  return defaultWidgetParameters;
975 }
976 
977 
978 
979 LayoutablePanel :: LayoutablePanel ( PG_Widget *parent, const PG_Rect &r, const ASCString& panelName_, bool loadTheme )
980  : Panel ( parent, PositionCalculator( r, panelName_), panelName_, loadTheme ), name( panelName_ )
981 {
982 }
983 
984 
985 PG_Rect LayoutablePanel::PositionCalculator( const PG_Rect& rect, const ASCString& panelName )
986 {
988  if ( CGameOptions::Instance()->getPanelData(panelName, pd) ) {
989  pd.x = PG_Application::GetScreenWidth() - pd.x;
990  PG_Rect r ( pd.x, pd.y, DashBoardWidth, rect.Height() );
991 
992  if ( r.x + r.w > PG_Application::GetScreenWidth() )
993  r.x = PG_Application::GetScreenWidth() - r.w;
994 
995  if ( r.y + r.h > PG_Application::GetScreenHeight() )
996  r.y = PG_Application::GetScreenHeight() - r.h;
997 
998  return r;
999  } else
1000  return PG_Rect( rect.x, rect.y, DashBoardWidth, rect.Height() );
1001 }
1002 
1004 {
1005  Panel::eventMoveWidget(x,y);
1007  pos.x = PG_Application::GetScreenWidth() - x;
1008  pos.y = y;
1009  pos.visible = true;
1010 
1011  CGameOptions::Instance()->updatePanelData( name, pos );
1012 }
1013 
1015 {
1016  Panel::eventHide();
1017 
1019  pos.x = PG_Application::GetScreenWidth() - my_xpos;
1020  pos.y = my_ypos;
1021  pos.visible = false;
1022 
1023  CGameOptions::Instance()->updatePanelData( name, pos );
1024 }
1025 
1027 {
1028  Panel::eventShow();
1029 
1031  pos.x = PG_Application::GetScreenWidth() - my_xpos;
1032  pos.y = my_ypos;
1033  pos.visible = true;
1034 
1035  CGameOptions::Instance()->updatePanelData( name, pos );
1036 }
1037 
1038 
1039 
1040 
1041 
1042 
1043 ConfigurableWindow :: ConfigurableWindow ( PG_Widget *parent, const PG_Rect &r, const ASCString& panelName_, bool loadTheme )
1044  : ASCGUI_Window( parent, r, panelName_, "Window", loadTheme )
1045 {
1046  if ( loadTheme )
1047  setup();
1048 
1049  BringToFront();
1050 }
1051 
1053 {
1054  return WidgetParameters();
1055 }
1056 
const int barDirectionNum
Definition: windowing.cpp:128
const int textAlignNum
Definition: windowing.cpp:119
vector< pair< double, int > > Colors
void addBool(const ASCString &name, bool &property)
map accessing and usage routines used by ASC and the mapeditor
TextPropertyGroup * textPropertyGroup
Definition: windowing.h:83
ASCString & toLower()
Definition: ascstring.cpp:36
const ASCString & getFileName() const
Definition: simplestream.h:80
const char * barDirections[barDirectionNum]
Definition: windowing.cpp:130
const char * sliderDirections[sliderDirectionNum]
Definition: windowing.cpp:139
TextPropertyGroup * run()
const char * imageModes[imageModeNum]
Definition: windowing.cpp:112
void setImage(const ASCString &widgetName, Surface &image, PG_Widget *parent=NULL)
Definition: windowing.cpp:739
virtual WidgetParameters getDefaultWidgetParams()=0
ASCGUI_Window(PG_Widget *parent, const PG_Rect &r, const ASCString &panelName_, const ASCString &baseStyle="Panel", bool loadTheme=true)
Definition: windowing.cpp:312
void eventMoveWidget(int x, int y)
Definition: windowing.cpp:1003
void warningMessage(const ASCString &str)
Global platform dependant definitions. This file just branches to the platform specific files in thei...
static GuiCache guiCache
Definition: windowing.h:81
WidgetParameters getDefaultWidgetParams()
Definition: windowing.cpp:1052
void updatePanelData(const ASCString &name, PanelData data)
SDL_Surface * getBaseSurface()
Definition: surface.h:116
LayoutablePanel(PG_Widget *parent, const PG_Rect &r, const ASCString &panelName_, bool loadTheme=true)
Definition: windowing.cpp:979
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void setWidgetTransparency(const ASCString &widgetName, int transparency, PG_Widget *parent=NULL)
Definition: windowing.cpp:757
void addStringArray(const ASCString &name, vector< ASCString > &property)
void setColor(int c)
void parsePanelASCTXT(PropertyReadingContainer &pc, PG_Widget *parent, WidgetParameters widgetParams)
Definition: windowing.cpp:370
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
WidgetTypes
Definition: windowing.cpp:92
void SetText(const std::string &text)
virtual void userHandler(const ASCString &label, PropertyReadingContainer &pc, PG_Widget *parent, WidgetParameters widgetParams)
Definition: windowing.h:101
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
static const Uint32 opaque
Definition: surface.h:66
bool hasTransparency(const Surface &surf)
Definition: windowing.cpp:233
void setBarGraphColor(const ASCString &widgetName, PG_Color color, PG_Widget *parent=NULL)
Definition: windowing.cpp:801
void assign(PG_Widget *widget)
Definition: windowing.cpp:284
void setBargraphValue(const ASCString &widgetName, float fraction, PG_Widget *parent=NULL)
Definition: windowing.cpp:790
ConfigurableWindow(PG_Widget *parent, const PG_Rect &r, const ASCString &panelName_, bool loadTheme=true)
Definition: windowing.cpp:1043
const ASCString & getMessage(void) const
Definition: errors.h:42
void show(const ASCString &widgetName, PG_Widget *parent=NULL)
Definition: windowing.cpp:778
Parses a .ASCTXT file and returns a TextPropertyGroup.
const int sliderDirectionNum
Definition: windowing.cpp:137
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
void rename(const ASCString &widgetName, const ASCString &newname, PG_Widget *parent=NULL)
Definition: windowing.cpp:675
static PG_Rect parseRect(PropertyReadingContainer &pc, PG_Widget *parent)
Definition: windowing.cpp:319
void addInteger(const ASCString &name, int &property)
virtual void closeBracket()
const char * widgetTypes[widgetTypeNum]
Definition: windowing.cpp:72
void setFraction(float f)
void addNamedInteger(const ASCString &name, int &property, int tagNum, const char **tags)
static Surface & getIcon(const ASCString &name)
void runTextIO(PropertyReadingContainer &pc)
Definition: windowing.cpp:166
void setLabelColor(const ASCString &widgetName, PG_Color color, PG_Widget *parent=NULL)
Definition: windowing.cpp:710
Panel(PG_Widget *parent, const PG_Rect &r, const ASCString &panelName_, bool loadTheme=true)
Definition: windowing.cpp:948
virtual void openBracket(const ASCString &name)
const T & max(const T &a, const T &b, const T &c)
Definition: misc.h:97
const int widgetTypeNum
Definition: windowing.cpp:70
void hide(const ASCString &widgetName, PG_Widget *parent=NULL)
Definition: windowing.cpp:768
void addString(const ASCString &name, ASCString &property)
const int imageModeNum
Definition: windowing.cpp:110
const char * textAlignment[textAlignNum]
Definition: windowing.cpp:121
bool find(const ASCString &name)
a map that stores pointers as values and deletes the pointed-to objects on destruction ...
Definition: typen.h:324
void setLabelText(const ASCString &widgetName, const ASCString &text, PG_Widget *parent=NULL)
Definition: windowing.cpp:685
WidgetParameters getDefaultWidgetParams()
Definition: windowing.cpp:957
void addDFloat(const ASCString &name, double &property)
int compare_ci(const ASCCharTString &s) const
Definition: ascstring.h:296