_X_ int windowThumbImageUpdate(objectKey thumbImage, const char *fileName, unsigned maxWidth, unsigned maxHeight, int stretch, color *background)
{
	// Desc: Update an existing window image component 'thumbImage', previously created with a call to windowNewThumbImage(), from the supplied image file name 'fileName'.  Dimension values 'maxWidth' and 'maxHeight' constrain the maximum image size.  The resulting image will be scaled down, if necessary, with the aspect ratio intact.  If 'fileName' is NULL, the image will become blank.

	int status = 0;
	image imageData;

	if (!libwindow_initialized)
		libwindowInitialize();

	// Check params.  File name and background can be NULL.
	if (!thumbImage || !maxWidth || !maxHeight)
		return (status = ERR_NULLPARAMETER);

	status = getImage(fileName, &imageData, maxWidth, maxHeight, stretch,
		background);

	if (status >= 0)
	{
		status = windowComponentSetData(thumbImage, &imageData, sizeof(image),
			1 /* redraw */);
	}

	imageFree(&imageData);
	return (status);
}
_X_ objectKey windowNewThumbImage(objectKey parent, const char *fileName, unsigned maxWidth, unsigned maxHeight, int stretch, componentParameters *params)
{
	// Desc: Create a new window image component from the supplied image file name 'fileName', with the given 'parent' window or container, and component parameters 'params'.  Dimension values 'maxWidth' and 'maxHeight' constrain the maximum image size.  The resulting image will be scaled down, if necessary, with the aspect ratio intact, unless 'stretch' is non-zero, in which case the thumbnail image will be resized to 'maxWidth' and 'maxHeight'.  If 'params' specifies a background color, any empty space will be filled with that color.  If 'fileName' is NULL, an empty image will be created.

	int status = 0;
	color *background = NULL;
	image imageData;
	objectKey thumbImage = NULL;

	if (!libwindow_initialized)
		libwindowInitialize();

	// Check params.  File name can be NULL.
	if (!parent || !maxWidth || !maxHeight || !params)
	{
		errno = ERR_NULLPARAMETER;
		return (thumbImage = NULL);
	}

	if (params->flags & WINDOW_COMPFLAG_CUSTOMBACKGROUND)
		background = &params->background;

	status = getImage(fileName, &imageData, maxWidth, maxHeight, stretch,
		background);

	if (status >= 0)
	{
		thumbImage = windowNewImage(parent, &imageData, draw_normal, params);
		if (!thumbImage)
			errno = ERR_NOCREATE;
	}

	imageFree(&imageData);
	return (thumbImage);
}
Beispiel #3
0
	bool Atlas::createTexure_( Logger & _logger, const MAGIC_CHANGE_ATLAS & c, LPDIRECT3DTEXTURE9 * _texture )
	{
		uint32_t image_width;
		uint32_t image_height;

		unsigned char * pixels = nullptr;

		if( c.data == nullptr )
		{
			pixels = imageLoadFromFile( c.file, image_width, image_height );
		}
		else
		{
			pixels = imageLoadFromMemory( c.data, c.length, image_width, image_height );
		}

		unsigned char * correct_pixels = pixels;

		UINT texture_width = getTexturePOW2( image_width );
		UINT texture_height = getTexturePOW2( image_height );

		LPDIRECT3DTEXTURE9 texture = NULL;
		if( m_pDevice->CreateTexture( texture_width, texture_height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL ) != D3D_OK )
		{
			return false;
		}

		D3DLOCKED_RECT lockedRect;
		DXCALL texture->LockRect( 0, &lockedRect, NULL, D3DLOCK_DISCARD );

		if( lockedRect.pBits == NULL || lockedRect.Pitch == 0 )
		{
			return false;
		}

		for( size_t i = 0; i != image_height; ++i )
		{
			unsigned char * image = correct_pixels + i * image_width * 4;
			unsigned char * bits = static_cast<unsigned char *>(lockedRect.pBits) + lockedRect.Pitch * i;

			std::copy( image, image + image_width * 4, bits );
		}

		DXCALL texture->UnlockRect( 0 );

		imageFree( pixels );

		*_texture = texture;

		return true;
	}
