Beispiel #1
0
//! ---|> Window
void WindowSDL::doSetCursor(const Cursor * cursor) {
	static SDL_Cursor * systemCursor = SDL_GetCursor();
	if(sdlCursor != nullptr) {
		SDL_FreeCursor(sdlCursor);
		sdlCursor = nullptr;
	}
	if(cursor == nullptr) {
		SDL_SetCursor(systemCursor);
	} else {
		sdlCursor = convertBitmapToSDLCursor(cursor->getBitmap(), cursor->getHotSpotX(), cursor->getHotSpotY());
		SDL_SetCursor(sdlCursor);
	}
}
static void clear_cache()
{
	for(size_t n = 0; n != cursor::NUM_CURSORS; ++n) {
		if(cache[n] != NULL) {
			SDL_FreeCursor(cache[n]);
			cache[n] = NULL;
		}
	}

	if(cursor_buf != NULL) {
		cursor_buf = NULL;
	}
}
Beispiel #3
0
//------------------------------------------------------------------------------------------------------
//setter function that creates a system mouse cursor 
//------------------------------------------------------------------------------------------------------
void InputManager::SetMouseCursorType(CursorType cursorType)
{

	//first destroy old cursor object from memory
	SDL_FreeCursor(m_cursor);

	//based on type of cursor value passed, create mouse cursor using SDL ID flag value 
	m_cursor = SDL_CreateSystemCursor(SDL_SystemCursor(cursorType));
	
	//use cursor pointer to assign cursor to SDL
	SDL_SetCursor(m_cursor);

}
Beispiel #4
0
 void Dispose()
 {
     if (_initialised)
     {
         for (size_t i = 0; i < CURSOR_COUNT; i++)
         {
             SDL_FreeCursor(_loadedCursors[i]);
             _loadedCursors[i] = nullptr;
         }
         _currentCursor = CURSOR_UNDEFINED;
         _initialised = false;
     }
 }
	~sdl_cursor_handler()
	{
		m_inited = false;
		if (m_system_cursor)
		{
			SDL_SetCursor(m_system_cursor);
			m_system_cursor = NULL;
		}
		if (m_active_cursor)
		{
			SDL_FreeCursor(m_active_cursor);
			m_active_cursor = NULL;
		}
	}
Beispiel #6
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);
}
Beispiel #7
0
void ImGui_ImplSDL2_Shutdown()
{
    g_Window = NULL;

    // Destroy last known clipboard data
    if (g_ClipboardTextData)
        SDL_free(g_ClipboardTextData);
    g_ClipboardTextData = NULL;

    // Destroy SDL mouse cursors
    for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
        SDL_FreeCursor(g_MouseCursors[cursor_n]);
    memset(g_MouseCursors, 0, sizeof(g_MouseCursors));
}
Beispiel #8
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
}
Beispiel #9
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_);
    }
}
Beispiel #10
0
		Cursor::~Cursor()
		{
			SCP_vector<SDL_Cursor*>::iterator iter;

			for (iter = mAnimationFrames.begin(); iter != mAnimationFrames.end(); ++iter)
			{
				SDL_FreeCursor(*iter);
			}

			mAnimationFrames.clear();
			
			// Free cursor
			bm_release(mBitmapHandle);
			mBitmapHandle = -1;
		}
