Post Reply 
Entering the 'Edit Integer' window
01-08-2024, 01:12 AM (This post was last modified: 01-08-2024 09:27 AM by matalog.)
Post: #16
RE: Entering the 'Edit Integer' window
And a little bit shorter: (edited)

Code:
KEY KS_Minus()
BEGIN
  local hc="0123456789ABCDEF";
  local w, s, d, 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,-1,15});
  keys[0]:=20;   //
  keys[1]:=21;
  keys[19]:=99;  //backspace
  keys[30]:=100; //enter
  local s,h,i,he;
 he:=0;
  RECT_P(80,80,240,146,0,16777215);
  BLIT_P(80,61,241,81,G0,0,0,1,20);
  TEXTOUT_P("Edit Integer",123,62,3,16777215);
  TEXTOUT_P("ENTER => OK",88,130,1);
  REPEAT

    w:=IFTE(he=0,IFTE(value=0,88,TEXTOUT_P(STRING(value,1),88,86,2,0,144,167772​15)),TEXTOUT_P(STRING(value,1),88,86,2,0,144,16777215));
    s:=CONVERT(value,"base",16);
    d:=GET(SIZE(s),1);
    h:="";
    FOR i FROM 1 TO d DO
    IF he and value>0 THEN
      h:=h+CHAR(hc[s[i]+1]);
    END;
    IF he=0 THEN
      h:=h+CHAR(hc[s[i]+1]);
    END;
    END;
    RECT_P(w,81,239,97);
    IF he=0 THEN 
    RECT_P(w,86,w+9,97,0);
    END;
    w:=TEXTOUT_P("HEX: "+h,88,100,2,0,144,16777215);
    RECT_P(w,100,239,111);
    IF he=1 THEN
        RECT_P(w,100,w+9,111,0);
    END;
    key:=keys[WAIT(0)];
    IF key=100 THEN
      RETURN "#"+h+"h";
    END;
    IF key=99 or key <> -1 AND key <10+he*9 THEN
      value:=IFTE(key=99,IP(value/(10+6*he)),value*(10+6*he)+key);
    END;
    IF key=20 THEN
    RECT_P(86,86,239,111);
    he:=NOT he;
    END;
    IF key=21 THEN   // Symb Key sets value to 0
    value:=0;
    END;

  UNTIL ISKEYDOWN(4);  //ESC will exit
RETURN 46;  //one way to exit program with no apparent consequences
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Entering the 'Edit Integer' window - matalog - 01-08-2024 01:12 AM



User(s) browsing this thread: 3 Guest(s)