ArrayArrayArrayArrayArrayArrayArrayArrayArrayArray
CODE:
//////////////////////////////////////////// // SWITCH AS TEXT FADER // if you are tired of those tiny windows 95 text entry popups, try this. It uses the text of// the button, so you can make it as large as you like. If the text will end up as the// title of the button, you can also know whether it will fit...//// off text is typically the title. when the user presses the switch// the text shown is either what was last entered, or an empty string, depending // on the state of 'clear existing'.// 'text to switch' is typically wired to the switch on caption, but could be wired// to the switch off caption as well, to show the value even when it's off.// since we don't have a cursor, a backspace will clear all the text. Actually more convenient// for short text, I think.// ////////////////////////////////////////////const ENTER = 13;const BACKSPACE = 8;const ESCAPE = 27; // Globally enable/disable logging const DTAG = 'TextButton: ';const DBUG_ON = TRUE;procedure debug(s: string); begin if DBUG_ON then strace(DTAG + s); end;procedure iDebug(s: string; num : integer); begin debug(s + '= ' + intToStr(num)); end;// parameters declaration var switchIN, switchTextIN, keyNumIN, keyDownIN, offEntersIN, clearTextIN: tParameter;var textOUT, switchOffOUT, switchTextOUT: tParameter;var gText, gRevertText, gKeyin: string;var gKeynum: integer;var gLive,gSwitchedOff: boolean; // initialisation : create parametersprocedure init;var i : integer; begin SetModuleColor($804080+600000); switchIN := CreateParam('switch in', ptSwitch, pioInput); //if we start with existing text switchTextIN := CreateParam('switch text', ptTextfield, pioInput); keyNumIN := CreateParam('key num', ptDatafield, pioInput); clearTextIN := CreateParam('clear existing', ptSwitch, pioInput); switchOffOUT := CreateParam('set switch off', ptButton, pioOutput); switchTextOUT := CreateParam('text to switch', ptTextfield, pioOutput); //text to send on textOUT := CreateParam('text out', ptTextfield, pioOutput); gLive := FALSE; gSwitchedOff := TRUE; end;procedure processSwitch(state: integer);begin if state = 0 then //switch turned off begin gLive := FALSE; end else if (state = 1) then //switch turned on begin if clearTextIN.asInteger = 0 then gText := switchTextIN.asString else gText := ''; switchTextOUT.asString(gText); gRevertText := switchTextIN.asString;; //save this in case the user cancels. gLive := TRUE; endend;procedure processKey(keynum: integer);begin //if the key is backspace, clear everything. We have no cursor, so this is how we do it if keynum = BACKSPACE then begin gText := ''; switchTextOUT.asString(gText); end //if the key is enter, send the text to the output and turn off the button else if keynum = ENTER then begin //button text will not need to be changed.... oh I guess it does. textOUT.asString(gText); switchTextOUT.asString(gText); switchOffOUT.asInteger(1); gSwitchedOff := TRUE; end //if the key is esc, clear the text and turn off the button else if keynum = ESCAPE then begin //gText := ''; switchOffOUT.asInteger(1); switchTextOUT.asString(gRevertText); gSwitchedOff := TRUE; end //otherwise, add the key to buttonText and send it out. else begin Debug('key ' + Chr(keynum)); gText := gText + Chr(keynum); switchTextOUT.asString(gText); gSwitchedOff := TRUE; end; //end;procedure Callback(n:integer); begin if n = switchIN then processSwitch(switchIN.asInteger) else if (n = keyNumIN) and (keyNumIN.asInteger > 0) and gLive then begin //we could store, and wait for zero (key up) idebug('process key num',keyNumIN.asInteger); processKey(keyNumIN.asInteger); endend;// no process blocprocedure processIdle();begin if gSwitchedOff then begin gSwitchedOff := FALSE; switchOffOUT.asInteger(0); textOUT.length(-1); switchTextOUT.length(-1); end;end;Statistics: Posted by woodslanding — 09 Dec 2024, 07:39
Statistics: Posted by woodslanding — 09 Dec 2024, 02:48
Statistics: Posted by woodslanding — 08 Dec 2024, 17:38
Statistics: Posted by woodslanding — 08 Dec 2024, 07:04
Statistics: Posted by senso — 25 Nov 2022, 10:18
Statistics: Posted by woodslanding — 25 Nov 2022, 07:03
Statistics: Posted by woodslanding — 25 Nov 2022, 06:52
Statistics: Posted by woodslanding — 25 Nov 2022, 06:33
CODE:
//////////////////////////////////////////// // SWITCH AS TEXT FADER // if you are tired of those tiny windows 95 text entry popups, try this. It uses the text of// the button, so you can make it as large as you like. If the text will end up as the// title of the button, you can also know whether it will fit...//// off text is typically the title. when the user presses the switch// the text shown is either what was last entered, or an empty string, depending // on the state of 'clear existing'.// 'text to switch' is typically wired to the switch on caption, but could be wired// to the switch off caption as well, to show the value even when it's off.// since we don't have a cursor, a backspace will clear all the text. Actually more convenient// for short text, I think.// ////////////////////////////////////////////const ENTER = 13;const BACKSPACE = 8;const ESCAPE = 27; // Globally enable/disable logging const DTAG = 'TextButton: ';const DBUG_ON = TRUE;procedure debug(s: string); begin if DBUG_ON then strace(DTAG + s); end;procedure iDebug(s: string; num : integer); begin debug(s + '= ' + intToStr(num)); end;// parameters declaration var switchIN, switchTextIN, keyNumIN, keyDownIN, offEntersIN, clearTextIN: tParameter;var textOUT, switchOffOUT, switchTextOUT: tParameter;var gText, gRevertText, gKeyin: string;var gKeynum: integer;var gLive,gSwitchedOff: boolean; // initialisation : create parametersprocedure init;var i : integer; begin SetModuleColor($804080+600000); switchIN := CreateParam('switch in', ptSwitch, pioInput); //if we start with existing text switchTextIN := CreateParam('switch text', ptTextfield, pioInput); keyNumIN := CreateParam('key num', ptDatafield, pioInput); clearTextIN := CreateParam('clear existing', ptSwitch, pioInput); switchOffOUT := CreateParam('set switch off', ptButton, pioOutput); switchTextOUT := CreateParam('text to switch', ptTextfield, pioOutput); //text to send on textOUT := CreateParam('text out', ptTextfield, pioOutput); gLive := FALSE; gSwitchedOff := TRUE; end;procedure processSwitch(state: integer);begin if state = 0 then //switch turned off begin gLive := FALSE; end else if (state = 1) then //switch turned on begin if clearTextIN.asInteger = 0 then gText := switchTextIN.asString else gText := ''; switchTextOUT.asString(gText); gRevertText := switchTextIN.asString;; //save this in case the user cancels. gLive := TRUE; endend;procedure processKey(keynum: integer);begin //if the key is backspace, clear everything. We have no cursor, so this is how we do it if keynum = BACKSPACE then begin gText := ''; switchTextOUT.asString(gText); end //if the key is enter, send the text to the output and turn off the button else if keynum = ENTER then begin //button text will not need to be changed.... oh I guess it does. textOUT.asString(gText); switchTextOUT.asString(gText); switchOffOUT.asInteger(1); gSwitchedOff := TRUE; end //if the key is esc, clear the text and turn off the button else if keynum = ESCAPE then begin //gText := ''; switchOffOUT.asInteger(1); switchTextOUT.asString(gRevertText); gSwitchedOff := TRUE; end //otherwise, add the key to buttonText and send it out. else begin Debug('key ' + Chr(keynum)); gText := gText + Chr(keynum); switchTextOUT.asString(gText); gSwitchedOff := TRUE; end; //end;procedure Callback(n:integer); begin if n = switchIN then processSwitch(switchIN.asInteger) else if (n = keyNumIN) and (keyNumIN.asInteger > 0) and gLive then begin //we could store, and wait for zero (key up) idebug('process key num',keyNumIN.asInteger); processKey(keyNumIN.asInteger); endend;// no process blocprocedure processIdle();begin if gSwitchedOff then begin gSwitchedOff := FALSE; switchOffOUT.asInteger(0); textOUT.length(-1); switchTextOUT.length(-1); end;end;Statistics: Posted by woodslanding — 09 Dec 2024, 07:39
Statistics: Posted by woodslanding — 09 Dec 2024, 02:48
Statistics: Posted by woodslanding — 08 Dec 2024, 17:38
Statistics: Posted by woodslanding — 08 Dec 2024, 07:04
Statistics: Posted by senso — 25 Nov 2022, 10:18
Statistics: Posted by woodslanding — 25 Nov 2022, 07:03
Statistics: Posted by woodslanding — 25 Nov 2022, 06:52
Statistics: Posted by woodslanding — 25 Nov 2022, 06:33