Пример #1
0
Cursor::Cursor(image::ImageData *data, int hotx, int hoty)
	: cursor(nullptr)
	, type(CURSORTYPE_IMAGE)
	, systemType(CURSOR_MAX_ENUM)
{
	Uint32 rmask, gmask, bmask, amask;
#ifdef LOVE_BIG_ENDIAN
	rmask = 0xFF000000;
	gmask = 0x00FF0000;
	bmask = 0x0000FF00;
	amask = 0x000000FF;
#else
	rmask = 0x000000FF;
	gmask = 0x0000FF00;
	bmask = 0x00FF0000;
	amask = 0xFF000000;
#endif

	int w = data->getWidth();
	int h = data->getHeight();
	int pitch = w * 4;

	SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(data->getData(), w, h, 32, pitch, rmask, gmask, bmask, amask);
	if (!surface)
		throw love::Exception("Cannot create cursor: out of memory!");

	cursor = SDL_CreateColorCursor(surface, hotx, hoty);
	SDL_FreeSurface(surface);

	if (!cursor)
		throw love::Exception("Cannot create cursor: %s", SDL_GetError());
}
Пример #2
0
static SDL_Cursor*
init_color_cursor(const char *file)
{
    SDL_Cursor *cursor = NULL;
    SDL_Surface *surface = SDL_LoadBMP(file);
    if (surface) {
        if (surface->format->palette) {
            SDL_SetColorKey(surface, 1, *(Uint8 *) surface->pixels);
        } else {
            switch (surface->format->BitsPerPixel) {
            case 15:
                SDL_SetColorKey(surface, 1, (*(Uint16 *)surface->pixels) & 0x00007FFF);
                break;
            case 16:
                SDL_SetColorKey(surface, 1, *(Uint16 *)surface->pixels);
                break;
            case 24:
                SDL_SetColorKey(surface, 1, (*(Uint32 *)surface->pixels) & 0x00FFFFFF);
                break;
            case 32:
                SDL_SetColorKey(surface, 1, *(Uint32 *)surface->pixels);
                break;
            }
        }
        cursor = SDL_CreateColorCursor(surface, 0, 0);
        SDL_FreeSurface(surface);
    }
    return cursor;
}
Пример #3
0
/**
 * @brief Check call to SDL_CreateColorCursor and SDL_FreeCursor
 *
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_CreateColorCursor
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor
 */
int
mouse_createFreeColorCursor(void *arg)
{
    SDL_Surface *face;
    SDL_Cursor *cursor;

    /* Get sample surface */
    face = SDLTest_ImageFace();
    SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL");
    if (face == NULL) return TEST_ABORTED;

    /* Create a color cursor from surface */
    cursor = SDL_CreateColorCursor(face, 0, 0);
        SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
        SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");
    if (cursor == NULL) {
        SDL_FreeSurface(face);
        return TEST_ABORTED;
    }

    /* Free cursor again */
    SDL_FreeCursor(cursor);
    SDLTest_AssertPass("Call to SDL_FreeCursor()");

    /* Clean up */
    SDL_FreeSurface(face);

    return TEST_COMPLETED;
}
Пример #4
0
bool Menu::Init()
{
    if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
    {
        printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
        return false;
    }
    //Create window
    Window = SDL_CreateWindow( "Menu", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480
                               , SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE );
    if( Window == NULL )
    {
        printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
        return false;
    }

    SDL_SetWindowMinimumSize(Window, 640, 480);
    SDL_GetWindowSize(Window, &WINDOW_WIDTH, &WINDOW_HEIGHT);

    Icon = IMG_Load("icon.png");
    if(Icon == NULL)
    {
        printf( "Icon could not be loaded! SDL_Error: %s\n", SDL_GetError() );
        return false;
    }

    SDL_SetWindowIcon(Window, Icon);

    Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if(Renderer == NULL) {
        printf( "Renderer could not be created! SDL_Error: %s\n", SDL_GetError() );
        return false;
    }

    cursorSurf = IMG_Load("cursor.png");
    if(cursorSurf == NULL)
    {
        printf( "Cursor image could not be loaded! SDL_Error: %s\n", SDL_GetError() );
        return false;
    }

    cursor = SDL_CreateColorCursor(cursorSurf, 0, 0);
    if(cursor == NULL)
    {
        printf( "Cursor could not be created! SDL_Error: %s\n", SDL_GetError() );
        return false;
    }

    SDL_SetCursor(cursor);


    Background = LoadKartinka("tank_back.png", Renderer);

    single_Player.load(Renderer, "single.png", 265, 116);
    two_Players.load(Renderer, "two.png", 265, 116);
    exit.load(Renderer, "exit.png", 265, 116);

    return true;
}
Пример #5
0
/* utility function mostly a copy of SDL_CreateCursor but allows us to change
 * color and supports blenders flipped bits */
