School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,148 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,738 people online right now. Registration is fast and FREE... Join Now!




Dark GDK Mouse Help

 

Dark GDK Mouse Help, Catching Mouse clicks

srlester

27 Sep, 2009 - 10:54 AM
Post #1

New D.I.C Head
*

Joined: 28 Jan, 2009
Posts: 12



Thanked: 1 times
My Contributions
Let me start by saying Im sorry I dont have any code for you guys to go off of and Im not wanting you guys to do my work for me...I am however asking that if anyone knows where I can get a tutorial or even if they can show me the code it would be highly appreciated. Dont think I didnt google because I have a few times and everything I can find on it doesnt really help me.
I am working with Dark GDK on a 2d game. A reason I have no code for you guys is that Im working on my code one task at a time then Im going to compile it when I have it all done...(Testing aside). Im working on my Main Menu and Im not doing buttons Its like buttons but my backround is just a simple .bmp with what looks like buttons on it...(Haha no one will care if it works). I figured I could do something involving the mouse coordinates like if a mouse click is within a certain range of coordinates it would go from there...Such as if they clicked single player...It would start single player code...Im kinda at a wall here guys and I got guys working on the animations for single player and I really dont want to get behind on them because (It was my idea to do this) I need to be a good leader you know how it is with game programming once something goes wrong everyone starts jumping ship.

So any ideas, links, helpful opinions, just about anything to get me rolling again...I appreciate it in advance. Well im off to start googling...=)

User is offlineProfile CardPM
+Quote Post


SixOfEleven

RE: Dark GDK Mouse Help

27 Sep, 2009 - 06:12 PM
Post #2

lives.ToCode();
Group Icon

Joined: 18 Oct, 2008
Posts: 3,066



Thanked: 171 times
Dream Kudos: 775
Expert In: C, C#, XNA, Game Programming, Programming Concepts

My Contributions
I don't know much about DarkGDK but I do have a suggestion for you if you know how to get the position of the mouse. Since you said you are using a .bmp for this you will know the (x,y) coordinates of the 'buttons' on the image. You will also know the height and width of the buttons. Create arrays for each button with the X coordinate first, then the Y coordinate second followed by the width and the height.

CODE

int myButton[] = { 100, 100, 100, 20 }; // Sample button


Once you have found out if the mouse coordinates there is a simple function I wrote that would check if the mouse was inside the 'button'. It takes the x coordinate of the mouse and checks to see if it is between the starting point and the starting point plus the width. If that succeeds it checks if the y coordinate is between the starting Y coordinate and the starting Y coordinate and the height.

CODE

bool checkInside(int button[], int x, int y)
{
    if (x >= button[0] && x <= button[0] + button[2])
        if ( y >= button[1] && y <= button[1] + button[3])
            return true;
    return false;
}


Alternatively you could use the four points and just check them.

CODE

int myButton[] = { 100, 100, 200, 120 };

bool checkInside(int button[], int x, int y)
{
    if (x >= button[0] && x <= button[2])
        if ( y >= button[1] && y <= button[3])
            return true;
    return false;
}


I don't think it is hard to find mouse clicks with DarkGDK but I could be wrong as I've never used it. Those would be the two easiest methods of finding out if the mouse is clicked in the area you want though.
User is offlineProfile CardPM
+Quote Post

srlester

RE: Dark GDK Mouse Help

28 Sep, 2009 - 03:57 PM
Post #3

New D.I.C Head
*

Joined: 28 Jan, 2009
Posts: 12



Thanked: 1 times
My Contributions
Yeah thats kinda what I was thinking...Im going to test this code and get you something back.
User is offlineProfile CardPM
+Quote Post

lesPaul456

RE: Dark GDK Mouse Help

29 Sep, 2009 - 01:25 PM
Post #4

D.I.C Regular
Group Icon

Joined: 16 Apr, 2009
Posts: 258



Thanked: 35 times
Dream Kudos: 175
My Contributions
SixOfEleven pretty much summed it up.

Since you are just using an image with the buttons drawn on it (I've done that before), you need the screen coordinates of the buttons.
You can find these by loading the image into any image editor, and checking the coordinates (in pixels).

Once you have these, just go ahead and create a few arrays to store them, as SixOfEleven suggested.

Using DarkGDK, the code to check the position would be something like this (SixOfEleven's code remains the same)...

cpp

int singlePlayerButton[] = { 100, 100, 100, 20 };


if (dbMouseClick() == 1)
{
int x = dbMouseX();
int y = dbMouseY();

if (CheckInside(singlePlayerButton, x, y))
{
// Handle button select code here...
}
}

bool CheckInside(int button[], int x, int y)
{
// Use 1 of the 2 options SixOfEleven posted earlier...
}

User is offlineProfile CardPM
+Quote Post

srlester

RE: Dark GDK Mouse Help

29 Sep, 2009 - 05:58 PM
Post #5

New D.I.C Head
*

Joined: 28 Jan, 2009
Posts: 12



Thanked: 1 times
My Contributions
Thanks guys I got all this to work yesterday, I appreciate all the help even though I lacked code to show you guys. I'll make sure I share the finished code with ya.

This post has been edited by srlester: 29 Sep, 2009 - 05:59 PM
User is offlineProfile CardPM
+Quote Post

srlester

RE: Dark GDK Mouse Help

30 Sep, 2009 - 12:05 PM
Post #6

New D.I.C Head
*

Joined: 28 Jan, 2009
Posts: 12



Thanked: 1 times
My Contributions
Problem Solved for anyone with this same issue here is some code for you, Thanks for all the help this is my function I came up with...Its mostly all your ideas in one:
CODE
void checkMClick()
{
    dbShowMouse();
    if (dbMouseClick()==1)
    {
        int mx = dbMouseX();
        int my = dbMouseY();
        if (mx>=0 && my>=0)
        {
            dbText(5,5,"It works");
        }
    }
}

User is offlineProfile CardPM
+Quote Post

Gurthfin

RE: Dark GDK Mouse Help

25 Oct, 2009 - 10:42 PM
Post #7

New D.I.C Head
*

Joined: 21 Oct, 2009
Posts: 1

Hello, I create 2D Card game (Magic the Gathering) and I will use Drag and Drop cards, but I don't know how to make it. Can you advice me? First part can make from this topic, but how drag?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 04:09PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month