Beispiel #11
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);
}
Beispiel #12
0
int
main(int argc, char *argv[])
{
    int i;

	/* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);

    /* Initialize test framework */
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    if (!state) {
        return 1;
    }
    state->skip_renderer = SDL_TRUE;
    for (i = 1; i < argc;) {
        int consumed;

        consumed = SDLTest_CommonArg(state, i);
        if (consumed == 0) {
            consumed = -1;
        }
        if (consumed < 0) {
            SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
            quit(1);
        }
        i += consumed;
    }
    if (!SDLTest_CommonInit(state)) {
        quit(2);
    }

    /* Main render loop */
    done = 0;
#ifdef __EMSCRIPTEN__
    emscripten_set_main_loop(loop, 0, 1);
#else
    while (!done) {
        loop();
    }
#endif
    SDL_FreeCursor(cursor);

    quit(0);
    /* keep the compiler happy ... */
    return(0);
}
static VALUE sdl_setCursor_imp(VALUE mod,VALUE data,VALUE mask,VALUE w,
			       VALUE h,VALUE hot_x,VALUE hot_y)
{
  SDL_Cursor *newCursor;
  newCursor=SDL_CreateCursor(GETCSTR(data),GETCSTR(mask),NUM2INT(w),
			     NUM2INT(h),NUM2INT(hot_x),NUM2INT(hot_y));
  if( newCursor==NULL )
    rb_raise(eSDLError,"cursor creation failed :%s",SDL_GetError());
  SDL_SetCursor(newCursor);
  
  /* free old cursor */
  if( cursor!=NULL )
    SDL_FreeCursor(cursor);
  cursor=newCursor;
  
  return Qnil;
}
/**
 * @brief Check call to SDL_CreateCursor and SDL_FreeCursor
 *
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_CreateCursor
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor
 */
int
mouse_createFreeCursor(void *arg)
{
    SDL_Cursor *cursor;

    /* Create a cursor */
    cursor = _initArrowCursor(_mouseArrowData);
        SDLTest_AssertPass("Call to SDL_CreateCursor()");
        SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
    if (cursor == NULL) {
        return TEST_ABORTED;
    }

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

    return TEST_COMPLETED;
}
GHOST_TSuccess
GHOST_WindowSDL::setWindowCustomCursorShape(GHOST_TUns8 *bitmap,
                                            GHOST_TUns8 *mask,
                                            int sizex, int sizey,
                                            int hotX, int hotY,
                                            int fg_color, int bg_color)
{
	if (m_sdl_custom_cursor) {
		SDL_FreeCursor(m_sdl_custom_cursor);
	}

	m_sdl_custom_cursor = sdl_ghost_CreateCursor((const Uint8 *)bitmap,
	                                             (const Uint8 *)mask,
	                                             sizex, sizex,
	                                             hotX, hotY);

	SDL_SetCursor(m_sdl_custom_cursor);
	return GHOST_kSuccess;
}
Beispiel #16
0
void Cursor::DefineShape(CursorShape shape, Image* image, const IntRect& imageRect, const IntVector2& hotSpot)
{
    if (shape < CS_NORMAL || shape >= CS_MAX_SHAPES)
    {
        LOGERROR("Shape index out of bounds, can not define cursor shape");
        return;
    }

    if (!image)
        return;

    ResourceCache* cache = GetSubsystem<ResourceCache>();
    CursorShapeInfo& info = shapeInfos_[shape];

    // Prefer to get the texture with same name from cache to prevent creating several copies of the texture
    info.texture_ = cache->GetResource<Texture2D>(image->GetName(), false);
    if (!info.texture_)
    {
        Texture2D* texture = new Texture2D(context_);
        texture->SetData(SharedPtr<Image>(image));
        info.texture_ = texture;
    }

    info.image_ = image;
    info.imageRect_ = imageRect;
    info.hotSpot_ = hotSpot;

    // Remove existing SDL cursor
    if (info.osCursor_)
    {
        SDL_FreeCursor(info.osCursor_);
        info.osCursor_ = 0;
    }

    // Reset current shape if it was edited
    if (shape == shape_)
    {
        shape_ = CS_MAX_SHAPES;
        SetShape(shape);
    }
}
Beispiel #17
0
void
SDL_MouseQuit(void)
{
    SDL_Cursor *cursor, *next;
    SDL_Mouse *mouse = SDL_GetMouse();

    SDL_ShowCursor(1);

    cursor = mouse->cursors;
    while (cursor) {
        next = cursor->next;
        SDL_FreeCursor(cursor);
        cursor = next;
    }

    if (mouse->def_cursor && mouse->FreeCursor) {
        mouse->FreeCursor(mouse->def_cursor);
    }

    SDL_zerop(mouse);
}
Beispiel #18
0
void Cursor::DefineShape(const String& shape, Image* image, const IntRect& imageRect, const IntVector2& hotSpot)
{
    if (!image)
        return;

    ResourceCache* cache = GetSubsystem<ResourceCache>();

    if (!shapeInfos_.Contains(shape))
        shapeInfos_[shape] = CursorShapeInfo();

    CursorShapeInfo& info = shapeInfos_[shape];

    // Prefer to get the texture with same name from cache to prevent creating several copies of the texture
    info.texture_ = cache->GetResource<Texture2D>(image->GetName(), false);
    if (!info.texture_)
    {
        Texture2D* texture = new Texture2D(context_);
        texture->SetData(SharedPtr<Image>(image));
        info.texture_ = texture;
    }

    info.image_ = image;
    info.imageRect_ = imageRect;
    info.hotSpot_ = hotSpot;

    // Remove existing SDL cursor
    if (info.osCursor_)
    {
        SDL_FreeCursor(info.osCursor_);
        info.osCursor_ = 0;
    }

    // Reset current shape if it was edited
    if (shape_ == shape)
    {
        shape_ = String::EMPTY;
        SetShape(shape);
    }
}
Beispiel #19
0
void
SDL_DelMouse(int index)
{
    SDL_Mouse *mouse = SDL_GetMouse(index);

    if (!mouse) {
        return;
    }

    mouse->def_cursor = NULL;
    SDL_free(mouse->name);
    while (mouse->cursors) {
        SDL_FreeCursor(mouse->cursors);
    }

    if (mouse->FreeMouse) {
        mouse->FreeMouse(mouse);
    }
    SDL_free(mouse);

    SDL_mice[index] = NULL;
}
Beispiel #20
0
/**
 * Deletes the display screen, cursor, states and shuts down all the SDL subsystems.
 */