static SDL_Cursor *
sdl_ghost_CreateCursor(const Uint8 *data,
                       const Uint8 *mask,
                       int w,
                       int h,
                       int hot_x,
                       int hot_y)
{
	SDL_Surface *surface;
	SDL_Cursor *cursor;
	int x, y;
	Uint32 *pixel;
	Uint8 datab = 0, maskb = 0;
	const Uint32 black = 0xFF000000;
	const Uint32 white = 0xFFFFFFFF;
	const Uint32 transparent = 0x00000000;

	/* Make sure the width is a multiple of 8 */
	w = ((w + 7) & ~7);

	/* Create the surface from a bitmap */
	surface = SDL_CreateRGBSurface(0, w, h, 32,
	                               0x00FF0000,
	                               0x0000FF00,
	                               0x000000FF,
	                               0xFF000000);
	if (!surface) {
		return NULL;
	}
	for (y = 0; y < h; ++y) {
		pixel = (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch);
		for (x = 0; x < w; ++x) {
			if ((x % 8) == 0) {
				datab = *data++;
				maskb = *mask++;

				/* reverse bit order */
				datab = (datab * 0x0202020202ULL & 0x010884422010ULL) % 1023;
				maskb = (maskb * 0x0202020202ULL & 0x010884422010ULL) % 1023;
			}
			if (maskb & 0x80) {
				*pixel++ = (datab & 0x80) ?  white : black;
			}
			else {
				*pixel++ = (datab & 0x80) ? white : transparent;
			}
			datab <<= 1;
			maskb <<= 1;
		}
	}

	cursor = SDL_CreateColorCursor(surface, hot_x, hot_y);

	SDL_FreeSurface(surface);

	return cursor;
}
static SDL_Cursor*
init_color_cursor(const char *file)
{
    SDL_Cursor *cursor = NULL;
    SDL_Surface *surface = SDL_LoadBMP(file);
    if (surface) {
        cursor = SDL_CreateColorCursor(surface, 0, 0);
        SDL_FreeSurface(surface);
    }
    return cursor;
}
Пример #7
0
bool Game::LoadContent()
{
    ///TEXTURES

    handSurf = IMG_Load("./Resources/Images/cursor.png");
    if(handSurf == NULL)
        return false;

    hand = SDL_CreateColorCursor(handSurf, 0, 0);

    if(hand == NULL)
        return false;

    SDL_SetCursor(hand);


    empty_layer.Tileset_Image = OnLoad(Renderer, TILESET);

    empty_layer.Hover_Image = OnLoad(Renderer, TILESET);

    Character.Image = OnLoad(Renderer, "./Resources/Images/ogre.png");

    if(empty_layer.Hover_Image == NULL)
    {
        return false;
    }

    if(empty_layer.Tileset_Image == NULL)
    {
        return false;
    }

    if(Character.Image == NULL)
    {
        return false;
    }

    SDL_SetTextureAlphaMod(empty_layer.Hover_Image, 100);

    ///MAPS

    empty_layer.loadMap.open("./Resources/empty_layer100x100.layer");

    if(empty_layer.LoadTileSet() == false)
    {
        cout<<"Map not loaded"<<endl;
        Sleep(1000);
        return false;
    }


    return true;
}
Пример #8
0
	int Surface::createColorCursor(State & state, SDL_Surface * surface){
		Stack * stack = state.stack;

		Cursor * interfaceCursor = state.getInterface<Cursor>("LuaSDL_Cursor");
		interfaceCursor->push(
			SDL_CreateColorCursor(
				surface,
				stack->to<int>(1),
				stack->to<int>(2)
			), true
		);
		return 1;
	}
