Post Reply 
HP 48GX - Center Text in the Display Area
08-27-2023, 04:48 PM
Post: #1
HP 48GX - Center Text in the Display Area
How would I center text in the display area?

\<< DUP SIZE NEG 22 +
2 / \-> f \<< " " 1 f
START " " + NEXT
SWAP + \>>
\>>

1: "text string"

The above example string contains 11 characters. That means I'm left with 5.5 spaces proceeding and preceding the string if it were centered in the display area. My code fails because I can't use half of a space. What can I do?
Find all posts by this user
Quote this message in a reply
08-27-2023, 08:41 PM (This post was last modified: 08-27-2023 09:44 PM by Giuseppe Donnini.)
Post: #2
RE: HP 48GX - Center Text in the Display Area
If you use string objects, the finest granularity you can achieve is indeed a single character’s width. If you want pixel-granularity, you have to use graphics objects instead, that is, you have to convert your text strings into separate graphics objects and then paste them into the graphics screen (i.e. PICT; System RPL would allow you to use the text display, too.)

The \->GROB command exists for this very purpose. It takes two arguments:
  • in level 2, a character string to be transformed into a graphics object;
  • in level 1, a real integer from 0 to 3 specifying the font size to be used.
    • 1 represents the small font (variable width [ranging from 2 to 6 pixels] x 6 pixels, the bottom row being always left blank since the small font has no descenders).
    • 2 represents the medium font (6 pixels wide x 8 pixels high).
    • 3 represents the large font (6 pixels wide x 10 pixels high).
      (Note that in all three cases, the width includes a blank column at the right edge that separates successive characters.)
    • 0 is intended for mathematical expressions. It uses all three fonts, if necessary, and produces an EquationWriter-like image of the input. The size of the resulting graphics object will be at least 131 x 56 pixels, even if the expression does not fill the entire display.

Here is a little demo to get you started:
Code:

\<< PICT DUP PURGE   @ Clear graphics screen, keep copy.
  "Test String"      @ Use arbitrary text string for test purposes.
  2 \->GROB          @ Convert input text to grob using medium font.
  DUP SIZE DROP      @ Get size of grob; drop height, keep width.
  #131d SWAP - 2 /   @ Compute #x-coordinate so that grob will be horizontally centered.
  #0                 @ Use arbitrary #y-coordinate for test purposes (0 = top row).
  2 \->LIST          @ Build pixel coordinate pair.
  SWAP REPL          @ Paste grob into graphics screen (automatically resized to 131 x 64).
  {} PVIEW           @ Show result.
\>>
Find all posts by this user
Quote this message in a reply
08-27-2023, 09:52 PM
Post: #3
RE: HP 48GX - Center Text in the Display Area
(08-27-2023 08:41 PM)Giuseppe Donnini Wrote:  If you use string objects, the finest granularity you can achieve is indeed a single character’s width.

Thanks for your help, Giuseppe.
Find all posts by this user
Quote this message in a reply
08-30-2023, 02:13 AM (This post was last modified: 08-30-2023 02:31 AM by MNH.)
Post: #4
RE: HP 48GX - Center Text in the Display Area
(08-27-2023 08:41 PM)Giuseppe Donnini Wrote:  If you want pixel-granularity, you have to use graphics objects instead, that is, you have to convert your text strings into separate graphics objects and then paste them into the graphics screen (i.e. PICT; System RPL would allow you to use the text display, too.)

\<< PICT DUP PURGE
SWAP 2 \->GROB DUP
SIZE DROP # 131d
SWAP - 2 / # 0d 2
\->LIST SWAP REPL {}
PVIEW
\>>

1: "PT 701 TO PT 702"

This works well.


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
09-02-2023, 04:55 PM (This post was last modified: 09-02-2023 04:56 PM by MNH.)
Post: #5
RE: HP 48GX - Center Text in the Display Area
(08-27-2023 08:41 PM)Giuseppe Donnini Wrote:  If you want pixel-granularity, you have to use graphics objects instead, that is, you have to convert your text strings into separate graphics objects and then paste them into the graphics screen (i.e. PICT; System RPL would allow you to use the text display, too.)

\<< STD 2 \-> x
\<< CLLCD 1 5
START 'x' INCR
DUP "" + SWAP DISP
NEXT 3 FREEZE
\>>
\>>

Using the above program as an example, how would I display "Test String", centered, along with all of the display areas? PICT PURGE purges the graphics environment until a GROB is pasted in it.
Find all posts by this user
Quote this message in a reply
09-03-2023, 12:57 PM
Post: #6
RE: HP 48GX - Center Text in the Display Area
(09-02-2023 04:55 PM)MNH Wrote:  Using the above program as an example, how would I display "Test String", centered, along with all of the display areas? PICT PURGE purges the graphics environment until a GROB is pasted in it.

Giuseppe's first response in this thread (post #2) gives an example code object that centers an arbitrary string on the display:
[Image: 176860_1.png]

The code in your most recent post simply draws 3,4,5,6 and 7 on successive lines:
[Image: 176860_2.png]

