• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Vortez

Need help to draw cursor properly

6 posts in this topic

I noticed a small bug in my remote desktop application related to drawing the cursor of the remote machine and im not sure how to solve it. The problem is that sometime, the cursor is not drawn at the proper location depending on the cursor. Also im using a weird hack to make it work for windows 7 and above and i don't think that's the right way to do it.

 

Here's the code im using right now:

void CScreenshot::DrawScreenCursor(HDC hDC)
{
    CURSORINFO CursorInfo;
    CursorInfo.cbSize = sizeof(CURSORINFO);
    GetCursorInfo(&CursorInfo);

    static DWORD Version = WinVer.DetectWindowsVersion();
    //static HCURSOR hCur = LoadCursor(NULL, IDC_ARROW);

    DWORD CursorWidth = GetSystemMetrics(SM_CXCURSOR);
    DWORD CursorHeight = GetSystemMetrics(SM_CYCURSOR);

    POINT CursorPos;
    GetCursorPos(&CursorPos);

    // Needed for XP or older windows
    if(Version < _WIN_VISTA_){
        CursorPos.x -= CursorWidth >> 2;
        CursorPos.y -= CursorHeight >> 2;
    }

    DrawIconEx(hDC, CursorPos.x, CursorPos.y, CursorInfo.hCursor, CursorWidth, CursorHeight, 0, NULL, DI_NORMAL);
}

If the cursor is the default arrow, this work fine, but if the cursor change for, let say, the resize cursor, then it's offset a little.

 

Now, after reading this post, im pretty sure this function could solve my problem, but im not sure how to do it.

 

The question is, how do i get the icon from the current cursor (so i can call GetIconInfo() with the right cursor)?


And, why do i need to divide the cursor width by 4 in recent version of windows? It's like i have all the pieces of the puzzle but i don't know how to make them fit togeter... Maybe if i could debug this or something that could help a lot.

 

Note: The mouse click always happen at the right spot, it's just the cursor that's offset a little.

 

EDIT: I just realised im already getting the cursor from GetCursorInfo(), but im still lost on how to solve the problem. Maybe the width and height im getting are wrong?

 

Any help appreciated.

Edited by Vortez
0

Share this post


Link to post
Share on other sites

The GetCursor (or GetCursorInfo, as you already pointed out) API(s) will give you the cursor's HCURSOR handle, and you can pass that handle to GetIconInfo (cast it to HICON).

Edited by tonemgub
1

Share this post


Link to post
Share on other sites

Humm, after reading a bit about the DI_DEFAULTSIZE parameter of DrawIconEx(), that should solve the size issue i think, but it's still not working. For example, i commented the lines

 

if(Version < _WIN_VISTA_){
CursorPos.x -= CursorWidth >> 2;
CursorPos.y -= CursorHeight >> 2;
}

 

and put the real cursor at (0, 0) on the screen, here's what i got. The cursor is offset by 10 pixels on the x and y axis... It's like i need to offset the cursor by half it's width and height, using something like this (the last reply).

 

Is there a way i could open the system cursors in a cursor editor program? Nvm, found them smile.png

 

Oh well, guess im gonna have to make a small app and do some testing... and get some sleep.

Edited by Vortez
0

Share this post


Link to post
Share on other sites

Seem like i solved it, i just had to substract the hotspot from the cursor location, and remove the width and height from the DrawIconEx() call

void CScreenshot::DrawScreenCursor(HDC hDC)
{
	POINT CursorPos;
	GetCursorPos(&CursorPos);
	
	CURSORINFO CursorInfo;
	CursorInfo.cbSize = sizeof(CURSORINFO);
	GetCursorInfo(&CursorInfo);

	ICONINFO IconInfo;
	ZeroMemory(&IconInfo, sizeof(ICONINFO));
	GetIconInfo((HICON)CursorInfo.hCursor, &IconInfo);

	int x = CursorPos.x - IconInfo.xHotspot;
	int y = CursorPos.y - IconInfo.yHotspot;

	DrawIconEx(hDC, x, y, CursorInfo.hCursor, 0, 0, 0, NULL, DI_NORMAL);
}

1

Share this post


Link to post
Share on other sites

This sounds like you need to get the cursor hotspot. Funnily you need to use GetIconInfo to retrieve that info.

 

 

Edit: Ninja'd

Edited by Endurion
1

Share this post


Link to post
Share on other sites

Yea, i was rather confused at first, then it hit me when i changed the hotspot of a cursor i modified. Heh, this bug been lurking in my code for 3 years, funny how just writting about a problem help to solve it.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0