Game::~Game()
{
	Sound::stop();
	Music::stop();

	for (std::list<State*>::iterator i = _states.begin(); i != _states.end(); ++i)
	{
		delete *i;
	}

	SDL_FreeCursor(SDL_GetCursor());

	delete _cursor;
	delete _lang;
	delete _save;
	delete _mod;
	delete _screen;
	delete _fpsCounter;

	Mix_CloseAudio();

	SDL_Quit();
}
Beispiel #21
0
void
SDL_MouseQuit(void)
{
    SDL_Cursor *cursor, *next;
    SDL_Mouse *mouse = SDL_GetMouse();

    if (mouse->CaptureMouse) {
        SDL_CaptureMouse(SDL_FALSE);
    }
    SDL_SetRelativeMouseMode(SDL_FALSE);
    SDL_ShowCursor(1);

    cursor = mouse->cursors;
    while (cursor) {
        next = cursor->next;
        SDL_FreeCursor(cursor);
        cursor = next;
    }
    mouse->cursors = NULL;
    mouse->cur_cursor = NULL;

    if (mouse->def_cursor && mouse->FreeCursor) {
        mouse->FreeCursor(mouse->def_cursor);
        mouse->def_cursor = NULL;
    }

    if (mouse->clickstate) {
        SDL_free(mouse->clickstate);
        mouse->clickstate = NULL;
    }

    SDL_DelHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
                        SDL_MouseNormalSpeedScaleChanged, mouse);

    SDL_DelHintCallback(SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE,
                        SDL_MouseRelativeSpeedScaleChanged, mouse);
}
Beispiel #22
0
void sdlgl_free_mouse_cursors(void)
{
  SDL_SetCursor(sdlgl_cursor_main);
   
  /* the main cursor is made by SDL itself */
  sdlgl_cursor_main = NULL;

  if (sdlgl_cursor_up)
  {
    SDL_FreeCursor(sdlgl_cursor_up);
    sdlgl_cursor_up = NULL;
  }

  if (sdlgl_cursor_down)
  {
    SDL_FreeCursor(sdlgl_cursor_down);
    sdlgl_cursor_down = NULL;
  }

  if (sdlgl_cursor_left)
  {
    SDL_FreeCursor(sdlgl_cursor_left);
    sdlgl_cursor_left = NULL;
  }

  if (sdlgl_cursor_right)
  {
    SDL_FreeCursor(sdlgl_cursor_right);
    sdlgl_cursor_right = NULL;
  }

  if (sdlgl_cursor_hand)
  {
    SDL_FreeCursor(sdlgl_cursor_hand);
    sdlgl_cursor_hand = NULL;
  }

  if (sdlgl_cursor_cross)
  {
    SDL_FreeCursor(sdlgl_cursor_cross);
    sdlgl_cursor_cross = NULL;
  }
}
Beispiel #23
0
int
main(int argc, char *argv[])
{
    int i;
    const char *color_cursor = NULL;

    /* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    /* Initialize test framework */
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    if (!state) {
        return 1;
    }
    for (i = 1; i < argc;) {
        int consumed;

        consumed = SDLTest_CommonArg(state, i);
        if (consumed == 0) {
            color_cursor = argv[i];
            break;
        }
        if (consumed < 0) {
            SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
            quit(1);
        }
        i += consumed;
    }

    if (!SDLTest_CommonInit(state)) {
        quit(2);
    }

    for (i = 0; i < state->num_windows; ++i) {
        SDL_Renderer *renderer = state->renderers[i];
        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
        SDL_RenderClear(renderer);
    }

    if (color_cursor) {
        cursors[0] = init_color_cursor(color_cursor);
    } else {
        cursors[0] = init_system_cursor(arrow);
    }
    if (!cursors[0]) {
        SDL_Log("Error, couldn't create cursor\n");
        quit(2);
    }
    for (i = 0; i < SDL_NUM_SYSTEM_CURSORS; ++i) {
        cursors[1+i] = SDL_CreateSystemCursor((SDL_SystemCursor)i);
        if (!cursors[1+i]) {
            SDL_Log("Error, couldn't create system cursor %d\n", i);
            quit(2);
        }
    }
    SDL_SetCursor(cursors[0]);

    /* Main render loop */
    done = 0;
#ifdef __EMSCRIPTEN__
    emscripten_set_main_loop(loop, 0, 1);
#else
    while (!done) {
        loop();
    }
#endif

    for (i = 0; i < SDL_arraysize(cursors); ++i) {
        SDL_FreeCursor(cursors[i]);
    }
    quit(0);

    /* keep the compiler happy ... */
    return(0);
}
Beispiel #24
0
Cursor::~Cursor()
{
	if (cursor)
		SDL_FreeCursor(cursor);
}
Beispiel #25
0
void Mouse::setCursor( const MouseCursor cursor )
{
    SDL_SystemCursor cursorName(SDL_SYSTEM_CURSOR_ARROW);
    switch(cursor)
    {
        case io::MouseCursor_Progress:
            cursorName = SDL_SYSTEM_CURSOR_WAIT; break;
            
        case io::MouseCursor_Custom:
        case io::MouseCursor_ZoomIn:
        case io::MouseCursor_ZoomOut:
        case io::MouseCursor_Pointer:
        case io::MouseCursor_Copy:
        case io::MouseCursor_None:
        case io::MouseCursor_VerticalText:
        case io::MouseCursor_Cell:
        case io::MouseCursor_ContextMenu:
        case io::MouseCursor_Alias:
            cursorName = SDL_SYSTEM_CURSOR_ARROW; break;
            
        case io::MouseCursor_Cross:
            cursorName = SDL_SYSTEM_CURSOR_CROSSHAIR; break;
            
        case io::MouseCursor_Grab:
        case io::MouseCursor_Grabbing:
        case io::MouseCursor_Hand:
            cursorName = SDL_SYSTEM_CURSOR_HAND; break;
            
        case io::MouseCursor_Help:
            cursorName = SDL_SYSTEM_CURSOR_ARROW; break;
            
        case io::MouseCursor_IBeam:
            cursorName = SDL_SYSTEM_CURSOR_IBEAM; break;
            
        case io::MouseCursor_NoDrop:
        case io::MouseCursor_NotAllowed:
            cursorName = SDL_SYSTEM_CURSOR_NO; break;
            
        case io::MouseCursor_Move:
        case io::MouseCursor_MiddlePanning:
        case io::MouseCursor_EastPanning:
        case io::MouseCursor_WestPanning:
        case io::MouseCursor_NorthPanning:
        case io::MouseCursor_SouthPanning:
        case io::MouseCursor_NorthEastPanning:
        case io::MouseCursor_SouthWestPanning:
        case io::MouseCursor_NorthWestPanning:
        case io::MouseCursor_SouthEastPanning:
            cursorName = SDL_SYSTEM_CURSOR_SIZEALL; break;
            
        case io::MouseCursor_NorthEastSouthWestResize:
        case io::MouseCursor_NorthEastResize:
        case io::MouseCursor_SouthWestResize:
            cursorName = SDL_SYSTEM_CURSOR_SIZENESW; break;
            
        case io::MouseCursor_NorthSouthResize:
        case io::MouseCursor_NorthResize:
        case io::MouseCursor_RowResize:
        case io::MouseCursor_SouthResize:
            cursorName = SDL_SYSTEM_CURSOR_SIZENS; break;
            
        case io::MouseCursor_NorthWestResize:
        case io::MouseCursor_NorthWestSouthEastResize:
        case io::MouseCursor_SouthEastResize:
            cursorName = SDL_SYSTEM_CURSOR_SIZENWSE; break;
            
        case io::MouseCursor_EastWestResize:
        case io::MouseCursor_EastResize:
        case io::MouseCursor_ColumnResize:
        case io::MouseCursor_WestResize:
            cursorName = SDL_SYSTEM_CURSOR_SIZEWE; break;
            
        case io::MouseCursor_Wait:
            cursorName = SDL_SYSTEM_CURSOR_WAITARROW; break;
        default:
            LOG(LogType_ProgrammerAssert, "Unknow mouse cursor %d", cursor);
    }
    
    SDL_Cursor* oldCursor(m_Cursor);
    m_Cursor = SDL_CreateSystemCursor(cursorName);
    SDL_SetCursor(m_Cursor);
    if (oldCursor != nullptr)
        SDL_FreeCursor(oldCursor);
}
Beispiel #26
0
void MyCursor_Uninit()
{
  SDLGUITK_LOG( "MyCursor_Uninit() OK\n" );
  SDL_FreeCursor( cursor_default );
  SDL_FreeCursor( cursor_text );
}
Beispiel #27
0
THCursor::~THCursor()
{
    SDL_FreeSurface(m_pBitmap);
    SDL_FreeCursor(m_pCursorHidden);
}
Beispiel #28
0
void CGeneral::DeleteCursor()
{
   SDL_FreeCursor(m_HandCursor);
}
Beispiel #29
0
/*
 * This thread will read the buttons in an interrupt like fashion, and
 * also initializes SDL_INIT_VIDEO and the surfaces
 *
 * it must be done in the same thread (at least on windows) because events only
 * work in the thread which called SDL_Init(SubSystem) with SDL_INIT_VIDEO
 *
 * This is an SDL thread and relies on preemptive behavoir of the host
 **/
