Results 1 to 9 of 9

Thread: Problem with hand cursor

  1. #1
    Lesser Knight
    Join Date
    Dec 2010
    Posts
    35

    Default Problem with hand cursor

    Hi

    I have a problem with changing mouse cursor from standard arrow to hand under Ubuntu 11.
    The same code run on Windows works fine, cursor changes.
    I'm using 2.2.12 version of Clanlib.
    Is it a problem with my computer or my code?

    Shortened code looks like this:
    Code:
    window = CL_DisplayWindow(title, 960, 720, false, true);
    window.set_cursor(cl_cursor_hand);

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    See - http://www.rtsoft.com/forums/showthr...763-X11-Cursor

    We are just waiting for someone to send a patch.
    Code:
    void CL_X11Window::show_system_cursor()
    {
    	XDefineCursor(disp, window, system_cursor);
    }
    
    void CL_X11Window::set_cursor(CL_StandardCursor type)
    {
    	//TODO:
    }
    
    void CL_X11Window::set_cursor(CL_CursorProvider_X11 *cursor)
    {
    	//TODO:
    }
    void CL_X11Window::hide_system_cursor()
    {
    	XDefineCursor(disp, window, hidden_cursor);
    }
    
    
    int CL_CursorProvider_X11::create_cursor(const CL_SpriteDescription &sprite_description, const CL_Point &hotspot) const
    {
    	// TODO: Implement me :)
    	return 0;
    }

  3. #3
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    Code:
    CL_X11Window::CL_X11Window()
    : cursor_shape(0)
    {
    }
    
    CL_X11Window::~CL_X11Window()
    {
    	if (cursor_shape)
    		XFreeCursor(cursor_shape);
    }
    
    void CL_X11Window::show_system_cursor()
    {
    	XDefineCursor(disp, window, system_cursor);
    }
    
    void CL_X11Window::set_cursor(CL_StandardCursor type)
    {
    	if (cursor_shape)
    		XFreeCursor(cursor_shape);
    	cursor_shape = 0;
    	unsigned int shape_index = 0;
    	switch (type)
    	{
    	default:
    	case cl_cursor_hand: shape_index = 0xdeadbabe; // Useless X11 docs. They didn't say what index was what!
    	}
    	cursor_shape = XCreateFontCursor(disp, shape_index);
    	XDefineCursor(disp, window, cursor_shape);
    }
    
    void CL_X11Window::set_cursor(CL_CursorProvider_X11 *cursor)
    {
    	//TODO: XCreatePixmapCursor(display, source, mask, foreground_color, background_color, x, y)
    }
    void CL_X11Window::hide_system_cursor()
    {
    	XDefineCursor(disp, window, hidden_cursor);
    }
    
    
    int CL_CursorProvider_X11::create_cursor(const CL_SpriteDescription &sprite_description, const CL_Point &hotspot) const
    {
    	// TODO: XCreatePixmapCursor(display, source, mask, foreground_color, background_color, x, y)
    	return 0;
    }
    That's about as far as I got with a simple google search.

  4. #4
    Lesser Knight
    Join Date
    Dec 2010
    Posts
    35

    Default

    Thanks for fast reply. I've googled a little bit and declared one function.
    Index which Magnus mentioned is probably the one that can be found here: http://tronche.com/gui/x/xlib/appendix/b/
    I'm not sure but it works.
    My code, maybe it gets to next release?
    As you can see some cursors are omitted.
    Code:
    void CL_X11Window::set_cursor(CL_StandardCursor type)
    {
    	//experimental:
    	XFreeCursor(disp, system_cursor);
    	unsigned int index = 0;
    	switch (type)
    	{
    		case cl_cursor_arrow:
    			index = 2;
    			break;
    		case cl_cursor_appstarting:
    			index = 150;
    			break;
    		case cl_cursor_cross:
    			index = 30;
    			break;
    		case cl_cursor_hand:	
    			index = 58;
    			break;
    		case cl_cursor_ibeam:
    			index = 152;
    			break;
    		case cl_cursor_size_all:	
    			index = 6;
    			break;
    		case cl_cursor_size_ns:
    			index = 42;
    			break;
    		case cl_cursor_size_we:
    			index = 108;
    			break;
    		case cl_cursor_uparrow:
    			index = 6;
    			break;
    		case cl_cursor_wait:
    			index = 150;
    			break;
    		case cl_cursor_no:
    		case cl_cursor_size_nesw:
    		case cl_cursor_size_nwse:
    		default:
    			break;
    	}
    	system_cursor = XCreateFontCursor(disp, index);
    	XDefineCursor(disp, window, system_cursor);
    }

  5. #5
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Committed revised patch to SVN (ClanLib 2.3 and ClanLib 2.4)

    User definable cursors are a bit troublesome.

    It should be easy to implement, however quotes found (using google) does not fill me with confidence:
    Looking at the source code for libX11 and libXcursor suggests that XCreatePixmapCursor() *may* ignore the specified pixmap/mask and use some other cursor instead.
    I think the reason is historical. Very old applications sometimes define their own cursors because the standard ones looked horrible. Newer window managers said "no, we can do better than that" ... so searched for a newer themed version of the cursor.

    It does not matter, there is the obvious workaround. (As long as you do not mind the cursor being only visible in your application window)

    display.hide_cursor()
    main_loop()
    {
    sprite.draw( mouse_x, mouse_y )
    }
    Last edited by rombust; 08-22-2011 at 11:48 AM.

  6. #6
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

  7. #7
    Lesser Knight
    Join Date
    Dec 2010
    Posts
    35

    Default

    I've found a bug in my code.
    It shoud look like:
    Code:
    case cl_cursor_size_all:	
    	index = 52;
    break;
    Now the index is 6.

  8. #8
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I already spotted that

    the patch was applied like this...

    Code:
    void CL_X11Window::set_cursor(CL_StandardCursor type)
    {
    	if (system_cursor)
    	{
    		XFreeCursor(disp, system_cursor);
    		system_cursor = 0;
    	}
    	unsigned int index = XC_left_ptr;
    	switch (type)
    	{
    		case cl_cursor_arrow:
    			index = XC_left_ptr;
    			break;
    		case cl_cursor_appstarting:
    			index = XC_watch;
    			break;
    		case cl_cursor_cross:
    			index = XC_cross;
    			break;
    		case cl_cursor_hand:	
    			index = XC_hand2;
    			break;
    		case cl_cursor_ibeam:
    			index = XC_xterm;
    			break;
    		case cl_cursor_size_all:	
    			index = XC_fleur;
    			break;
    		case cl_cursor_size_ns:
    			index = XC_double_arrow;
    			break;
    		case cl_cursor_size_we:
    			index = XC_sb_h_double_arrow;
    			break;
    		case cl_cursor_uparrow:
    			index = XC_sb_up_arrow;
    			break;
    		case cl_cursor_wait:
    			index = XC_watch;
    			break;
    		case cl_cursor_no:
    			index = XC_X_cursor;
    			break;
    		case cl_cursor_size_nesw:
    		case cl_cursor_size_nwse:
    		default:
    			break;
    	}
    	system_cursor = XCreateFontCursor(disp, index);
    	XDefineCursor(disp, window, system_cursor);
    }

  9. #9
    Lesser Knight
    Join Date
    Dec 2010
    Posts
    35

    Default

    Definitely, you have too much free time Rombust.
    Thanks for your work.

Similar Threads

  1. X11 Cursor
    By spin in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 08-22-2011, 02:02 PM
  2. Obtaining the Cursor Position
    By Haku in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 02-28-2011, 11:35 AM
  3. Cursor and Sprite question.
    By Eng C. Born in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 04-18-2009, 02:05 PM
  4. CL_Sprite mouse cursor
    By AlfaRed in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 02-11-2009, 09:29 AM
  5. resolution, mouse cursor, etc
    By Uhfgood in forum Novashell Game Creation System
    Replies: 1
    Last Post: 09-06-2007, 12:40 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •