Post Reply 
Entering the 'Edit Integer' window
01-08-2024, 07:35 PM (This post was last modified: 01-08-2024 07:43 PM by komame.)
Post: #18
RE: Entering the 'Edit Integer' window
I've added some optimizations.

Code:
KEY KS_Minus()
BEGIN
  local hc="0123456789ABCDEF", white=16777215;
  local wd, wh, key, keys=MAKELIST(-1,X,0,50), value;
  keys:=REPLACE(keys,32,{7,8,9,-1,-1,4,5,6,-1,-1,1,2,3,-1,-1,0});
  keys:=REPLACE(keys,14,{10,11,12,13,14,99,15});
  keys[0]:=20;
  keys[1]:=21;
  keys[30]:=100;
  local s,h,i,he=0,ov;

  RECT_P(80,80,240,146,0,white);
  BLIT_P(80,61,241,81,G0,0,0,1,20);
  TEXTOUT_P("Edit Integer",123,62,3,white);
  TEXTOUT_P("DEC:",88,86,2,0); TEXTOUT_P("HEX:",88,100,2,0);
  TEXTOUT_P("APPS => base, ENTER => OK",88,130,1);

  REPEAT
    wd:=TEXTOUT_P(STRING(value,1),115,86,2,0,144,white);
    h:=CHAR(EXECON("hc[&1+1]",CONVERT(value,"base",16)));

    RECT_P(wd,81,239,97); // clear the space after DEC
    wh:=TEXTOUT_P(h,115,100,2,0,144,white);
    RECT_P(wh,100,239,111); // clear the space after HEX

    IF value = 0 THEN
      115▶wd▶wh;
    END;
    IF he THEN
      RECT_P(wh,100,wh+6,111,0);
    ELSE
      RECT_P(wd,86,wd+6,97,0);
    END;
    key:=keys[WAIT(0)];
    CASE
      IF key=100 THEN
        RETURN "#"+h+"h";
      END;
      IF key >= 0 AND key < 10+he*9 or key=99 THEN
        ov:=value;
        value:=IFTE(key=99,IP(value/(10+6*he)),value*(10+6*he)+key);
        IF value>999999999999 THEN
          value:=ov;
        END;
      END;
      IF key=20 THEN // Apps changes the base
        he:=NOT he; //RECT_P(115,86,239,111); // unnecessary
      END;
      IF key=21 THEN   // Symb Key sets value to 0
        value:=0;
      END;
    END;
  UNTIL ISKEYDOWN(4);  //ESC will exit

  RETURN 46;  //one way to exit program with no apparent consequences
END;

I think we're not far from a solution where this could be turned into a real editor, with the ability to move the cursor across the digits (left and right) and edit them at specific positions.
I'm leaving for the whole day tomorrow, but if you don't get this sorted out by then, I'll take care of it the day after tomorrow Wink
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Entering the 'Edit Integer' window - komame - 01-08-2024 07:35 PM



User(s) browsing this thread: