|
GUI-Object "d_edit_proc()" |
Christian Geisler
Member #6,289
October 2005
|
Dear Allegro-Programmers, I have a serious problem with the GUI-Objektd_edit_proc( ). Could you kindly give me your advice and/or opinion concerning this problem. The GUI-function d_edit_proc( ) allows letters and/or miscellaneous other characters. For the input of double-values this, however, does not make any sense. My user-defined function should suppress certain characters during the input (for example: letters the tilde-char etc.). During the input, the function should replace a comma by a KEY_STOP. Although I have studied the allegro-documentation for several times as well as various examples with concern to the GUI-Programming of Shawn Hargreaves and Revin Guillen (GUI-CLINIC), I am not capable of solving this problem. Please let me know whether this change of the GUI-function d_edit_proc ( ) is possible and meaningsful or if there is any easy example of a customary dialogue-procedure using the d_edit_proc ( ) by parsing the input string. If there is no easy solution for the problem and my problem is not as trivial as it may seem at first glance, I can provide you with my code-fragments by giving more details of the problem. Many thanks for your help. Christian |
Steve Terry
Member #1,989
March 2002
|
I'm not sure I entirely understand what you are saying. Are you wanting an input box that only accepts numbers as a double value? If so then you can override the d_edit_proc to ignore all character input, and if the '.' character is encountered accept only one instance, all others ignored. From there the string value can be converted to a double value via atof() or atol(). ___________________________________ |
Christian Geisler
Member #6,289
October 2005
|
First a warning: English is not my mother tongue. For the question I had a native next to me. Now he is gone. Yes exatly this is the problem. I don't know wether "overwrite" is what I'm trying to do. The edit-funktion of the parent-object "d_edit_proc()" like toggling between Insert- and overwerite modus, the home and the end-key etc. should work further on. The GUI-player provides the edit-dialog (here: for double-values) and should call my custom function, whenever a key is pressed. The following paraphrase of the Allegro Doc is concerning the problem: Quote:
If the object deals with the keypress it should return D_USED_CHAR, otherwise First the code for the dialog: DIALOG the_dialog[] = { /* (proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ {indouble, 264, 248, 184, 16, 0, 0, 0, 0, sizeof(the_string)-1, 0, (void*)the_string, NULL, NULL }, ... }; Further the code fragment for the keys I want to 'block'.
When I'trying to replace the 'COMMA' by a full stop I get a little confused. But now I would like to hear your feedback for the basic code. Thanks for your help. |
Steve Terry
Member #1,989
March 2002
|
The int c parameter will contain the full scancode/ascii code of the key being pressed so you should not have to use the key array. By FULL_STOP I think you mean the '.' key? I think you have the right idea anyway, be sure to call d_edit_proc at the end of your custom function for default handling of other methods. [edit] ___________________________________ |
Christian Geisler
Member #6,289
October 2005
|
Hello Steve, Quote: (...)be sure to call d_edit_proc at the end of your custom function for default handling of other methods. (...) That was an impotant hint. Thanks! I try this. You mean parsing and manipulating the string is the right idea. There are other manipulations I have to do, like accepting one '-' character only at the beginning of the string, only one '.' character etc. For the moment I write some little aplication for mechanics. There is an other question left. The dialog element "d->dp" points to the beginning of the string. To access the third character of the string "d->dp[3]" dosn't work. Could you kindly give me a hint to that? Many thanks ! |
miran
Member #2,407
June 2002
|
Quote: The dialog element "d->dp" points to the beginning of the string. To access the third character of the string "d->dp[3]" dosn't work. Could you kindly give me a hint to that? d->dp[2] or maybe (char *)(d->dp)[2] or something similar... -- |
Christian Geisler
Member #6,289
October 2005
|
Hello miran, Thanks for your help. I had a look on your skinnable GUI-System - great Before I'm capable of changing the behavior of the Allegro GUI, I have to work with the GUI basics. Germans would say: "Langsam ernährt sich das Eichhörnchen !" |
Steve Terry
Member #1,989
March 2002
|
[raises hand] ___________________________________ |
Tobias Dammers
Member #2,604
August 2002
|
Christian: What you are trying to do sounds complicated; a far easier and straightforward solution would be to just accept any kind of input and check later, i.e. when you read data back from the dialog. At that time you can throw an error message if the input cannot be interpreted as a double, or just set it to a default value. --- |
Dennis
Member #1,090
July 2003
|
I once wrote a custom edit box dialog procedure, because I also needed that "numbers only" input behaviour:
I now have modified it to (hopefully, as this is untested) replace ',' with '.' on input. The idea I based this on was to check in the custom proc, if the input was ',' and then send it as '.' to the default edit proc, by changing the c parameter of the message:
This still has a few issues though. First - is only allowed at the beginning, but actually this proc will happily let you enter two -- or even more, so you still need to parse the string to decide what input is valid, before passing the parameters on to the default d_edit_proc. Also this proc doesn't prevent entering multiple '.'s. --- 0xDB | @dennisbusch_de --- |
|