static int sdl_event_thread(void * param)
{
    SDL_InitSubSystem(SDL_INIT_VIDEO);

#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
    SDL_sem *wait_for_maemo_startup;
#endif
    SDL_Surface *picture_surface = NULL;
    int width, height;
    int depth;
    Uint32 flags;

    /* Try and load the background image. If it fails go without */
    if (background) {
        picture_surface = SDL_LoadBMP("UI256.bmp");
        if (picture_surface == NULL) {
            background = false;
            DEBUGF("warn: %s\n", SDL_GetError());
        }
    }
    
    /* Set things up */
    if (background)
    {
        width = UI_WIDTH;
        height = UI_HEIGHT;
    } 
    else 
    {
#ifdef HAVE_REMOTE_LCD
        if (showremote)
        {
            width = SIM_LCD_WIDTH > SIM_REMOTE_WIDTH ? SIM_LCD_WIDTH : SIM_REMOTE_WIDTH;
            height = SIM_LCD_HEIGHT + SIM_REMOTE_HEIGHT;
        }
        else
#endif
        {
            width = SIM_LCD_WIDTH;
            height = SIM_LCD_HEIGHT;
        }
    }

    depth = LCD_DEPTH;
    if (depth < 8)
        depth = 16;

    flags = SDL_HWSURFACE|SDL_DOUBLEBUF;
#if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA))
    /* Fullscreen mode for maemo app */
    flags |= SDL_FULLSCREEN;
#endif

    SDL_WM_SetCaption(UI_TITLE, NULL);

    if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, depth, flags)) == NULL) {
        panicf("%s", SDL_GetError());
    }

