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? |
|||
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:
Here is a little demo to get you started: Code:
|
|||
08-27-2023, 09:52 PM
Post: #3
|
|||
|
|||
RE: HP 48GX - Center Text in the Display Area | |||
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. |
|||
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. |
|||
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: The code in your most recent post simply draws 3,4,5,6 and 7 on successive lines: 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? If so, what are you trying that's not working? |
|||
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? 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. |
|||
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:
|
|||
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. 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 |
|||
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? 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. |
|||
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: That's certainly a succinct strategy. I'm glad you clarified what the commands do. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)