• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML [Solved] Global Mouse Left overrides Mouse Left?

X

XirmiX

Guest
I've heard from a previous thread that Global Mouse Left would be the way to go to make it so that, say, a text box I've created gets deselected. However, the moment I do this, even when I click on the text box itself, it stops from being . It seems as if Global Mouse Left overrides Mouse Left, despite the latter being first in the event list. So, question is, how do I make it so that when I click anywhere BUT the textbox, the textbox gets deselected? Mouse cursor isn't an object, so you can't do a "place meeting".

I've had others suggest me having an object that constantly follows the mouse cursor, but honestly that seems like a dubiously bad idea. I had previously followed a text box tutorial and had help from the other topic about this and some other issues before, however because it got to a point where there's no redemption to that code, I've decided to abandon ship and re-do the code, especially since I was using and keeping keyboard_strings in places I didn't want to and vice versa.

Here's my basic code currently for the selection itself (yes, I have other code for writing in the actual text box and such):
Create event
Code:
self.selected = false;
self.max_char = 30;
self.char_written = 0;
txt = "";
Left Mouse Click
Code:
self.selected = true;
Global Left Mouse Click
Code:
self.selected = false;

Without the global mouse event code, I start typing and nothing happens, and then click on the box and typing does happen.

With the global mouse event code, I start typing and nothing happens, and then click on the box and still nothing happens.
 
Mouse cursor isn't an object, so you can't do a "place meeting".
But even without the mouse being an object, you can still check the mouse_x and mouse_y values. So you could just use the Global Left Mouse Click and check the mouse_x and mouse_y coordinates to see if they are within the boundary of your textbox, and then if it is set selected = true, otherwise set selected = false.
 
X

XirmiX

Guest
But even without the mouse being an object, you can still check the mouse_x and mouse_y values. So you could just use the Global Left Mouse Click and check the mouse_x and mouse_y coordinates to see if they are within the boundary of your textbox, and then if it is set selected = true, otherwise set selected = false.
That's what I thought. Here's what I don't know; how do I define the boundaries of the textbox object's sprite?
 
All depends upon how you have set up the origin of the sprite. Let's say that it is origin Top-Left, then you will already know the left and top side coordinates (x and y), so just need to calculate the right and bottom sides and those would be based on the width and height of the sprite.

You could then use point_in_rectangle something like this:
Code:
var leftX = x;
var topY = y;
var rightX = x + sprite_width();
var bottomY = y + sprite_height();

if point_in_rectangle(mouse_x, mouse_y, leftX, topY, rightX, bottomY) {
  self.selected = true;
} else {
  self.selected = false;
}
This is completely untested, but I'm just going from the manual for the point_in_rectangle command. I've assumed that the object that has this Global Left Mouse Click event is the textbox, and that object has the sprite assigned to it.
 
X

XirmiX

Guest
All depends upon how you have set up the origin of the sprite. Let's say that it is origin Top-Left, then you will already know the left and top side coordinates (x and y), so just need to calculate the right and bottom sides and those would be based on the width and height of the sprite.

You could then use point_in_rectangle something like this:
Code:
var leftX = x;
var topY = y;
var rightX = x + sprite_width();
var bottomY = y + sprite_height();

if point_in_rectangle(mouse_x, mouse_y, leftX, topY, rightX, bottomY) {
  self.selected = true;
} else {
  self.selected = false;
}
This is completely untested, but I'm just going from the manual for the point_in_rectangle command. I've assumed that the object that has this Global Left Mouse Click event is the textbox, and that object has the sprite assigned to it.
I thought it would get this complicated, but I was hoping that there would be a simpler way to do this. Albeit, this is still quite simple, but still, for a simple mouse-click, this seems a bit ridiculous. Shame. Well, it works at least, so I guess this is solved.
 
Top