Help with EditBox

For questions about using Classic.

Post » Thu Aug 05, 2010 11:01 am

I'm making a simple money counting program. Something like..

1c x 0
5c x 0
10c x 0
.
.
100$ x 0
sum = 0

Where user would click on 0 and enter the number of coins or bills. I'm using EditBox with initial value 0, but I would need bigger font size. I can't find it in the EditBox only in the Text object.
ImageImage
B
25
S
6
G
8
Posts: 773
Reputation: 6,643

Post » Thu Aug 05, 2010 9:28 pm

I have been vexed by that as well. I don't think it can be changed. Because it's a windows API widget, it's not quite as integrated into Construct as most other objects. For instance, it can't be zoomed.

Anyway, you might be able to make an acceptable alternative. linkman2004 made an example of a custom editbox a while back. It uses a hidden editbox to do the grunt work, while a Text and Box object make up the visible display. Something like that can be adapted to work with multiple fields.

Check it out here:

[url:cffnojv6]http://www.scirra.com/forum/viewtopic.php?f=16&t=5686&p=45360#p45360[/url:cffnojv6]

Another alternative that I just thought of, would be trying lucid's spritefont plugin. There is a recent tutorial that mentions using it as an editbox, here:

[url:cffnojv6]http://www.scirra.com/forum/viewtopic.php?f=8&t=6867[/url:cffnojv6]

The plugin is linked to in that thread as well.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Fri Aug 06, 2010 9:49 pm

If you only need to input numbers you can accomplish it with just the Mouse&Keyboard and Text objects and two events:
[code:1u3t3ixj]+ System: For "" from 0 to 9
+ MouseKeyboard: On key LoopIndex + 25 pressed
+ System: Trigger once
-> Text: Set text to int(.Text & LoopIndex)

+ MouseKeyboard: On key Backspace pressed
-> Text: Set text to int(left(.Text, len(.Text)-1))
[/code:1u3t3ixj]

Here is a more advanced example that works with multiple instances of the text object and shows a blinking cursor on the selected instance:
[url:1u3t3ixj]http://dl.dropbox.com/u/5426011/examples/NumberInput.cap[/url:1u3t3ixj]
B
79
S
24
G
53
Posts: 4,728
Reputation: 40,219

Post » Mon Aug 23, 2010 7:11 pm

Thank you Silent Cacophony and R0J0hound for your help. I've used bit of both. Here's what I've got so far
http://dl.dropbox.com/u/10457408/Constr ... ncovka.cap
http://dl.dropbox.com/u/10457408/Constr ... ncovka.exe
It works but I still have some problems

How can I make objects use variables, so I can make use of FOR
object(x)
object(x)
.etc
FOR "" 1 to 12
object(LoopIndex)
Look into the .cap, is there a way how to make it better optimized? I have On Click On Object for every 12 objects. Can I use just one event for all?

When I input, say 25 into a box and than I click on that box again, the bleeping cursor in the EditBox stays at the beginning and adds numbers before 25 and not after.

How can I add that bleeping cursor into a box so it will not look that empty

Sorry for all those questions. I've wanted to use numbers for object names like 100 instead of onehundred but I got errors. And finally when I save the .cap on my home PC I can't open it on my work laptop even it's same version. I think, that I only have one plugin installed on home comp but it's not included in the .cap

note - currency is in CZK
ImageImage
B
25
S
6
G
8
Posts: 773
Reputation: 6,643

Post » Mon Aug 23, 2010 7:48 pm

For the cursor moving to the front of the number it can be corrected with this sequence of actions:
-> EditBox: Focus on
-> EditBox: Select all
-> EditBox: Cut
-> EditBox: Paste

It will put the cursor at the end, kind of hacky but it works.
B
79
S
24
G
53
Posts: 4,728
Reputation: 40,219

Post » Tue Aug 24, 2010 9:58 pm

There are a few ways to set the cursor to the end of the text in an EditBox. Here are two that I've used:

[code:1ck842a0]EditBox.SelectAll()
EditBox.ClearSelection()

or:

EditBox.SetSelection(len(EditBox.Text), len(EditBox.Text))[/code:1ck842a0]

I greatly prefer the latter when the text is large, as it's faster, and prevents the selection flashing that the former causes. It just sets the start and end of the selection to the end of the text, which doesn't really select anything.

As for making the .cap above with less events and separate objects, you can use a single Text object for all of those separate ones for the denominations, with private variables set differently for each instance to make them distinct. This can be done at runtime with a for loop that creates each instance at a different Y location, then sets an ID or Index private variable for each immediately after, using LoopIndex or something similar. Or, you can clone them in the layout editor, and set each manually there.

I'd probably have a private variable for ID, Denomination, and Number. ID would be 1-12, Denomination could be set at runtime with {1,2,5,10,20,50,100,200,500,1000,2000,5000} @ LoopIndex, and Number would store the number that has been input for that denomination.

Also, this way you could do a for each to total the amount by adding Denomination * Number to another variable.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Wed Aug 25, 2010 12:43 am

I was just thinking about this thing again, and wondered about how to do a cursor. I found that it is feasible, though it'd be a bit more complicated than I'd like to make for a multi-line editbox.

It's pretty simple for a single-line box if you limit the text length so that you don't run out of the Text display area. Here's a quick example:

http://dl.dropbox.com/u/5868916/EditBoxCursor.cap

The cursor is just a sprite with the hotspot set to lower-left, and sine-opacity behavior.

This doesn't handle shift-selecting very well, but hey... ;) I'm sure that could be done, too.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Wed Aug 25, 2010 9:10 am

Thanks again. I'm at work now, but I'll try it later. I've tried R0J0hound's cut/paste trick, but as you say I could see flashing (maybe I was doing it wrong), so I can't wait to try the other method
ImageImage
B
25
S
6
G
8
Posts: 773
Reputation: 6,643

Post » Thu Aug 26, 2010 2:05 pm

[code:1ktkrpco]EditBox.SetSelection(len(EditBox.Text), len(EditBox.Text))[/code:1ktkrpco]
This works perfectly and your EditBoxCursor too. I've had some problems with setting private variables and than calling them, but I think it's ok now.
Now only what I have to do is put it all together. I'll try post final version next week
ImageImage
B
25
S
6
G
8
Posts: 773
Reputation: 6,643


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests