About Store Forum Documentation Contact



Post Reply 
double click on the same button(touschscreen)
Author Message
andrake Offline
Member

Post: #1
double click on the same button(touschscreen)
Hi!
i try to made that program work so:
on double click on gui_element do somethink

if i use:
if(t.db() && area=guielement) do something
it works as i expected on android , but not at PC

actual behaviour: on PC first click can be in any area and second should be in gui area

expected behaviour: first and second click should be in guy area that program do something

is there is something wrong or all in ok with this?
thank you
05-26-2014 04:43 AM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #2
RE: double click on the same button(touschscreen)
Every compiler has it's own order etc of reading things. There are some that reads the right argument first etcetc. So you can never be sure; i'm not sure if this'll help but.. Try

if(area == guiElement)
if(t.db())

This way you are sure that it'll always check when it is inside.

so.. if(Gui.msLit() ==&myButton) if(Ms.db(0)) as an example on a normal pc application
05-26-2014 05:14 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: double click on the same button(touschscreen)
Quote:Every compiler has it's own order etc of reading things. There are some that reads the right argument first etcetc
I don't think that's the case.
I think "if(a && b)" will always proceed to b condition only if a was met, across all compilers

The issue you have is that 'db' stands for having a second click in a short amount of time, but it doesn't include anything related to mouse movement. So you need additional logic in your code.
05-26-2014 06:12 AM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #4
RE: double click on the same button(touschscreen)
(05-26-2014 06:12 AM)Esenthel Wrote:  
Quote:Every compiler has it's own order etc of reading things. There are some that reads the right argument first etcetc
I don't think that's the case.
I think "if(a && b)" will always proceed to b condition only if a was met, across all compilers

You cannot be sure of this.. As an example a common C function that takes three total arguments will create the assembly in such way that the arguments are pushed onto the stack reversed order and stored into the EAX.. Intel syntax. This is however outside the discussion but my point being, there's no mandatory way of compiling the order of code. When talking about if statements and arguments passed in a function there's nothing saying which order it has to be. Because of this it can vary from compiler to compiler.

However in a right - left ordered compiled solution the first argument with always be on top of the stack. Where as the left - right it would be wise-versa.

The only way to be completely sure of how you want your code to be ran is by doing several if statements so that you can order them yourself. This is completely out of discussion but can actually be good to know in certain cases. As you never know if somebody comes in with another compiler or with another version of a compiler where ordering has been changed. So an example like this would be complete failure :
Code:
bool EnterCriticalSection(Atomic<Bool> &b)?
{
     for(;;)
     if(b);
     else
     {
           b = true;
           return true;
     }
}
Atomic<Bool> b = true;
int main()
{
        int number = 5;
  
     if(number == 3 && EnterCriticalSection(b) || number == 5)
     {
     }
}

As if the compiler structure were to be wrong and first read EnterCriticalSection to see if the argument returns false and then if that's true going onto the number == 3 and then the second argument. The ordering of this cannot be taken for certain. As the boolean is true here the application would stop even though the number is not three because it first ran the function argument.
(This post was last modified: 05-26-2014 06:39 AM by TBJokers.)
05-26-2014 06:38 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: double click on the same button(touschscreen)
This is what I've found
http://stackoverflow.com/questions/13313...-evaluated

http://www.mochima.com/tutorials/conditionals.html
Quote:In C++, the logical operators && and || have an interesting property: short-circuit evaluation. The language rules require that when evaluating a composite condition, if the result from the first part (the expression on the left of the logical operator) is sufficient to determine the result of the condition, then the second part must not be evaluated.
05-26-2014 06:52 AM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #6
RE: double click on the same button(touschscreen)
You are actually correct, according to more detailed only an overloaded && operator would have unspecified evaluation order. According to C++ standard the && is left operand first if the left is false the compiler avoids calling the second operand. Same thing with ||and , operators. But that saying the "," operator is not the function "," it's the actual operator. And aswell seems to be with ternary, but other than that everything else is unspecified and shan't be taken for granted. Especially if you overload operators then you must make sure that the evaluation order is correct. Partial information taught from http://en.cppreference.com/w/cpp/language/eval_order
05-26-2014 07:05 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #7
RE: double click on the same button(touschscreen)
(t.db() && area=guielement) <-- Was the assignment intentional?
05-26-2014 01:51 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #8
RE: double click on the same button(touschscreen)
(05-26-2014 01:51 PM)Rubeus Wrote:  (t.db() && area=guielement) <-- Was the assignment intentional?