#if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA))
    /* SDL touch screen fix: Work around a SDL assumption that returns
       relative mouse coordinates when you get to the screen edges
       using the touchscreen and a disabled mouse cursor.
     */
    uint8_t hiddenCursorData = 0;
    SDL_Cursor *hiddenCursor = SDL_CreateCursor(&hiddenCursorData, &hiddenCursorData, 8, 1, 0, 0);

    SDL_ShowCursor(SDL_ENABLE);
    SDL_SetCursor(hiddenCursor);
#endif

    if (background && picture_surface != NULL)
        SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);

    /* let system_init proceed */
    SDL_SemPost((SDL_sem *)param);

#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
    /* Start maemo thread: Listen to display on/off events and battery monitoring */
    wait_for_maemo_startup = SDL_CreateSemaphore(0); /* 0-count so it blocks */
    SDL_Thread *maemo_thread = SDL_CreateThread(maemo_thread_func, wait_for_maemo_startup);
#endif

    /*
     * finally enter the button loop */
    gui_message_loop();

#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
    /* Ensure maemo thread is up and running */
    SDL_SemWait(wait_for_maemo_startup);
    SDL_DestroySemaphore(wait_for_maemo_startup);

#if (CONFIG_PLATFORM & PLATFORM_MAEMO5)
    pcm_shutdown_gstreamer();