Пример #9
0
bool Cursor::createFromSurface(const Surface &surface, const Point &p)
{
    SDL_Cursor *created = SDL_CreateColorCursor(surface, p.x, p.y);
    if (!created)
    {
        Error() << "creating cursor from surface: " << SDL_GetError();
    }
    else
    {
        load(created);
    }
    return created;
}
Пример #10
0
void
sdl_set_cursor(const sprite_t *sprite)
{
	if (NULL != cursor) {
		SDL_SetCursor(NULL);
		SDL_FreeCursor(cursor);
	}
	if (NULL == sprite) {
		return;
	}
	SDL_Surface *surface = create_transp_surface(sprite, 0);
	cursor = SDL_CreateColorCursor(surface, 8, 8);
	SDL_SetCursor(cursor);
}
Пример #11
0
void Cursor::ApplyOSCursorShape()
{
    // Mobile platforms do not support applying OS cursor shapes: comment out to avoid log error messages
#if !defined(ANDROID) && !defined(IOS)
    if (!osShapeDirty_ || !GetSubsystem<Input>()->IsMouseVisible() || GetSubsystem<SystemUI>()->GetCursor() != this)
        return;

    CursorShapeInfo& info = shapeInfos_[shape_];

    // Remove existing SDL cursor if is not a system shape while we should be using those, or vice versa
    if (info.osCursor_ && info.systemDefined_ != useSystemShapes_)
    {
        SDL_FreeCursor(info.osCursor_);
        info.osCursor_ = 0;
    }

    // Create SDL cursor now if necessary
    if (!info.osCursor_)
    {
        // Create a system default shape
        if (useSystemShapes_ && info.systemCursor_ >= 0 && info.systemCursor_ < CS_MAX_SHAPES)
        {
            info.osCursor_ = SDL_CreateSystemCursor((SDL_SystemCursor)osCursorLookup[info.systemCursor_]);
            info.systemDefined_ = true;
            if (!info.osCursor_)
                ATOMIC_LOGERROR("Could not create system cursor");
        }
        // Create from image
        else if (info.image_)
        {
            SDL_Surface* surface = info.image_->GetSDLSurface(info.imageRect_);

            if (surface)
            {
                info.osCursor_ = SDL_CreateColorCursor(surface, info.hotSpot_.x_, info.hotSpot_.y_);
                info.systemDefined_ = false;
                if (!info.osCursor_)
                    ATOMIC_LOGERROR("Could not create cursor from image " + info.image_->GetName());
                SDL_FreeSurface(surface);
            }
        }
    }

    if (info.osCursor_)
        SDL_SetCursor(info.osCursor_);

    osShapeDirty_ = false;
#endif
}
Пример #12
0
void Cursor::ApplyShape()
{
    CursorShapeInfo& info = shapeInfos_[shape_];
    texture_ = info.texture_;
    imageRect_ = info.imageRect_;
    SetSize(info.imageRect_.Size());

    // If the OS cursor is being shown, define/set SDL cursor shape if necessary
    // Only do this when we are the active UI cursor
    if (GetSubsystem<Input>()->IsMouseVisible() && GetSubsystem<UI>()->GetCursor() == this)
    {
        // Remove existing SDL cursor if is not a system shape while we should be using those, or vice versa
        if (info.osCursor_ && info.systemDefined_ != useSystemShapes_)
        {
            SDL_FreeCursor(info.osCursor_);
            info.osCursor_ = 0;
        }

        // Create SDL cursor now if necessary
        if (!info.osCursor_)
        {
            // Create a system default shape
            if (useSystemShapes_)
            {
                info.osCursor_ = SDL_CreateSystemCursor((SDL_SystemCursor)osCursorLookup[shape_]);
                info.systemDefined_ = true;
                if (!info.osCursor_)
                    LOGERROR("Could not create system cursor");
            }
            // Create from image
            else if (info.image_)
            {
                SDL_Surface* surface = info.image_->GetSDLSurface(info.imageRect_);
                
                if (surface)
                {
                    info.osCursor_ = SDL_CreateColorCursor(surface, info.hotSpot_.x_, info.hotSpot_.y_);
                    info.systemDefined_ = false;
                    if (!info.osCursor_)
                        LOGERROR("Could not create cursor from image " + info.image_->GetName());
                    SDL_FreeSurface(surface);
                }
            }
        }

        if (info.osCursor_)
            SDL_SetCursor(info.osCursor_);
    }
}
Пример #13
0
void
sdl_set_cursor(const sprite_t *sprite)
{
	if (cursor != NULL) {
		SDL_SetCursor(NULL);
		SDL_FreeCursor(cursor);
		cursor = NULL;
	}

	if (sprite == NULL) return;

	SDL_Surface *surface = create_surface_from_sprite(sprite);
	cursor = SDL_CreateColorCursor(surface, 8, 8);
	SDL_SetCursor(cursor);
}
Пример #14
0
bool I_SetCursor(FTexture *cursorpic)
{
	static SDL_Cursor *cursor;
	static SDL_Surface *cursorSurface;

	if (cursorpic != NULL && cursorpic->UseType != ETextureType::Null)
	{
		// Must be no larger than 32x32.
		if (cursorpic->GetWidth() > 32 || cursorpic->GetHeight() > 32)
		{
			return false;
		}

		if (cursorSurface == NULL)
			cursorSurface = SDL_CreateRGBSurface (0, 32, 32, 32, MAKEARGB(0,255,0,0), MAKEARGB(0,0,255,0), MAKEARGB(0,0,0,255), MAKEARGB(255,0,0,0));

		SDL_LockSurface(cursorSurface);
		uint8_t buffer[32*32*4];
		memset(buffer, 0, 32*32*4);
		FBitmap bmp(buffer, 32*4, 32, 32);
		cursorpic->CopyTrueColorPixels(&bmp, 0, 0);
		memcpy(cursorSurface->pixels, bmp.GetPixels(), 32*32*4);
		SDL_UnlockSurface(cursorSurface);

		if (cursor)
			SDL_FreeCursor (cursor);
		cursor = SDL_CreateColorCursor (cursorSurface, 0, 0);
		SDL_SetCursor (cursor);
	}
	else
	{
		if (cursor)
		{
			SDL_SetCursor (NULL);
			SDL_FreeCursor (cursor);
			cursor = NULL;
		}
		if (cursorSurface != NULL)
		{
			SDL_FreeSurface(cursorSurface);
			cursorSurface = NULL;
		}
	}
	return true;
}
Пример #15
0
    void SDLCursorManager::_createCursorFromResource(const std::string& name, int rotDegrees, osg::Image* image, Uint8 size_x, Uint8 size_y, Uint8 hotspot_x, Uint8 hotspot_y)
    {
        if (mCursorMap.find(name) != mCursorMap.end())
            return;

        osg::ref_ptr<osg::Image> decompressed = decompress(image, static_cast<float>(rotDegrees));

        SDL_Surface* surf = SDLUtil::imageToSurface(decompressed, false);

        //set the cursor and store it for later
        SDL_Cursor* curs = SDL_CreateColorCursor(surf, hotspot_x, hotspot_y);
        mCursorMap.insert(CursorMap::value_type(std::string(name), curs));

        //clean up
        SDL_FreeSurface(surf);

        _setGUICursor(name);
    }