If it is I guess (t.db() &&(area=guielement))
wouldn't hurt.

assigning pointer in if alone will most likely work fine eg
if(area=guielement), but I've noticed in a couple of instances that use of the && operator needs extra parenthasis around pointer assignment.
(This post was last modified: 05-26-2014 09:00 PM by Zervox.)
05-26-2014 09:00 PM
Find all posts by this user Quote this message in a reply
andrake Offline
Member

Post: #9
RE: double click on the same button(touschscreen)
>>(t.db() && area=guielement) <-- Was the assignment intentional?
Nope, just misspell
of course i mean
(t.db() && area==guielement)

sorry for this

[quote='Esenthel' pid='47346' dateline='1401081162']
Quote:The issue you have is that 'db' stands for having a second click in a short amount of time, but it doesn't include anything related to mouse movement. So you need additional logic in your code.

this mean that it include something related to both tap locations, but not to mouse cursor location?

tap on touchscreen related to position on the screen ,but mouse double click related only to mouse button?
ok
anyway by mouse i can't emulate two taps permanently and my app should works on android.
(This post was last modified: 05-27-2014 01:27 PM by andrake.)
05-27-2014 01:17 PM
Find all posts by this user Quote this message in a reply
para Offline
Member

Post: #10
RE: double click on the same button(touschscreen)
Because && has higher precedence than =, and lower then & or * (de/reference).

All standard abiding compilers evaluate expressions the same way, for (a && b && c ...) the compiler always stops evaluating at the first false statement it encounters from left to right. So it's safe to write code like if( p && p->func() ) ...


Anyway, maybe something like this would work? (assuming you can't have a double click before getting a single click at least a frame earlier)
Code:
if( !doubleclick )
{
        if( click )
        {
                // mark clicked object
        }
}
else
{
        if( marked object == current object == target_button )
        {
                 // do double click something here
        }
}
05-27-2014 02:08 PM
Visit this user's website Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #11
RE: double click on the same button(touschscreen)
(05-27-2014 02:08 PM)para Wrote:  Because && has higher precedence than =, and lower then & or * (de/reference).

All standard abiding compilers evaluate expressions the same way, for (a && b && c ...) the compiler always stops evaluating at the first false statement it encounters from left to right. So it's safe to write code like if( p && p->func() ) ...

Yeah mind that this is only for the default operators, an overloaded would not do this. Which makes sense, I guess i've been overloaded with information about different languages pfft So the left-right evaluation order is for these
Code:
int a = (aa=1, aa++);

if(a == 5 && myAFunc())

(a==5) ? (a++) : (a+=2);

if((a || aa) > 0)

But mind me saying also that for evaluation order when it comes to functions is not specified and will not do it same order all the time. Also a code such as this
Code:
int a = 5;
cout << a << a++ << a++ << ++a;
would not always show 5, 6, 7, 8.

But yeah as Para noted something alike

Code:
if(MT.touch(i)->guiObj == &myObjectGUI)
if(MT.db(i) || MT.bp(i)??? ) // <-- Not sure which would work best.
05-27-2014 04:31 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #12
RE: double click on the same button(touschscreen)
(05-27-2014 04:31 PM)TBJokers Wrote:  But mind me saying also that for evaluation order when it comes to functions is not specified and will not do it same order all the time. Also a code such as this
Code:
int a = 5;
cout << a << a++ << a++ << ++a;
would not always show 5, 6, 7, 8.

Would that EVER show 5, 6, 7, 8? These operators have a certain precedence as well as defined by the standard. It can be confusing to us, but there are very, very few situations in which the behavior is undefined. The C++ standards are written like a legal document, and as such, leave very little out.
It's a very rare thing that 2 compilers have different results for the same code.
05-27-2014 05:41 PM
Find all posts by this user Quote this message in a reply
Post Reply