123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|526|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> Mouse select text

Sat, 22 Oct 2016, 17:36
Afr0
I'm writing a texbox control. Do you guys have any idea what I need to do to make it possible to select text with the mouse (eventually iOS, but that's for later)?
I know that the cursor should go where the mous clicks within the control if that area has text, but I'm kinda lost on where to go from there.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 22 Oct 2016, 19:00
Jayenkai
If you can create "actual text" in your GUI, rather than rendered ingame text, then do that. Different os's handle things very differently, and it'll be hell to fight against it.
In Windows, click and drag selects letters at a time.
Double-click and drag selects words at a time.
Triple-click and drag selects sentences at a time.. usually... sometimes!
Trying to replicate all of that, and account for other OS's, too, would be a freakin' nightmare.

-=-=-
''Load, Next List!''
Sun, 23 Oct 2016, 07:54
Afr0
Well, I was looking at a way that I could get text from the keyboard through the Windows API, which would simplify my code greatly (right now it's right around 1000 lines), but then I'd have to hook into all the different APIs for all the different platforms. :\
I think I might just skip mouse interaction for now, except for allowing clicking to place the cursor.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 29 Oct 2016, 06:52
Afr0
UGH

I had to delete my text insertion code. Initially I had the idea of using a position vector for the cursor (updating it by one every time a character was removed or added, or the cursor was moved).
This turned out to be messy and incredibly buggy.
Probably the buggiest code I've produced in years.
If anyone has a better idea, please tell me!
Jay, perhaps perchance you could knock out an example in Blitz for me?
I'm fresh out of ideas

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 29 Oct 2016, 07:48
Jayenkai
I'm not sure a Jay-Code Blitz based example would be all that helpful. It depends on a LOT of variables.
Are you using a TTF or a Bitmap font?
Are you using Monospaced font, or a proportional one?
Is the text then wrapped into the area by the system or by you?

Best I can come up with is to work out an approximate X/Y "center" for each letter, but that depends on a whole lot of those variables before it'll work properly.


I've coded this.. It's not perfect, but if it's workable then it'll probably be a decent enough starting point for you.
Blitz2D/3D/Plus


-=-=-
''Load, Next List!''
Sat, 29 Oct 2016, 09:05
Afr0
I'm using a TTF. It's... uhm, I think it's monospaced. How do I know?
I'm wrapping the text myself.
It looks like your code mainly deals with when the text is selected by a mouse?
I'll try to understand it, it's been a while since I've used Blitz. Thanks!

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 29 Oct 2016, 09:09
Dabz
lol... I've just give that a spin... Started tapping the keyboard... Nowt happening... Looked at the code... Thinking, it should work... Then I realised...

I was tippy tapping on my 6128!

Dabz

-=-=-
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 8Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit
Sat, 29 Oct 2016, 10:14
Jayenkai
I'm not sure if that's a terrible thing, or a wonderful thing..

...

Yeah, wonderful! Keep tappy-tap-tapping on your CPC!

-=-=-
''Load, Next List!''
Sat, 29 Oct 2016, 10:23
Jayenkai
Afr0 I think it's monospaced. How do I know?


Use your Willy!!

If W, i and l all end up being the exact same width between them, then it's monospaced.
If, instead, the W takes up more space, whereas the is and ls are all thin, then that's a proportional font.

-=-=-
''Load, Next List!''
Sat, 29 Oct 2016, 10:44
Afr0
Think it might be monospaced...



-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 29 Oct 2016, 10:48
Jayenkai
No, that's definitely proportional. "ill" can easily fit into the width of the W!

-=-=-
''Load, Next List!''
Sat, 10 Dec 2016, 09:53
Afr0
So, a little over a month onwards, I'm nearly done with what Jay said I shouldn't do (mainly because I didn't have a choice, as Monogame only supports listening for text characters (not special or numeric ones).
Initially I didn't even know it supported that, and I was writing the code for handling *each* *individual* *key* and, in the case of non-english keyboards, determining its value based on language.
There was no way in hell I was going to hook into the native API, as it would have neccessitated doing so for *every* *single* *OS* that I wanted to support.
At this point I'm getting somewhat tired of dealing with text input, but ironically what I thought was going to be the easiest bit turns out to be the (most?) difficult;

How do in the name of all that's holy do I figure out where to place the cursor when the mouse clicked on the control?



See the comment above for frustration.

If you want context, here is the entire 1047-line monstrosity:



|edit| Oh yeah, and the mouse position is already picked (I.E transformed by the view matrix). |edit|

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 10 Dec 2016, 10:26
Jayenkai
Fook,what a mess!!!!

But as long as it works... fast.... that's the main thing.

-=-=-
''Load, Next List!''