Пример #16
0
/**
	init_system_ColorCursor()-- Create a colored mouse cursor image
 */
SDL_Cursor *init_system_ColorCursor(CURSOR cur, const char *fileName)
{

	iV_Image *psSprite = (iV_Image *)malloc(sizeof(iV_Image));
	if (!psSprite)
	{
		debug(LOG_FATAL, "Could not allocate memory for cursor sprite. Exiting.");
		exit(-1);
	}

	if (!iV_loadImage_PNG(fileName, psSprite))
	{
		debug(LOG_FATAL, "Could not load cursor sprite. Exiting.");
		exit(-1);
	}

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	uint32_t rmask = 0xff000000;
	uint32_t gmask = 0x00ff0000;
	uint32_t bmask = 0x0000ff00;
	uint32_t amask = 0x000000ff;
#else
	uint32_t rmask = 0x000000ff;
	uint32_t gmask = 0x0000ff00;
	uint32_t bmask = 0x00ff0000;
	uint32_t amask = 0xff000000;
#endif

	SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(psSprite->bmp, psSprite->width, psSprite->height, psSprite->depth * 8, psSprite->width * 4, rmask, gmask, bmask, amask);
	SDL_Cursor *pointer = SDL_CreateColorCursor(surface, psSprite->width / 2, psSprite->height / 2);	// We center the hotspot for all (FIXME ?)
	if (!pointer)
	{
		debug(LOG_FATAL, "Could not create cursor because %s", SDL_GetError());
		exit(-1);
	}

	// free up image & surface data
	free(psSprite->bmp);
	free(psSprite);
	SDL_FreeSurface(surface);

	return pointer;
}