It's probably only me, but I'm not sure what you are really asking here. Is your end goal to have something that combines the two, like this?
[Image: 176860_3.png]

If so, what are you trying that's not working?
Find all posts by this user
Quote this message in a reply
09-03-2023, 02:17 PM
Post: #7
RE: HP 48GX - Center Text in the Display Area
(08-27-2023 04:48 PM)MNH Wrote:  How would I center text in the display area?

\<< DUP SIZE NEG 22 +
2 / \-> f \<< " " 1 f
START " " + NEXT
SWAP + \>>
\>>

1: "text string"

The above example string contains 11 characters. That means I'm left with 5.5 spaces proceeding and preceding the string if it were centered in the display area. My code fails because I can't use half of a space. What can I do?

Hi all. I haven’t programmed my 48 in a while.
Please let me know what \>> and \-> f \<< are and how to type them in. Thank you.
Find all posts by this user
Quote this message in a reply
09-03-2023, 03:27 PM (This post was last modified: 09-03-2023 08:59 PM by Giuseppe Donnini.)
Post: #8
RE: HP 48GX - Center Text in the Display Area
In my demo, I used the graphics screen (PICT) as a quick means to show the final picture, because, in User RPL, graphics objects can only be pasted directly into PICT, not into the text screen (TEXT). However, if you want to use the DISP command together with pixel-precise methods, I would suggest using the text screen, which has the additional advantage of not disturbing a plot or other picture currently in PICT.

Since User RPL does not allow us to paste single graphics objects directly into the text screen, we have to use the following strategy:

1. Use DISP to put the different text elements on the text screen, except for those elements that need pixel-precise positioning.
2. Use LCD\-> to put a copy of the current text screen on the stack.
3. Use \->GROB to convert the remaining text elements (those needing pixel-precise treatment) to graphics objects.
4. Use REPL to paste them into the (copy of the) text screen.
5. Use \->LCD (together with FREEZE) to put everything back and display the result.

For instance:

Code:

\<<
  RCLF STD           @ Save current modes, activate STD.
  CLLCD              @ Clear text screen.
  1 6 FOR n          @ For n from 1 to 6:
    n \->STR         @ - Convert (real number) n to text string.
    n 1 + DISP       @ - Display it on the (n+1)th line.
  NEXT
  LCD\->             @ Get copy of entire text screen.
  "Test String"      @ Use arbitrary title string for test purposes.
  2 \->GROB          @ Convert title text to grob using medium font.
  DUP SIZE DROP      @ Get size of title grob; drop height, keep width.
  #131d SWAP - 2 /   @ Compute #x-coordinate so that title will be horizontally centered.
  #0                 @ Use 0 as #y-coordinate (top row).
  2 \->LIST          @ Build pixel coordinate pair.
  SWAP REPL          @ Paste title grob into copy of text screen.
  \->LCD             @ Overwrite text screen with new copy.
  3 FREEZE           @ Freeze status and stack areas.
  STOF               @ Restore initial modes.
\>>
Find all posts by this user
Quote this message in a reply
09-03-2023, 04:48 PM
Post: #9
RE: HP 48GX - Center Text in the Display Area
(09-03-2023 02:17 PM)Matt Agajanian Wrote:  Hi all. I haven’t programmed my 48 in a while.
Please let me know what \>> and \-> f \<< are and how to type them in. Thank you.

Many of the 48's built-in characters are not ASCII, so a scheme was created by HP that maps those special characters to a sets of several ASCII characters, and these sets are automatically translated when sent to/from the 48 via ConnKit.

See p. 27-16 in the 48GX Users Guide, available here:
https://literature.hpcalc.org/items/375

which summarizes the translation sets.

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
09-03-2023, 07:27 PM
Post: #10
RE: HP 48GX - Center Text in the Display Area
(09-03-2023 12:57 PM)DavidM Wrote:  It's probably only me, but I'm not sure what you are really asking here. Is your end goal to have something that combines the two, like this?
[Image: 176860_3.png]

Yes.

(09-03-2023 12:57 PM)DavidM Wrote:  If so, what are you trying that's not working?

I'm still working on the code. I don't understand how to clear the part of the display area that will contain my centered text string.
Find all posts by this user
Quote this message in a reply
09-03-2023, 07:43 PM
Post: #11
RE: HP 48GX - Center Text in the Display Area
(09-03-2023 03:27 PM)Giuseppe Donnini Wrote:  Since User RPL does not allow us to paste single graphics objects directly into the text screen, we have to use the following strategy:

1. Use DISP to put the different text elements on the text screen, except for those elements that need pixel-precise positioning.
2. Use LCD\-> to put a copy of the current text screen on the stack.
3. Use \->GROB to convert the remaining text elements (those needing pixel-precise treatment) to graphics objects.
4. Use REPL to paste them into the (copy of the) text screen.
5. Use \->LCD (together with FREEZE) to put everything back and display the result.

That's certainly a succinct strategy. I'm glad you clarified what the commands do.
Find all posts by this user
Quote this message in a reply
Post Reply 




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