Change how button text is highlighted on click.

Started by Lt. Smash, Mon 11/06/2007 13:03:47

Previous topic - Next topic

Lt. Smash

I wanted to ask how to change the way the text is displayed when I click on a GUI button.
Now when I click on a GUI button the text moves 1px down and 1px to the right. But I wanted it to highlight in yellow and not to move.

Anyone who knows how I can change it?

Ashen

AFAIK you can't, not directly at least. You need to include the text as part of the button graphic, then you can use the 'Mouseover' and 'Pushed' graphics for highlight effects.
I know what you're thinking ... Don't think that.

Akatosh

Hm... it *should* be possible to script your way to this, but it would mean a BIG amount of work, so you're probably better off with Ashen's suggestion.

GarageGothic

#3
It seems that it's offset by exactly one pixel, and due to the 320x200 grid used by AGS there's no way to counteract this in hi-res. If your game is in 320x200, you could do something like this in on_event:

Code: ags
if (event == eEventGUIMouseDown) {
    GUIControl *mycontrol = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
		Button *mybutton;
		if (mycontrol != null) mybutton = mycontrol.AsButton;
		if (mybutton != null) {
			if (mybutton.Text != "") {
				mybutton.X = mybutton.X - 1;
				mybutton.Y = mybutton.Y - 1;
				}
			}
		}


Of course you must then also store the *mybutton pointer globally and add some code to repeatedly_execute to reset it's position once it's either been clicked or the player has moved the cursor away from the button and let go of the mouse button.

Alternately, you could script your own system using labels instead of buttons (one way of identifying the labels that should work as buttons would be to use different fonts and check Label.Font), but labels can't have background graphics so it would be text only.

Ashen

But wouldn't that move the entire Button one pixel (/screen unit) up and left? OK, that'd mean the text was in the same place but IMO would look weirder than just letting the text move. Also surely you'll need a matching eEventGUIMouseUp condition to move the Button back down, so it doesn't just drift off the GUI after a couple of presses?

As for using Labels, you could use the Label.Clickable property to stop them registering clicks, and place it over a Button, allowing for graphics as well as Text. However, that method seems like it'd require a lot of messing around with custom fonts (to make the hightlighted version properly match the 'normal' version), as well as doubling the number of Controls needed. (If not tripling, if you wanted one Label for the normal text to be visible inside the hightlight.)

So, text as part of the graphic still seems the easiest, most effective method to me, even if it does require a lot more sprites. Unless there's an undocumented option to disable the text movement - I've noticed that the hard-corded GUIs (e.g. Quit and Save/Load ones) don't have it.
I know what you're thinking ... Don't think that.

GarageGothic

Quote from: Ashen on Mon 11/06/2007 17:42:26But wouldn't that move the entire Button one pixel (/screen unit) up and left?

Ah yes, my bad. My game doesn't use any graphics for buttons so it looked fine when I tested it.

QuoteAlso surely you'll need a matching eEventGUIMouseUp condition to move the Button back down, so it doesn't just drift off the GUI after a couple of presses?

Well, as I said: "Of course you must then also store the *mybutton pointer globally and add some code to repeatedly_execute to reset it's position once it's either been clicked or the player has moved the cursor away from the button and let go of the mouse button."
I think that would be a better solution than just eEventGUIMouseUp, as the player could move the cursor over one button, hold the mouse button, then move it over another button with the mouse button still held.

Ashen

Quote
and add some code to repeatedly_execute to reset it's position once it's either been clicked or the player has moved the cursor away from the button and let go of the mouse button.

Sorry, missed that bit somehow, but on_event still makes more sense than rep_ex to me. If you reset mybutton in the MouseUp event then yes, releasing the mouse over a different object is an issue, but because you mentioned delcaring mybutton globally (which I did read, even if I missed the rest of the sentence) I was thinking more like:

Code: ags

 if (event == eEventGUIMouseDown) {
    // mybutton/mycontrol declared at top of script
    mycontrol = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
    if (mycontrol != null) mybutton = mycontrol.AsButton;
    if (mybutton != null && mybutton.Text != "") {
      mybutton.X = mybutton.X - 1;
      mybutton.Y = mybutton.Y - 1;
    }
  }
  if (event == eEventGUIMouseUp) {
    if (mybutton!=null && mybutton.Text != "") {
      mybutton.X = mybutton.X + 1;
      mybutton.Y = mybutton.Y + 1;
      mybutton = null;
    }
  }


Which seems to work perfectly (not much testing), but like I said looks weird with graphical Buttons.

Probably slightly pointless, given it's limitations (it doesn't work properly in hi-res for example), but there it is anyway.
I know what you're thinking ... Don't think that.

GarageGothic

It surely doesn't hurt to use eEventGUIMouseUp, but as there are situations that need you to reset the button position without the mouse button being released (such as moving the cursor away from the button while mouse key is still pressed), it does seem a bit redundant to have multiple instances of the reset code.

SMF spam blocked by CleanTalk