Beispiel #1
0
ImageObject* SDLImageObject::themeSDLImageObjectLoader( const string fname, InifileSection* iniSec, const ThemeLoadOptions& op )
{
  SDLImageObject* im = new SDLImageObject;
  im->loadImage( fname );
  if ( im->isLoaded() ) {
    int sw = iniSec->keyIntValue( "sectionwidth", 0 );
    int sh = iniSec->keyIntValue( "sectionheight", 0 );
		int a = iniSec->keyIntValue( "alpha", 255 );
    if ( (sw != 0) && (sh != 0) ) {
      im->setSectionWidht( sw );
      im->setSectionHeight( sh );
    }
		if ( iniSec->keyIndex( "colorkey" ) >= 0 ) {
			Color c;
			Utils::fromString( iniSec->keyStringValue( "colorkey", "" ), c );
			SDL_SetColorKey( im->getSurface(), SDL_SRCCOLORKEY, SDL_MapRGB( im->getSurface()->format, c.getR(), c.getG(), c.getB() ) );
			if ( (c.getA() != 255) && ( a == 255 ) )
				a = c.getA();
			else
				im->setAlpha( 255 );
		}
		if ( a != 255 )
			im->setAlpha( a );

    return (ImageObject*)im;
  } else {
    delete im;
    return NULL;
  }
}
Beispiel #2
0
void SDLImageObject::drawImage( ImageObject &image, const Rect& dr, const Rect &sr )
{
  Rect dr2 = dr;
  dr2.left += pRelX;
  dr2.top += pRelY;
  visDebug( dr2 );
  updated = true;
  SDLImageObject *i = (SDLImageObject*)ℑ

//  cout << "* Ui::SDLDrawInterface::drawImage(  )" << endl;
  pushClipRect( dr2 );
  if ( clipRect().area() <= 0 ) {
    popClipRect();
    return;
  }

  SDL_Rect *sdldr = new SDL_Rect;

  sdldr->x = dr2.left;
  sdldr->y = dr2.top;
  if ( dr2.width == 0 ) {
    sdldr->w = image.width();
  } else {
    sdldr->w = dr2.width;
  }
  if ( dr2.height == 0 ) {
    sdldr->h = image.height();
  } else {
    sdldr->h = dr2.height;
  }

  SDL_Rect *sdlsr = NULL;
  if ( sr != NULL_RECT ) {
    sdlsr = new SDL_Rect;
    sdlsr->x = sr.left;
    sdlsr->y = sr.top;
    sdlsr->w = sr.width;
    sdlsr->h = sr.height;
  }

  SDL_BlitSurface( i->getSurface(), sdlsr, s, sdldr );

  popClipRect();
  delete sdldr;

}
Beispiel #3
0
void SDLImageObject::drawImageStreched( ImageObject &image, const Rect& dr, const Rect &sr )
{
  Rect dr2 = dr;
  dr2.left += pRelX;
  dr2.top += pRelY;
  visDebug( dr2 );
  updated = true;
  SDLImageObject *i = (SDLImageObject*)&image;

//  cout << "* Ui::SDLDrawInterface::drawImageTiled(  )" << endl;
  pushClipRect( dr2 );
  if ( clipRect().area() <= 0 ) {
    popClipRect();
    return;
  }

  SDL_Rect *sdldr = new SDL_Rect;

  //clipRect().debug( "drawImage" );

  double fnumx, fnumy;
  int numx, numy;

  fnumx = (double)dr.width / (double)i->width();
  fnumy = (double)dr.height / (double)i->height();

  numx = (int)ceil( fnumx );
  numy = (int)ceil( fnumy );

  sdldr->w = i->width();
  sdldr->h = i->height();

  SDL_Rect *sdlsr = NULL;
  if ( sr != NULL_RECT ) {
    sdlsr = new SDL_Rect;
    sdlsr->x = sr.left;
    sdlsr->y = sr.top;
    sdlsr->w = sr.width;
    sdlsr->h = sr.height;
  }

  int x, y;
  for( y = 0; y < numy; y++ ) {
    for( x = 0; x < numx; x++ ) {
      sdldr->x = dr2.left + x * i->width();
      sdldr->y = dr2.top + y * i->height();

      SDL_BlitSurface( i->getSurface(), sdlsr, s, sdldr );
    }
  }

  popClipRect();
  delete sdldr;

}
Beispiel #4
0
NetwalkWindow::NetwalkWindow(Frame* parent, Font* f)
 : WindowFrame( parent )
{
  pSizeX = 6;
  pSizeY = 6;
  pNumCli = 8;

  beginUpdate();
  titleLabel.setParent( this );
  titleLabel.setTheme( Theme::defaultTheme() );

  scoreLabel.setParent( this );
  newButton.setParent( this );
  skillCombo.setParent( this );
  skillEasyItem.setText( L"Easy" );
  skillNormalItem.setText( L"Normal" );
  skillHardItem.setText( L"Hard" );
  skillDropdown.addItem( &skillEasyItem );
  skillDropdown.addItem( &skillNormalItem );
  skillDropdown.addItem( &skillHardItem );

  skillCombo.setDropdownList( &skillDropdown );

  skillDropdown.setTheme( Theme::defaultTheme() );

  skillCombo.setTheme( Theme::defaultTheme(), "readonly_" );
  skillCombo.setHeight( 20 );
  skillCombo.setName( "nw.skillCombo" );
  mapView.setParent( this );
  mapView.setTheme( Theme::defaultTheme() );
  mapView.setName( "nw.mapView" );

  titleLabel.setTop( 0 );
  titleLabel.setLeft( 0 );
  titleLabel.setWidth( 80 );
  titleLabel.setHeight( 20 );
//  titleLabel.setFont( f );
  titleLabel.setText( L"Netwalk" );
  titleLabel.setName( "nw.titleLabel" );

  scoreLabel.setTop( 20 );
  scoreLabel.setLeft( 0 );
  scoreLabel.setWidth( 40 );
  scoreLabel.setHeight( 20 );
  scoreLabel.setTheme( Theme::defaultTheme(), "score_" );
  scoreLabel.setText( L"0" );
  scoreLabel.setName( "nw.scoreLabel" );

  newButton.setTheme( Theme::defaultTheme() );
  newButton.setTop( 20 );
  newButton.setLeft( 42 );
  newButton.setWidth( 40 );
  newButton.setHeight( 20 );
  newButton.setText( L"New" );
  newButton.setName( "nw.newButton" );

  skillCombo.setTop( 20 );
  skillCombo.setLeft( 84 );
  skillCombo.setWidth( 78 );
  skillCombo.setText( L"Easy" );
  skillCombo.setReadOnly( true );

  mapView.setTop( 40 );
  mapView.setLeft( 0 );
  mapView.setTheme( Theme::defaultTheme() );

  string datadir;
  datadir = UIDATADIR;
  datadir += "/Images";

  Utils::setNotice( "Datadir is: " + datadir );

  SDLImageObject* imbg = new SDLImageObject();
  assert( imbg->loadImage( datadir+string("/net_bg.png") ) );
  mapView.tileImages().append( (ImageObject*&)imbg );

  SDLImageObject* imbg1 = new SDLImageObject();
  assert( imbg1->loadImage( datadir+"/net_flare1.png" ) );
  mapView.tileImages().append( (ImageObject*&)imbg1 );

  SDLImageObject* imbg2 = new SDLImageObject();
  assert( imbg2->loadImage( datadir+"/net_flare2.png" ) );
  mapView.tileImages().append( (ImageObject*&)imbg2 );

  SDLImageObject* imbg3 = new SDLImageObject();
  assert( imbg3->loadImage( datadir+"/net_flare3.png" ) );
  mapView.tileImages().append( (ImageObject*&)imbg3 );

  SDLImageObject* imo1 = new SDLImageObject();
  assert( imo1->loadImage( datadir+"/net_1u.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo1 );

  SDLImageObject* imo2 = new SDLImageObject();
  assert( imo2->loadImage( datadir+"/net_1r.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo2 );

  SDLImageObject* imo3 = new SDLImageObject();
  assert( imo3->loadImage( datadir+"/net_1d.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo3 );

  SDLImageObject* imo4 = new SDLImageObject();
  assert( imo4->loadImage( datadir+"/net_1l.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo4 );

  SDLImageObject* imo5 = new SDLImageObject();
  assert( imo5->loadImage( datadir+"/net_ph.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo5 );

  SDLImageObject* imo6 = new SDLImageObject();
  assert( imo6->loadImage( datadir+"/net_pv.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo6 );

  SDLImageObject* imo7 = new SDLImageObject();
  assert( imo7->loadImage( datadir+"/net_tur.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo7 );

  SDLImageObject* imo8 = new SDLImageObject();
  assert( imo8->loadImage( datadir+"/net_tul.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo8 );

  SDLImageObject* imo9 = new SDLImageObject();
  assert( imo9->loadImage( datadir+"/net_tdr.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo9 );

  SDLImageObject* imo10 = new SDLImageObject();
  assert( imo10->loadImage( datadir+"/net_tdl.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo10 );

  SDLImageObject* imo11 = new SDLImageObject();
  assert( imo11->loadImage( datadir+"/net_3u.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo11 );

  SDLImageObject* imo12 = new SDLImageObject();
  assert( imo12->loadImage( datadir+"/net_3r.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo12 );

  SDLImageObject* imo13 = new SDLImageObject();
  assert( imo13->loadImage( datadir+"/net_3d.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo13 );

  SDLImageObject* imo14 = new SDLImageObject();
  assert( imo14->loadImage( datadir+"/net_3l.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo14 );


  SDLImageObject* imo15 = new SDLImageObject();
  assert( imo15->loadImage( datadir+"/net_1u2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo15 );

  SDLImageObject* imo16 = new SDLImageObject();
  assert( imo16->loadImage( datadir+"/net_1r2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo16 );

  SDLImageObject* imo17 = new SDLImageObject();
  assert( imo17->loadImage( datadir+"/net_1d2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo17 );

  SDLImageObject* imo18 = new SDLImageObject();
  assert( imo18->loadImage( datadir+"/net_1l2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo18 );

  SDLImageObject* imo19 = new SDLImageObject();
  assert( imo19->loadImage( datadir+"/net_ph2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo19 );

  SDLImageObject* imo20 = new SDLImageObject();
  assert( imo20->loadImage( datadir+"/net_pv2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo20 );

  SDLImageObject* imo21 = new SDLImageObject();
  assert( imo21->loadImage( datadir+"/net_tur2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo21 );

  SDLImageObject* imo22 = new SDLImageObject();
  assert( imo22->loadImage( datadir+"/net_tul2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo22 );

  SDLImageObject* imo23 = new SDLImageObject();
  assert( imo23->loadImage( datadir+"/net_tdr2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo23 );

  SDLImageObject* imo24 = new SDLImageObject();
  assert( imo24->loadImage( datadir+"/net_tdl2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo24 );

  SDLImageObject* imo25 = new SDLImageObject();
  assert( imo25->loadImage( datadir+"/net_3u2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo25 );

  SDLImageObject* imo26 = new SDLImageObject();
  assert( imo26->loadImage( datadir+"/net_3r2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo26 );

  SDLImageObject* imo27 = new SDLImageObject();
  assert( imo27->loadImage( datadir+"/net_3d2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo27 );

  SDLImageObject* imo28 = new SDLImageObject();
  assert( imo28->loadImage( datadir+"/net_3l2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo28 );


  SDLImageObject* imo29 = new SDLImageObject();
  assert( imo29->loadImage( datadir+"/net_serv.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo29 );

  SDLImageObject* imo30 = new SDLImageObject();
  assert( imo30->loadImage( datadir+"/net_cli.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo30 );

  SDLImageObject* imo31 = new SDLImageObject();
  assert( imo31->loadImage( datadir+"/net_cli2.png" ) );
  mapView.objectImages().append( (ImageObject*&)imo31 );


  skillDropdown.onItemClicked.connect( this, &NetwalkWindow::skillDropdownClick );
  newButton.onMouseClick.connect( this, &NetwalkWindow::newButtonClick );
  mapView.onMouseMove.connect( this, &NetwalkWindow::mapViewMouseMove );
  mapView.onMousePressed.connect( this, &NetwalkWindow::mapViewMousePressed );
  mapView.onMouseClick.connect( this, &NetwalkWindow::mapViewMouseClick );
  mapView.onTileClicked.connect( this, &NetwalkWindow::mapViewTileClicked );

  titleLabel.setVisible( true );
  scoreLabel.setVisible( true );
  newButton.setVisible( true );
  skillCombo.setVisible( true );
  mapView.setVisible( true );

  endUpdate();
}