Beispiel #4
0
int main(int argc __attribute__((unused)), char *argv[])
{
	int status = 0;

	setlocale(LC_ALL, getenv(ENV_LANG));
	textdomain("mines");

	// Only work in graphics mode
	if (!graphicsAreEnabled())
	{
		printf(_("\nThe \"%s\" command only works in graphics mode\n"),
			argv[0]);
		return (errno = ERR_NOTINITIALIZED);
	}

	// Load our images
	status = imageLoad(MINE_IMAGE, 0, 0, &mineImage);
	if (status < 0)
	{
		printf(_("\nCan't load %s\n"), MINE_IMAGE);
		return (errno = status);
	}
	mineImage.transColor.green = 255;

	// Create a new window
	window = windowNew(multitaskerGetCurrentProcessId(), WINDOW_TITLE);

	// Register an event handler to catch window events.
	windowRegisterEventHandler(window, &eventHandler);

	// Generate mine field
	initialize();

	// Go live.
	windowSetVisible(window, 1);

	// Run the GUI
	windowGuiRun();

	// Destroy the window
	windowDestroy(window);

	imageFree(&mineImage);

	// Done
	return (0);
}
static int getImage(const char *fileName, image *imageData, unsigned maxWidth,
	unsigned maxHeight, int stretch, color *background)
{
	int status = 0;
	image loadImage;
	float scale = 0;
	unsigned thumbWidth = 0;
	unsigned thumbHeight = 0;

	memset(&loadImage, 0, sizeof(image));

	status = imageNew(imageData, maxWidth, maxHeight);
	if (status < 0)
		return (status);

	if (!stretch && background)
	{
		status = imageFill(imageData, background);
		if (status < 0)
			goto out;
	}

	if (fileName)
	{
		status = imageLoad(fileName, 0, 0, &loadImage);
		if (status < 0)
			goto out;

		// Scale the image
		thumbWidth = loadImage.width;
		thumbHeight = loadImage.height;

		// Presumably we need to shrink it?
		if (stretch)
		{
			thumbWidth = maxWidth;
			thumbHeight = maxHeight;
		}
		else
		{
			if (thumbWidth > maxWidth)
			{
				scale = ((float) maxWidth / (float) thumbWidth);
				thumbWidth = (unsigned)((float) thumbWidth * scale);
				thumbHeight = (unsigned)((float) thumbHeight * scale);
			}

			if (thumbHeight > maxHeight)
			{
				scale = ((float) maxHeight / (float) thumbHeight);
				thumbWidth = (unsigned)((float) thumbWidth * scale);
				thumbHeight = (unsigned)((float) thumbHeight * scale);
			}
		}

		if ((thumbWidth != loadImage.width) ||
			(thumbHeight != loadImage.height))
		{
			status = imageResize(&loadImage, thumbWidth, thumbHeight);
			if (status < 0)
				goto out;
		}

		status = imagePaste(&loadImage, imageData,
			((maxWidth - loadImage.width) / 2),
			((maxHeight - loadImage.height) / 2));
		if (status < 0)
			goto out;
	}

	status = 0;

out:
	if (loadImage.data)
		imageFree(&loadImage);

	if ((status < 0) && imageData->data)
		imageFree(imageData);

	return (status);
}
Beispiel #6
0
/** Main function **/
int main(int argc, char* args[])
{
	//
	// Initialize program

	// Init SDL
	SDL_Init(SDL_INIT_EVERYTHING);

	// Open window
	gbl::S_screen = SDL_SetVideoMode((int)cnst::WINDOW_WIDTH,(int)cnst::WINDOW_HEIGHT,32,SDL_SWSURFACE);

	// Set caption
	SDL_WM_SetCaption(cnst::WINDOW_CAPTION.c_str(), NULL);

	// Initialize fps regulator
	fpsCalc::GetInstance()->Init((double)cnst::TARGET_FPS);





	//
	// Load resources

	// Graphics
	res::S_title = imageLoad("resources/graphics/title.png");
	res::S_message = imageLoad("resources/graphics/message.png");

	// Sounds
	//





	//
	// Initialize game

	// Set state to title screen
	gbl::state = 2;

	// Initialize title screen
	scr_title_start();





	//
	// Main loop

	while(gbl::loop)
	{

		/*Events*/
		keystates = SDL_GetKeyState(NULL);
		while(SDL_PollEvent(&event))
		{
			if(event.type == SDL_QUIT)
				gbl::loop = false;

			// event
			if(event.type == SDL_KEYDOWN)
			{
				switch(event.key.keysym.sym)
				{
					case SDLK_SPACE:
						gbl::spacePressed = true;
					break;
				}
			}

		}

		// keystates
		doKeys();

		 switch(gbl::state)
		 {



			case 2: // title

				scr_title_step();
				scr_title_render_graphics();
				if(gbl::state == 3)
					scr_lvl_start();

			break;

			case 3: // level select

				scr_lvl_step();
				scr_lvl_render_graphics();
				if(gbl::state == 4)
					playLevel("resources/levels/lvl_01.pkm");


			break;

			case 4: // play

				//scr_title_step();
				//scr_title_render_graphics();

			break;



		 }//switch


	}//while




	//
	// Shutdown

	// SDL
	SDL_Quit();

	// Free images
	imageFree(res::S_title);
	imageFree(res::S_message);

	// Bye
	return 0;
}