Click System

The Partridge Family were neither partridges nor a family. Discuss.
egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Click System

Post by egizz983 » May 6th, 2017, 4:16 pm

Hi guys havent been here for a while , was busy at work , so now was able to find free minute to code , have opened my last project and found a note about click system that is not working properly , its actually click system for GUI not sure if i should be dealing this for whole framework or keep with guy. So problem the same as you usually have with keyboard , you press a key once to go left but he will go more then once squire because of FPS , same with mouse click , i hit it once but because of high FPS its runs like 10 times or even more , so its not working properly .So was thinking to fix this over gui because not sure if i will be using this anywhere else , if you think that i should be dealing over whole framework , fixing this issue in a Mouse class , tell me please .

So my GUI system works like this gui manager have 3 functions for handling a elements : Draw, MouseHandler, KeyboardHandler . in this specific case we only need to look at MouseHandler .

Code: Select all

https://pastebin.com/EZTkFrci
so its works pretty simple this function handles all mouse event stack in mouse class , and calling it for each of GUI elements callbacks .
there is actually two callbacks witch are related : OnLeftPressed , OnLeftReleased ;
and those callback have been called based on event .
This is GUIElement witch is entity class for each elements and almost all clicks are managing the same , only specific elements have been overriding those

Code: Select all

https://pastebin.com/RZRv9QaD
so the problem is obvious . and i cant think of anything good to solve it , Chili was saying me something long time ago but i have forgot :D

. What i was thinking is to add one more Bool variable witch is "Clicked" and then

Code: Select all

OnLeftPress(){ Click = true;} 
and

Code: Select all

OnLeftRelease(){ if(IsHover() && Click){ Clicked = true;} }

Code: Select all

IsClicked(){return Clicked;} 
i guess that would work(maybe) , but the problem is that Clicked will never been reset to false in this case so , this solution is not work . need your advice on how to solve this thing . PS sorr for no GitHub

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Click System

Post by albinopapa » May 6th, 2017, 6:15 pm

If you are using the chili 2016 framework, then use the Read function in the Mouse class to get Mouse::Events. This way you only get a click message when left is pressed instead of just checking if LeftIsPressed.

Something like:

Code: Select all

const auto mouseEventType = mouse.Read().GetType();
if( mouseEventType == Mouse::Event::LPress )
{
     // ....
}
else if( mouseEventType == Mouse::Event::LRelease )
{
     // ....
}

If the mouse event queue is empty, then Event::Type will be Invalid.
The mouse event queue will add new events when windows sends new events, so a button press or release, a mouse move or wheel data.
The read function pops one element out of the queue each time it's read, so when the queue is empty, it will return the Event::Type::Invalid event.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: Click System

Post by egizz983 » May 6th, 2017, 7:20 pm

Alibinopapa have you looked at my MouseHandler function ? thats the way i am doing now , using read and then based on event calling Element callbacks

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Click System

Post by albinopapa » May 7th, 2017, 5:09 am

Wow, don't know how I missed it, sorry. Since you are using Read, you shouldn't get any messages accept for press and release which only happen when you press and release the mouse button. I suppose we'd need the actual code to test it to give any definitive answers.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: Click System

Post by egizz983 » May 7th, 2017, 1:48 pm

Okay so here is the solution (sorr if you prefer GIthub) , when you reach login step do not worry about login details just hit login . One you get into game state you will see a map and a button in right bot corner .
Image
i am using this button for testing , and the code of this button you can see at GameStateGamePlay.cpp void GameStateGamePlay::ButtonHandler()

Everything else is part of GUI system GUIManager.cpp and GUIElement.h , GUIManager only related function is MouseHandler();

The button as i mentioned should enable and disable(Toggle) GUIGroup . this doent work because i am not handling click properly and one click results as 10-15 depends on frame rate .
Attachments
Game.rar
(2.53 MiB) Downloaded 128 times

coolmoon
Posts: 7
Joined: April 7th, 2017, 12:17 am

Re: Click System

Post by coolmoon » May 7th, 2017, 6:34 pm

hey egizz983,
first of all I don't know shit, I am just starting out and don't understand much of your code. that being said in GUIButton.cpp I added a "Click = false;" as shown below. It probably breaks other shit but does toggle the button. thought it might give you a clue on what to fix

~CoolMoon

Code: Select all

void GUIButton::Draw(Graphics & gfx)
{
	if (Enabled) 
	{
		Surf[0]->Draw(Box.left, Box.top, gfx, Alfa);
		gfx.DrawText(title, Box, bFont, fontColor, TextSurface::Alignment::Center);
		if (Click) 
		{
			Surf[2]->Draw(Box.left, Box.top, gfx, Alfa);
			gfx.DrawText(title, Box, bFont, fontColor, TextSurface::Alignment::Center);
			Click = false;
		}

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: Click System

Post by egizz983 » May 7th, 2017, 6:56 pm

as i said the only thing you should be looking at is GameStateGamePlay.cpp (Button handler function) ,GUIManager.cpp (MouseHandler function) and GUIElement.h mouse callsbacks this is not even related at all , and because you add Click= false ; you would not even notice an effect witch is an active surface draw over main button textures or its actually just a mask i made for a button surface , its not related ...

coolmoon
Posts: 7
Joined: April 7th, 2017, 12:17 am

Re: Click System

Post by coolmoon » May 7th, 2017, 7:18 pm

Ok, so like I said I don't understand your code, and didn't mean this to be a fix. If you add the Click = false; like I did you do see an effect which is it toggles a menu or something for Gang or Character. I only posted so it might help you track your problem down.

anyway good luck

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: Click System

Post by egizz983 » May 7th, 2017, 7:45 pm

you would not see an effect you get this : when you click mouse you set Click = true ; and if its click=true after draw you set him to false and the next frame when it goes it wont be draw en again ,and because game runs 60 frame per second you wont see any effect. I know where problem is i just need an advice on how to solve it , i mean there is a shitty way around witch i dont wanna do it , and problem is not with drawing at all it about how i am currently handling mouse clicks

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Click System

Post by albinopapa » May 8th, 2017, 2:03 am

What I found so far is you are only getting a single LPress message, but I'm having troubles finding an instance where Click is turning to false except through OnLeftRelease(), but again, Mouse::Read() is only sending one LRelease message when you lift your finger from the mouse button and not each frame.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply