Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Toggle problem
 Post Posted: September 9th, 2017, 6:17 am 
 

Joined: June 17th, 2017, 5:46 pm
Posts: 8
Location: Sweden
Hi. I am in the process of expanding the original chili framework to support GUI (menus, buttons etc)
But there is one small thing that has been bugging me for days and I have tried various different ways to solve it but none have worked.

Code:
      if (mouse.LeftIsPressed())
      {
         isClicked = !isClicked;
      }


Basically I want the button to toggle every time it is clicked once, but if I hold down the left mouse button, the button toggles back and fourth many times quickly, which is not what i want. I want it to toggle once no matter how long you are holding the left mouse button for.

Any help appreciated, thanks!


Top 
 Profile  
Reply with quote  
 Post subject: Re: Toggle problem
 Post Posted: September 9th, 2017, 9:48 am 
 

Joined: April 13th, 2017, 8:35 pm
Posts: 38
http://wiki.planetchili.net/index.php?title=Mouse_(Chili_Framework)#Examples_of_Use


Top 
 Profile  
Reply with quote  
 Post subject: Re: Toggle problem
 Post Posted: September 9th, 2017, 1:22 pm 
 

Joined: September 9th, 2017, 1:19 pm
Posts: 1
Not sure if that wiki page helped you, but my solution was to run it when mouse is depressed instead of pressed. Can be done by keeping track of bool.
e.g.

Code:
if( wnd.mouse.LeftIsPressed() )
{
   wasPressed = true;
}
else
{
   if( wasPressed )
   {
      // do code
   }
   wasPressed = false;
}


Top 
 Profile  
Reply with quote  
 Post subject: Re: Toggle problem
 Post Posted: September 9th, 2017, 2:17 pm 
 

Joined: June 17th, 2017, 5:46 pm
Posts: 8
Location: Sweden
Slidy wrote:
Not sure if that wiki page helped you, but my solution was to run it when mouse is depressed instead of pressed. Can be done by keeping track of bool.
e.g.

Code:
if( wnd.mouse.LeftIsPressed() )
{
   wasPressed = true;
}
else
{
   if( wasPressed )
   {
      // do code
   }
   wasPressed = false;
}

Thank you kind sir


Top 
 Profile  
Reply with quote  
 Post subject: Re: Toggle problem
 Post Posted: September 10th, 2017, 1:45 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2826
Location: Oklahoma, United States
Just want to point out that the info on the wiki is a better fit for what you are trying to do.

Code:
   while( !wnd.mouse.IsEmpty() )
   {
      const auto e = wnd.mouse.Read();

      if( e.GetType() == Mouse::Event::Type::LPress )
      {
         // Handle press event
      }
      else if( e.GetType() == Mouse::Event::Type::LRelease )
      {
         // Handle release 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


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 5 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: