Community

SCI Programming => SCI Syntax Help => Topic started by: gumby on December 27, 2012, 06:09:34 PM

Title: Detect click on a view
Post by: gumby on December 27, 2012, 06:09:34 PM
Okay, so I know I can use the nsTop, nsBottom, nsLeft, and nsRight to detect if I've clicked anywhere on the full area of a view.

What I would like to know is if I've clicked on the visible portions of the current cel within a view.  I have a view that is fairly large, but the viewable pixels only occupy a small portion of the view within a cel.

Any suggestions here?
Title: Re: Detect click on a view
Post by: Cloudee1 on December 27, 2012, 06:28:48 PM
Is the view static or animated... if it is static, might I suggest using addToPic to place it. Then you can always check for clicks on that priority color in combination of a bounding area.

Code: [Select]
(if(== $0100 OnControl(ocPRIORITY (send pEvent:x) (send pEvent:y)))
   (if((> (send pEvent:x) 273) and
       (< (send pEvent:x) 293) and
       (> (send pEvent:y) 90) and
       (< (send pEvent:y) 95))
  (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))
   // .... do some stuff
   )
   (else
   (send pEvent:type(evMOUSEBUTTON) claimed(FALSE))
   )
)

I am assuming though that since there is more than one cel, we aren't going to get that lucky. I can't come up with any good way of checking against clicking on a portion of a view. I hate to ask, but are you sure you need one large view? No way of breaking it down into more manageable sections?

Maybe though, if you know where the clickable area's are during any given cel, it might be possible to check against a bounding area in addition to checking on the views cel.

Code: [Select]
(if((> (send pEvent:x) 273) and
    (< (send pEvent:x) 293) and
    (> (send pEvent:y) 90) and
    (< (send pEvent:y) 95))
  (if(== (someView:cel) 5)
  (send pEvent:type(evMOUSEBUTTON) claimed(TRUE))
   // .... do some stuff
   )
   (else
   (send pEvent:type(evMOUSEBUTTON) claimed(FALSE))
   )
)

Probably easier to do this next part but I'm just making it up as I go, so I may have some syntax a tad off and definately a bracket or two, but it should be enough to give you the idea. So instead of figuring out the bounding box based off of the room, maybe try to base it off the bounds of the view...

Code: [Select]
(if((> (send pEvent:x) (someView:nsLeft) and
    (< (send pEvent:x) (someView:nsRight)) and
    (> (send pEvent:y) (someView:nsTop)) and
    (< (send pEvent:y) (someView:nsBottom)))
  (switch(cel)
    (case 0
      (if((> (send pEvent:x) (+ (someView:nsLeft) someValueFromLeft)) and
          (< (send pEvent:x) (- (someView:nsRight) someValueFromLeft)) and
          (> (send pEvent:y)  (+ (someView:nsTop) someValueFromTop)) and
          (< (send pEvent:y) (- (someView:nsBottom) someValueFromBottom))
     ... do something
     )
     (if((> (send pEvent:x) (+ (someView:nsLeft) someOtherValueFromLeft)) and
          (< (send pEvent:x) (- (someView:nsRight) someOtherValueFromLeft)) and
          (> (send pEvent:y)  (+ (someView:nsTop) someOtherValueFromTop)) and
          (< (send pEvent:y) (- (someView:nsBottom) someOtherValueFromBottom))
     ... do something
     )
   ) // end case
  ) // end switch
)
In the end this approach might make for a whole bunch of code, but in theory it should work. Just scroll through your cels, figure out the hotspots and code them into the switch...
Title: Re: Detect click on a view
Post by: gumby on December 27, 2012, 06:56:41 PM
Yeah, it's a big animated view.  I probably should have broken it into three different views, and I might if I cannot get this to work.

I've already implemented similar logic to what you've posted with regard to clicking on a particular control color (though I used priority colors, but it amounts to basically the same code).

I'm thinking that I need to check the underlying control/priority color of the scene with the color of the view to determine if the mouse is clicking on a part of the view or 'through' the view (clicking on the transparent color and in effect, clicking on some part of the scene rather than the view).  Not sure if this is possible or not, will report back.
Title: Re: Detect click on a view
Post by: Cloudee1 on December 27, 2012, 07:01:53 PM
You may want to check out my last edit on the other post.

If I remember correctly, it will not work. For instance when trying to determine if you were clicking on an actor, I had tried to use the priority color of the actor and checked against that. It didn't work. Even though the actor and his priority were there, I don't think it was "drawn" to the pic, so it didn't really see it.
Title: Re: Detect click on a view
Post by: gumby on December 27, 2012, 07:45:53 PM
Yeah, that should work, using a switch on the cel.  Quite a bit of code, for sure.  I'm going to see if I can work our another method, but I may not have a choice.  Thanks for confirming that I haven't missed anything obvious.