Author Topic: External ASCII Chart  (Read 3357 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
External ASCII Chart
« on: September 10, 2018, 03:11:05 pm »
Since a lot of folks here didn't seem to know about QB64's in-built ASCII chart, I can only assume that they also don't know the history of the chart...   

When I was working on my IDE several years back, I tried to think of all the features that I'd like for it to have that QB64 didn't have.  The ASCII chart was one of those features, as well as the Math Calculator which is currently used for both CONST evaluation and the Math function available under Help.

Once I'd gotten them working in StevesIDE, I made certain to make them as portable as I possibly could, and then I worked around with adding them into QB64 for everyone.  At first, both routines used external calls to stand-alone programs, which QB64 shelled out to, and then used the SHELL return value inside QB64 itself.  You can still see the comment where this happened if you look inside the QB64 source at the current version of ideASCIIchart:

    'IF INSTR(_OS$, "WIN") THEN ret% = SHELL("internal\ASCII-Picker.exe") ELSE ret% = SHELL("internal/ASCII-Picker")

This worked fine back in the SDL days, but somehow it got broken for Linux users once we swapped to over to the GL version.  You could select SPACE (value 32) in Linux, and sometimes it'd give a return value of 214, or something equally odd.  That glitch was never sorted out properly, as it seemed OS specific to certain versions of Linux only, and instead the ASCII chart was modified to work directly with QB64's internal strings -- which is how it currently exists today.  (Whether SHELL's return values are still broken for Linux, I couldn't tell you.  Somebody else, with a Linux machine, would have to test that out to see.)

Personally, I like the in-built ASCII chart QB64 has.  Gives values as well as being clickable and selectable!  Found happily enough under the Help tab, on the top right of the IDE.
Oh my goodness, I did not even see this, LOL. Yes, it is handy. Is there a way it can be made to appear without losing the code window though?

Since folks have been asking about making it appear without losing the code window, that's a simple enough request which I can easily give a response to: SURE IT CAN!!  WOOT!!WOOT!!

After all, it was an external program, completely independent to QB64 itself, to begin with....

Code: QB64: [Select]
  1. _TITLE "External ASCII Picker"
  2. SCREEN _NEWIMAGE(640, 480, 32)
  3. f = _LOADFONT("cour.ttf", 128) 'a nice large display font, not a 100% match to QB64's inbuilt version,
  4. _FONT f '                       but it works easily here for a demo highlight character
  5.  
  6.  
  7.  
  8.     _CLIPBOARD$ = ASCIIbox$ 'get an ASCII character
  9.     CLS
  10.     PRINT _CLIPBOARD$ 'preview it
  11.     SLEEP: _KEYCLEAR 'hit a key to select another
  12. LOOP UNTIL RIGHT$(out$, 1) = CHR$(27)
  13.  
  14. FUNCTION ASCIIbox$
  15.     STATIC temp AS LONG, temp1 AS LONG, ws AS LONG
  16.     d = _DEST
  17.     font = _FONT
  18.     IF temp = 0 THEN 'static backgrounds so we don't have to make them over and over, or worry about freeing them
  19.         temp = _NEWIMAGE(640, 480, 32)
  20.         temp1 = _NEWIMAGE(640, 480, 32)
  21.         ws = _NEWIMAGE(640, 480, 32)
  22.     END IF
  23.     SCREEN temp
  24.     DIM CurrentASC(1 TO 16, 1 TO 16)
  25.     DIM CurrentOne AS INTEGER
  26.     CLS , _RGB(0, 0, 170)
  27.     COLOR , _RGB(0, 0, 170)
  28.     FOR y = 1 TO 16
  29.         FOR x = 1 TO 16
  30.             LINE (x * 40, 0)-(x * 40, 480), _RGB32(255, 255, 0)
  31.             LINE (0, y * 30)-(640, y * 30), _RGB32(255, 255, 0)
  32.             IF counter THEN _PRINTSTRING (x * 40 - 28, y * 30 - 23), CHR$(counter)
  33.             counter = counter + 1
  34.         NEXT
  35.     NEXT
  36.  
  37.     _DEST temp1
  38.     CLS , _RGB(0, 0, 170)
  39.     COLOR , _RGB(0, 0, 170)
  40.     counter = 0
  41.     FOR y = 1 TO 16
  42.         FOR x = 1 TO 16
  43.             LINE (x * 40, 0)-(x * 40, 480), _RGB32(255, 255, 0)
  44.             LINE (0, y * 30)-(640, y * 30), _RGB32(255, 255, 0)
  45.             text$ = LTRIM$(STR$(counter))
  46.             IF counter THEN _PRINTSTRING (x * 40 - 24 - (LEN(text$)) * 4, y * 30 - 23), text$
  47.             counter = counter + 1
  48.         NEXT
  49.     NEXT
  50.     _DEST temp
  51.  
  52.     x = 1: y = 1
  53.     _PUTIMAGE , temp, ws
  54.     DO: LOOP WHILE _MOUSEINPUT 'clear the mouse input buffer
  55.     oldmousex = _MOUSEX: oldmousey = _MOUSEY
  56.  
  57.     DO
  58.         _LIMIT 60
  59.         DO: LOOP WHILE _MOUSEINPUT
  60.         IF oldx <> _MOUSEX AND oldy <> _MOUSEY THEN
  61.             x = _MOUSEX \ 40 + 1 'If mouse moved, where are we now?
  62.             y = _MOUSEY \ 30 + 1
  63.         END IF
  64.         oldx = _MOUSEX: oldy = _MOUSEY
  65.  
  66.         num = (y - 1) * 16 + x - 1
  67.         IF num = 0 THEN
  68.             text$ = ""
  69.         ELSE
  70.             flashcounter = flashcounter + 1
  71.             IF flashcounter > 30 THEN
  72.                 COLOR _RGB32(255, 255, 255), _RGB(0, 0, 170)
  73.                 text$ = CHR$(num)
  74.                 IF LEN(text$) = 1 THEN text$ = " " + text$ + " "
  75.             ELSE
  76.                 COLOR _RGB32(255, 255, 255), _RGB(0, 0, 170)
  77.                 text$ = RTRIM$(LTRIM$(STR$(num)))
  78.             END IF
  79.         END IF
  80.         IF flashcounter = 60 THEN flashcounter = 1
  81.         CLS
  82.         IF toggle THEN _PUTIMAGE , temp1, temp ELSE _PUTIMAGE , ws, temp
  83.         _PRINTSTRING (x * 40 - 24 - (LEN(text$)) * 4, y * 30 - 23), text$
  84.         LINE (x * 40 - 40, y * 30 - 30)-(x * 40, y * 30), _RGBA32(255, 255, 255, 150), BF
  85.  
  86.         k1 = _KEYHIT
  87.         MouseClick = 0: MouseExit = 0
  88.         IF MouseButtonSwapped THEN
  89.             MouseClick = _MOUSEBUTTON(2): MouseExit = _MOUSEBUTTON(1)
  90.         ELSE
  91.             MouseClick = _MOUSEBUTTON(1): MouseExit = _MOUSEBUTTON(2)
  92.         END IF
  93.         SELECT CASE k1
  94.             CASE 13: EXIT DO
  95.             CASE 27
  96.                 GOTO cleanexit
  97.             CASE 32: toggle = NOT toggle
  98.             CASE 18432: y = y - 1
  99.             CASE 19200: x = x - 1
  100.             CASE 20480: y = y + 1
  101.             CASE 19712: x = x + 1
  102.         END SELECT
  103.  
  104.         IF x < 1 THEN x = 1
  105.         IF x > 16 THEN x = 16
  106.         IF y < 1 THEN y = 1
  107.         IF y > 16 THEN y = 16
  108.         _DISPLAY
  109.         IF MouseExit GOTO cleanexit
  110.     LOOP UNTIL MouseClick
  111.  
  112.     ret% = (y - 1) * 16 + x - 1
  113.     IF ret% > 0 AND ret% < 255 THEN
  114.         ASCIIbox$ = CHR$(ret%)
  115.     END IF
  116.     cleanexit:
  117.  
  118.     SCREEN d
  119.     _FONT font
  120.     _DEST 0: _DELAY .2
  121.  
  122.  

Run the above and we get the ASCII Chart we all know and love.  (And if someone didn't know it, they do now, and I'm certain they'll love it...)  Choose a character, it'll copy to your clipboard, where it should paste into whichever program you need it to -- including QB64.

It's not quite as simple as Click-To-Insert, as it's Click-To-Clipboard, but it does have the added advantage of staying up for those times when you simply need to know what character corresponds to what value.  Feel free to save it and use it for all you ASCII needs.  :)

Edit: Cleaned up the code just a bit since it doesn't have to work just for SCREEN 0, like with QB64's IDE.  Also loaded a larger font for display purposes, just for the heck of it.  :P
« Last Edit: September 10, 2018, 03:33:23 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: External ASCII Chart
« Reply #1 on: September 10, 2018, 03:56:41 pm »
Woot! Woot!

Now have ASCII_Chart.exe on my desktop whenever I need it.
« Last Edit: September 10, 2018, 04:02:34 pm by TerryRitchie »
In order to understand recursion, one must first understand recursion.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: External ASCII Chart
« Reply #2 on: September 10, 2018, 04:14:35 pm »
Hey Steve!  I remember your IDE and chart.  I still have them on my old laptop.  Handy chart.  I'll be using it.

- Dav