Label-clicks? [SOLVED]

Started by monkey0506, Sun 12/12/2004 23:12:53

Previous topic - Next topic

monkey0506

Is it possible to test if the user clicks on a label? I know about the interface_click function, I've read the manual, and I even searched the forums. So please, don't flame me. I tried testing for label-clicks in interface_click, but it didn't work. Let me know if you need to see the code. (Which I have already deleted, otherwise I'd post it...)

strazer

I don't think that's directly possible at the moment.

If the GUI has a fixed position, here is a workaround that could work:

Code: ags

// main global script

function on_event(int event, int data) {
  if (event == GUI_MDOWN) { // if clicked on A GUI (any mouse button, combine with IsButtonDown to allow/disallow buttons)
    if (data == YOURGUINAMEHERE) { // if clicked on THIS gui
      if ( ((mouse.x/2) >= (XCOORDINATEOFGUI+XCOORDINATEOFLABEL)) && ((mouse.x/2) <= (XCOORDINATEOFGUI+XCOORDINATEOFLABEL+WIDTHOFLABEL)) && ((mouse.y/2) >= (YCOORDINATEOFGUI+YCOORDINATEOFLABEL)) && ((mouse.y/2) <= (YCOORDINATEOFGUI+YCOORDINATEOFLABEL+HEIGHTOFLABEL)) ) { // mouse is over label
        // do stuff
      }
    }
  }
}


I probably screwed some braces there, but you'll see.
Replace the uppercase stuff with the appropriate values. I like to use + to make the code easier to fix if one of the values changes (e.g. you move label around).

strazer

It seems mouse coordinates are always in the 320-res system, so you don't need to divide them by 2.
Replace (mouse.x/2) with just mouse.x and (mouse.y/2) with mouse.y
Sorry for the confusion.

monkey0506

Thanks!  ;D I'm having to work out some errors in my script, but yours works!

Proskrito


monkey0506

#5
I would, but the text on GUI buttons is centered. I need it left-aligned...Ã,  :P

EDIT: FYI, I can't just re-align the buttons, because the label is at X-coordinate 1...

Proskrito

#6
mm in that case you could also put two buttons together, like:
b.1  b.2
 _________________
|text|            |
|____|____________|

and, in interface_click, instead i.e
if (button==1)
you would write
if (button==1 || button==2)

EDIT: Or maybe better:  you could make a transparent button over the label, that way you can change the label text, color... and keep registering clicks with the button.
I think its quicker and cleaner that manually check for clicks in the label.

monkey0506

I actually tried that first, but I couldn't get it to work... Probably a simple error, but it doesn't matter. I'll change it if it becomes a problem. Like I've said before, it doesn't matter to me if my scripts are "pretty", as long as they work...

SMF spam blocked by CleanTalk