DoHitTest - Multiple Mouse Clicks and feedback

David McFarlane mcfarla9 at msu.edu
Thu May 20 20:43:14 UTC 2010


Stock reminder:  1) I do not work for PST.  2) PST's trained staff 
takes any and all questions at 
http://support.pstnet.com/e%2Dprime/support/login.asp , and they 
strive to respond to all requests in 24-48 hours (although latest 
reports indicate more like 10 days) -- this is pretty much their 
substitute for proper documentation, so make full use of it.  3) If 
you do get an answer from PST Web Support, please extend the courtesy 
of posting their reply back here for the sake of others.

That said, here is my take...

>i'm new to e-prime, but not new to programming.

Good to have an actual programmer on board, though as a real 
programmer you will will E-Prime deficient in many respects.  But 
forging ahead...

>i've got a slight problem, i've read the following post about multiple
>mouse clicks
>however i've become a bit unsure about the whole "slide states"
>scenario. for my experiment i'm having the following screen:
>
>on this screen i want to be able to detect 4 mouse clicks in total,
>each mouse click will be assigned to any box, but not the same box
>twice. i was wondering if there is an easily programmable way to
>change the colour of each selected box once it has been clicked, i've
>currently only been able to do this with only one box.

I just programmed something like this a week or so ago.  In short, 
you can make use of the the .Draw method of any object, in this case 
either the entire Slide object or at a finer grain each individual 
SlideText or SlideImage sub-object (see the appropriate topics in the 
online E-Basic Help, which comprises the real technical 
documentation).  In our case for each selection we wanted to restore 
the previous selection to its previous state, and then color the 
border or background of the new selection.  (That means keeping track 
of a little more history than in your case, which I could have done 
with variable but instead did by restoring color properties 
immediately after each .Draw so that the next .Draw would 
automatically restore the original color.)  I decided to wrap this 
work into a couple of Subs for more general use.  So I now offer here 
my two Subs, plus a little example inline code using these.  I 
provide these with no offer of any further support, and it is up to 
you to extract what you may from these:

'/==========================\
Function  SlideState_TextAltBorderColor( slState as SlideState, _
         slTextName as String, altColor as Long ) as SlideText
' Draws alternate color on border of named SlideText object of the
' SlideState, and then restores the .BorderColor property for the next
' .Draw of the SlideText.
' Returns named SlideText object.
         Dim  color0 as Long
         Dim  slText as SlideText
         Set slText = CSlideText( slState.Objects( slTextName ) )
         color0 = slText.BorderColor  ' preserve color setting
         ' set & sraw alternat color...
         slText.BorderColor = altColor
         slText.Draw
         ' restore original color setting for next .Draw:
         slText.BorderColor = color0
         Set SlideState_TextAltBorderColor = slText  ' return value
End Function  ' SlideState_TextAltBorderColor()

Sub  SlideText_AltBackColor( slText as SlideText, altColor as Long )
' Draws alternate color to background of specified SlideText object,
' and then restores the .BackColor property for the next .Draw of the
' SlideText.
         Dim  color0 as Long
         color0 = slText.BackColor  ' preserve color setting
         ' set & sraw alternat color...
         slText.BackColor = altColor
         slText.Draw
         ' restore original color setting for next .Draw:
         slText.BackColor = color0
End Sub  ' SlideText_AltBackColor()

Some inline code fragments...
' RatingSlide must use a SlideText object for each rating item,
' and the object name must take the form of ScaleStub#LevelStub#,
' e.g., "Scale1L1"...
Const  ScaleStub as String = "Scale"  ' precedes scale #
Const  LevelStub as String = "L"  ' precedes level #
' Alternate colors for rating items...
Const  AltBorderColorStr as String = "red"
Const  AltBackColorStr as String = "red"
' Working variables...
Dim  scaleN as Integer, levelSelect as Integer
Dim  slideTextName as String
Dim  RatingSlideText as SlideText
' Some variables for convenience & clarity...
Dim  altBorderColor as Long, altBackColor as Long
' Assign "constant" variables for notational convenience below...
altBorderColor = CColor( AltBorderColorStr )
altBackColor = CColor( AltBackColorStr )
Set RatingSlideState = RatingSlide.States(RatingSlide.ActiveState)
' Initialize scales & display...
slideTextName = CStr(ScaleStub & scaleN & LevelStub & levelSelect)
Set RatingSlideText = SlideState_TextAltBorderColor( RatingSlideState, _
     slideTextName, altBorderColor )
' [... other stuff happens, then later...]
' Draw alternate color & restore color property for next .Draw:
SlideText_AltBackColor RatingSlideText, altBackColor
' [... even more stuff happens, and later still...]
' Restore color of previously selected rating item, alter color of
' newly selected rating item...
RatingSlideText.Draw  ' restore previous color
slideTextName = CStr(ScaleStub & scaleN & LevelStub & levelSelect)
Set RatingSlideText = SlideState_TextAltBorderColor( RatingSlideState, _
     slideTextName, altBorderColor )
' [... clean up before we leave...]
' Close out object variables:
Set RatingSlideState = Nothing
Set RatingSlideText = Nothing
'\==========================/


>  in the boxes i
>would also like the numbers 1-4 displayed according to which one was
>clicked 1st, 2nd, 3rd etc. i am more than happy with the underlying
>code about setting up the arrays and checking those as i have had
>years of experience in that, however it is the detecting and
>displaying i'm unsure about.

I will have to leave you to work that one out.


>another question is am i able to do this all from the e-prime user
>interface using the "slides" and "inline" functions or would i have to
>do it entirely from the script editor?

Hmm, I don't know what you mean by the distintion between inline code 
and a "script editor".


>here is my current code if this helps:

I cannot speak for others, but generally when I see more than about a 
dozen lines of code in someone's question then I just tune 
out.  (Yes, I did just post more than a dozen lines of code myself, 
but I provided that as an answer, not as a question :) .)  All the 
double-spacing does not help matters, nor does the lack of indentation.

Regards,
-- David McFarlane, Professional Faultfinder

-- 
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com.
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.



More information about the Eprime mailing list