#endif

    g_main_loop_quit (maemo_main_loop);
    g_main_loop_unref(maemo_main_loop);
    SDL_WaitThread(maemo_thread, NULL);
#endif

#if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA))
    SDL_FreeCursor(hiddenCursor);
#endif

    if(picture_surface)
        SDL_FreeSurface(picture_surface);

    /* Order here is relevent to prevent deadlocks and use of destroyed
       sync primitives by kernel threads */
#ifdef HAVE_SDL_THREADS
    sim_thread_shutdown(); /* not needed for native threads */
#endif
    return 0;
}
Beispiel #30
0
void
loop()
{
    int i;
    SDL_Event event;
        /* Check for events */
        while (SDL_PollEvent(&event)) {
            SDLTest_CommonEvent(state, &event, &done);

            if (event.type == SDL_WINDOWEVENT) {
                if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
                    SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
                    if (window) {
                        SDL_Log("Window %d resized to %dx%d\n",
                            event.window.windowID,
                            event.window.data1,
                            event.window.data2);
                    }
                }
                if (event.window.event == SDL_WINDOWEVENT_MOVED) {
                    SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
                    if (window) {
                        SDL_Log("Window %d moved to %d,%d (display %s)\n",
                            event.window.windowID,
                            event.window.data1,
                            event.window.data2,
                            SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
                    }
                }
            }
            if (event.type == SDL_KEYUP) {
                SDL_bool updateCursor = SDL_FALSE;

                if (event.key.keysym.sym == SDLK_LEFT) {
                    --system_cursor;
                    if (system_cursor < 0) {
                        system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
                    }
                    updateCursor = SDL_TRUE;
                } else if (event.key.keysym.sym == SDLK_RIGHT) {
                    ++system_cursor;
                    if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
                        system_cursor = 0;
                    }
                    updateCursor = SDL_TRUE;
                }
                if (updateCursor) {
                    SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
                    SDL_FreeCursor(cursor);
                    cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
                    SDL_SetCursor(cursor);
                }
            }
        }

        for (i = 0; i < state->num_windows; ++i) {
            SDL_Renderer *renderer = state->renderers[i];
            SDL_RenderClear(renderer);
            SDL_RenderPresent(renderer);
        }
#ifdef __EMSCRIPTEN__
    if (done) {
        emscripten_cancel_main_loop();
    }
#endif
}