示例#1
0
文件: uiknob.cpp 项目: chille/GameUI
void Knob::render( ImageObject& img, const Rect& r )
{
  if ( !visible() ) return;
  if ( pImage != NULL ) {
    img.drawImage( *pImage, Rect( 0, 0, pImage->sectionWidth(), pImage->sectionHeight() ), pImage->sectionRect( pValue ) );
  } else if ( pImages != NULL ) {
    ImageObject* tmp = pImages->get( pValue );
    if ( tmp != NULL ) {
      img.drawImage( *tmp, Rect( 0, 0, tmp->width(), tmp->height()), pImage->sectionRect( pValue ) );
    }
  } else {
    Widget::render( img, r );
  }
}
示例#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;

}
示例#3
0
void SDLMouseCursor::load( ImageObject& img, const int& hotspotX, const int& hotspotY, const Color& transparentColor, const Color& invertColor )
{
	if ( imageIsSystemCursor( &img ) ) {

		Uint8* data = new Uint8[ (int)ceil( (double)(img.width() * img.height()) / 8 ) ];
		Uint8* mask = new Uint8[ (int)ceil( (double)(img.width() * img.height()) / 8 ) ];

		int bit = 1;
		int i = -1;

		Color black( 0, 0, 0 );
		Color white( 255, 255, 255 );
		//cout << "Cursor:" << endl;
		for( int y = 0; y < img.height(); y++ ) {
			for( int x = 0; x < img.width(); x++ ) {
				Color c = img.getPixel( x, y );

				if ( bit == 128 ) {
					bit = 64;
				}
				else if ( bit == 64 )
					bit = 32;
				else if ( bit == 32 )
					bit = 16;
				else if ( bit == 16 )
					bit = 8;
				else if ( bit == 8 )
					bit = 4;
				else if ( bit == 4 )
					bit = 2;
				else if ( bit == 2 )
					bit = 1;
				else if ( bit == 1 ) {
					bit = 128;
					i++;
					data[i] = 0;
					mask[i] = 0;
				}

				if ( c == white ) {
					//cout << ".";
					mask[i] |= bit;
				} else if ( c == black ) {
					//cout << "X";
					data[i] |= bit;
					mask[i] |= bit;
				} else if ( c == invertColor ) {
					//cout << "0";
					data[i] |= bit;
				} else {
					//cout << " ";
				}
			}
			//cout << endl;
		}
		pCursor = SDL_CreateCursor( data, mask, img.width(), img.height(), hotspotX, hotspotY );

		delete[] mask;
		delete[] data;

	} else {
	}
}