Keeping graphic objects in programs
11-20-2020, 02:19 AM
Post: #1
 cahlucas Member Posts: 120 Joined: Mar 2016
Keeping graphic objects in programs
Hi all,
The program I'm currently making uses a lot of graphic objects, and it takes time to create them on the screen. That is why I want to save these objects in the program, ready to use, in such a way that they do not have to be built up completely, but can be displayed directly on the screen. You can compare this to a GROB that you keep in a variable on the HP-50g, ready to display on the screen. I know this is possible because it is done in the PhysicsElectronics program (https://www.hpcalc.org/details/7773), possibly in even more programs. Can someone explain to me how to create something like this? Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
11-20-2020, 08:40 AM (This post was last modified: 11-20-2020 08:59 AM by gege.)
Post: #2
 gege Junior Member Posts: 10 Joined: Aug 2016
RE: Keeping graphic objects in programs
You can create your program into an application library. In this library you include png or jpeg files into your project and load it with:
Code:
AFiles("mypicture.png")▶G1;
And after use BLIT_P function to display it.
Code:
BLIT_P(G1);

Another method is to use DIMGROB_P, see this thread.
Or use ICON, like this.
11-21-2020, 03:03 AM
Post: #3
 cahlucas Member Posts: 120 Joined: Mar 2016
RE: Keeping graphic objects in programs
(11-20-2020 08:40 AM)gege Wrote:  You can create your program into an application library. In this library you include png or jpeg files into your project and load it with:
Code:
AFiles("mypicture.png")▶G1;
And after use BLIT_P function to display it.
Code:
BLIT_P(G1);

Another method is to use DIMGROB_P, see this thread.
Or use ICON, like this.

Dear Mr. Gege,
I like the ICON method, how can I use it with graphics made on my Prime? At least, I hope this is possible. How do I do that, and how do I bring it up on the screen? Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
11-21-2020, 09:38 AM
Post: #4
 gege Junior Member Posts: 10 Joined: Aug 2016
RE: Keeping graphic objects in programs
A sample of use for ICON. But ICON is deprecated and is not available in the last firmware.
To convert picture to GROB or ICON you can use the DimGrob program.
11-21-2020, 04:43 PM
Post: #5
 Han Senior Member Posts: 1,842 Joined: Dec 2013
RE: Keeping graphic objects in programs
(11-21-2020 03:03 AM)cahlucas Wrote:  Dear Mr. Gege,
I like the ICON method, how can I use it with graphics made on my Prime? At least, I hope this is possible. How do I do that, and how do I bring it up on the screen? Sincerely, Karel.

If you type ICON in the command line, and while the cursor is touching any letter of the word ICON, pressing the [Help] key will bring up any relevant information on its usage. The unfortunate drawback (pun optional) is that one must rely on computer program to create the data for the ICON command. The data itself can be quite large even for very small images, and it makes code management extremely cumbersome if you ever need to alter your images. In short, there are much better ways that will also make your code more manageable.

If you are planning to create a relatively large project (perhaps large due to lots of graphics files), I would recommend creating them as PNG files. This can be done on your computer. Simply create them, and incorporate them into your application. Or if you generate them on your calculator, you can save the image on the screen using AFiles("filename.png"):=G0 (G0 through G9 are the system's graphic objects, with G0 being the current screen.) The AFiles() command really only makes sense within a custom application (i.e. an app you create based on one of the existing apps).

One of the applications I wrote makes use of an extensive collection of images: https://www.hpmuseum.org/forum/thread-7725.html

The source code is provided as well, so you are welcome to look at how they are used. A snippet of the drawing routine is below. Basically, the images are stored as img##.png files where ## are alphanumeric digits and "na" specifically means a picture is not available (scheme selected for ease of coding). The "picture" is either a static image, or a collection of frames within an animation.
Code:
// UI for viewing picture ssShowPic() begin   local j,n,x,y,run,fname,frames;   fname:=ssCurSys(9);   if (type(fname) == 2) then     // fixed image     if (fname == "na") then       msgbox(ssNoPicAvail);     else       dimgrob_p(G2,1,1);       fname:="img" + fname + ".png";       G2:=AFiles(fname);       x:=grobw_p(G2);       y:=grobh_p(G2);       if ((x < 160) AND (y < 120)) then         x:=2*x; y:=2*y;       end;       rect_p(G0);       blit_p(160-x/2, 120-y/2,160+x/2,120+y/2,G2);       textout_p(ssCurSys(1),1,1,4,ssR);       freeze;       wait(-1);     end;   else     // animation (list)     frames:=fname;     n:=size(frames)-1;     dimgrob_p(G2,1,1);     fname:="img" + frames(1) + ".png";     G2:=AFiles(fname);     x:=grobw_p(G2);     y:=grobh_p(G2);     if ((x < 160) AND (y < 120)) then       x:=2*x; y:=2*y;     end;     j:=0;     run:=1;     rect_p(G0);     textout_p(ssCurSys(1),1,1,4,ssR);     while run do       j:=(j mod n) + 1;       fname:="img" + frames(j) + ".png";       G2:=AFiles(fname);       blit_p(160-x/2, 120-y/2,160+x/2,120+y/2,G2);       wait(frames(n+1));       run:=(mouse(1)==-1) AND (getkey() == -1);     end;   end; end;

Graph 3D | QPI | SolveSys
11-21-2020, 05:29 PM
Post: #6
 gege Junior Member Posts: 10 Joined: Aug 2016
RE: Keeping graphic objects in programs
What's I remember is ICON is deprecated and no more available on last firmware.
11-21-2020, 06:03 PM
Post: #7
 Han Senior Member Posts: 1,842 Joined: Dec 2013
RE: Keeping graphic objects in programs
(11-21-2020 05:29 PM)gege Wrote:  What's I remember is ICON is deprecated and no more available on last firmware.

Not all users necessarily update to the most recent firmware. I am aware that the most firmware, for example, breaks certain commands. As an example, EDITMAT doesn't work properly and is somewhat crucial in displaying the results in a solver app I wrote. So I have kept one of my Primes on an older firmware for this reason.

Graph 3D | QPI | SolveSys
11-22-2020, 12:48 AM
Post: #8
 cahlucas Member Posts: 120 Joined: Mar 2016
RE: Keeping graphic objects in programs
(11-21-2020 04:43 PM)Han Wrote:  If you are planning to create a relatively large project (perhaps large due to lots of graphics files), I would recommend creating them as PNG files. This can be done on your computer. Simply create them, and incorporate them into your application. Or if you generate them on your calculator, you can save the image on the screen using AFiles("filename.png"):=G0 (G0 through G9 are the system's graphic objects, with G0 being the current screen.) The AFiles() command really only makes sense within a custom application (i.e. an app you create based on one of the existing apps).
Dear Mr. Han,
How can I make such an app? What I've noticed about custom apps is that there are files placed in a directory, and the extension is ".hpappdir". This directory must then be copied into the CK during installation. Do you create such a directory on the PC / MAC, and is it compatible with the Prime? And how do you load those .PNG files into your program? This is all very confusing to me. I would like to receive a response from you. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
11-22-2020, 02:44 AM (This post was last modified: 11-22-2020 02:46 AM by Han.)
Post: #9
 Han Senior Member Posts: 1,842 Joined: Dec 2013
RE: Keeping graphic objects in programs
The best way, in my personal opinion, is to use the connectivity kit (CK) while your calculator (real or virtual) is connected to your computer.

1. Find your calculator on the left side, and click on Application Library. Your own app should be created using one of the existing applications (used as a template). So for example, in the past I wrote a 3D graphing app (link below in my signature) and it was based on the Advanced Graphing app. Let's use this one as an example. Right-click on Advanced Graphing, and select Copy.

2. Rename the copy to whatever is appropriate for your project. Then open the project in the CK by double clicking on it. A window will open to the right side and you should see a bunch of tabs corresponding to the black "app" keys on the calculator (near the direction pad). In particular, though, is the Program tab which is the "file" that contains your source code.

3. An app basically takes over the "base" app (in our case, the Advanced Graphing app) via built-in functions that are pre-populated for you in the CK. You simply have to modify them to suit your needs. The basics can be found in this video: https://www.youtube.com/watch?v=hv-MMwfzwwA (it's quite outdated, but the main ideas are all still applicable).

Other resources that would be of benefit if you are new to the process:

https://www.hpmuseum.org/forum/thread-215.html
https://www.hpmuseum.org/forum/thread-216.html

Once you are ready to test your app, you can either send it to your calculator (make sure to edit the source file via the Program editor to "Check" and make sure there are no source code errors first). The other option is to simultaneously run the virtual app, and test it out on the virtual app.

Graph 3D | QPI | SolveSys
11-22-2020, 07:11 PM
Post: #10
 cahlucas Member Posts: 120 Joined: Mar 2016
RE: Keeping graphic objects in programs
Dear Mr. Han,
I will try this out very soon after I have seen the tutorials. What remains for me is how best to convert the graphics I made on the Prime into something usable using the command "AFiles ()" in conjunction with that copied app. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
11-24-2020, 10:58 PM
Post: #11
 cahlucas Member Posts: 120 Joined: Mar 2016
RE: Keeping graphic objects in programs
Dear Mr. Han,
I made a copy of the spreadsheet app. What is the best way to use the command "AFiles ();"? Are the graphics saved on the computer? And do I then have to put them in a directory, along with my program? Can this also be done on a MAC? Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
11-25-2020, 06:41 PM (This post was last modified: 11-25-2020 06:46 PM by Han.)
Post: #12
 Han Senior Member Posts: 1,842 Joined: Dec 2013
RE: Keeping graphic objects in programs
(11-24-2020 10:58 PM)cahlucas Wrote:  Dear Mr. Han,
I made a copy of the spreadsheet app. What is the best way to use the command "AFiles ();"? Are the graphics saved on the computer? And do I then have to put them in a directory, along with my program? Can this also be done on a MAC? Sincerely, Karel.

EDIT: Also, to capture the screen, another simple method is to connect your calculator to the CK and use the Monitor panel to capture the screen. There is a monitor icon on the top right to reveal the Monitor panel. Right click your screen's mini-snapshot and use Save As...

Original message:

Within your copied app (on the calculator), you can use AFiles("mypicture.png"):=G0 to capture the current screen into the file called mypicture.png. I presume you probably have some sort of program that creates the spreadsheet, so you can simply insert the command into your program. You may possibly have to use STARTVIEW to force the view you wish to capture.

If, on the other hand, you manually created a spreadsheet and want a "screenshot" then you can create a small program that basically uses two commands: STARTVIEW and AFiles (the first to switch to the view you want, and the second to capture the screen into a file).

If you do this on your actual calculator, you will then need to connect it to the CK to grab a copy of the mypicture.png file (also true for the virtual calculator). In the CK, open your copied app and it should appear in the Files folder. This is also where you would import your own files from your computer -- Mac or PC -- into the copied app. Just drag the files into the Files folder.

Graph 3D | QPI | SolveSys
11-25-2020, 11:46 PM
Post: #13
 cahlucas Member Posts: 120 Joined: Mar 2016
RE: Keeping graphic objects in programs
(11-25-2020 06:41 PM)Han Wrote:  EDIT: Also, to capture the screen, another simple method is to connect your calculator to the CK and use the Monitor panel to capture the screen. There is a monitor icon on the top right to reveal the Monitor panel. Right click your screen's mini-snapshot and use Save As...

Original message:

Within your copied app (on the calculator), you can use AFiles("mypicture.png"):=G0 to capture the current screen into the file called mypicture.png. I presume you probably have some sort of program that creates the spreadsheet, so you can simply insert the command into your program. You may possibly have to use STARTVIEW to force the view you wish to capture.

If, on the other hand, you manually created a spreadsheet and want a "screenshot" then you can create a small program that basically uses two commands: STARTVIEW and AFiles (the first to switch to the view you want, and the second to capture the screen into a file).

If you do this on your actual calculator, you will then need to connect it to the CK to grab a copy of the mypicture.png file (also true for the virtual calculator). In the CK, open your copied app and it should appear in the Files folder. This is also where you would import your own files from your computer -- Mac or PC -- into the copied app. Just drag the files into the Files folder.
Dear Mr. Han,
Thank you for your explanation. I will start working on this as soon as possible, unfortunately I don't have time for this on Thursday. After that, I will keep you informed of further developments, so I hope you will remain prepared. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
11-30-2020, 10:10 PM
Post: #14
 cahlucas Member Posts: 120 Joined: Mar 2016
RE: Keeping graphic objects in programs
Dear Mr. Han,
I'm still working on it, my app gives some weird responses to the various keystrokes, and I don't know how to get it working properly yet. Please have a little patience before I come up with a definitive answer. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
12-01-2020, 03:41 AM
Post: #15
 Tim Wessman Senior Member Posts: 2,239 Joined: Dec 2013
RE: Keeping graphic objects in programs
(11-30-2020 10:10 PM)cahlucas Wrote:  Dear Mr. Han,
I'm still working on it, my app gives some weird responses to the various keystrokes, and I don't know how to get it working properly yet. Please have a little patience before I come up with a definitive answer. Sincerely, Karel.

Is your application a "repurposed" one of the built in applications where you want a bit of extra functionality? Or is it totally empty thing you want no screens with from the saved application?

You can make a totally empty "app" that just does nothing with any of the normal plot/symb/num keys if you prefer that.

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
12-01-2020, 11:50 PM
Post: #16
 cahlucas Member Posts: 120 Joined: Mar 2016
RE: Keeping graphic objects in programs
(12-01-2020 03:41 AM)Tim Wessman Wrote:  Is your application a "repurposed" one of the built in applications where you want a bit of extra functionality? Or is it totally empty thing you want no screens with from the saved application?

You can make a totally empty "app" that just does nothing with any of the normal plot/symb/num keys if you prefer that.

Dear Mr. Wessman,
I made a copy of the spreadsheet app and disabled the symb/plot/num keys with empty BEGIN/END blocks. I don't need all the screens of the spreadsheet app, because the app I'm going to make have nothing to do with that. I just needed an app to start with, so I chose the spreadsheet. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
12-15-2020, 10:03 PM
Post: #17
 cahlucas Member Posts: 120 Joined: Mar 2016
RE: Keeping graphic objects in programs
(11-25-2020 06:41 PM)Han Wrote:  Also, to capture the screen, another simple method is to connect your calculator to the CK and use the Monitor panel to capture the screen. There is a monitor icon on the top right to reveal the Monitor panel. Right click your screen's mini-snapshot and use Save As...

Original message:

Within your copied app (on the calculator), you can use AFiles("mypicture.png"):=G0 to capture the current screen into the file called mypicture.png. I presume you probably have some sort of program that creates the spreadsheet, so you can simply insert the command into your program. You may possibly have to use STARTVIEW to force the view you wish to capture.

If, on the other hand, you manually created a spreadsheet and want a "screenshot" then you can create a small program that basically uses two commands: STARTVIEW and AFiles (the first to switch to the view you want, and the second to capture the screen into a file).

If you do this on your actual calculator, you will then need to connect it to the CK to grab a copy of the mypicture.png file (also true for the virtual calculator). In the CK, open your copied app and it should appear in the Files folder. This is also where you would import your own files from your computer -- Mac or PC -- into the copied app. Just drag the files into the Files folder.
Dear Mr. Han,
My apologies for the long wait. Unfortunately, both methods don't seem to work. I haven't used STARTVIEW yet because I don't know which number to add to this. The screen capture method in the CK produces a distorted and incomplete image, the method with "AFiles("mypicture.png"):=G0" does nothing at all. Maybe I am doing something wrong, but I am not getting graphics files from my program. I hope you can give me a little more insight so that I can solve this problem. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
12-16-2020, 01:56 AM (This post was last modified: 12-16-2020 01:56 AM by Han.)
Post: #18
 Han Senior Member Posts: 1,842 Joined: Dec 2013
RE: Keeping graphic objects in programs
(12-15-2020 10:03 PM)cahlucas Wrote:  Dear Mr. Han,
My apologies for the long wait. Unfortunately, both methods don't seem to work. I haven't used STARTVIEW yet because I don't know which number to add to this.

Type STARTVIEW in the command line (or in the program editor) and press the Help key to see more information on that command. This works on all commands, actually.

Quote:The screen capture method in the CK produces a distorted and incomplete image

I will have to check again to see if mine produced a 1-to-1 image if there was some sort of distortion. Were you taking a screenshot of a still image? Or was the screen updating while you tried to capture the screen?

Quote:the method with "AFiles("mypicture.png"):=G0" does nothing at all. Maybe I am doing something wrong, but I am not getting graphics files from my program. I hope you can give me a little more insight so that I can solve this problem. Sincerely, Karel.

Did you check the app inside the CK? It should show up there (inside your app). Also, what happens when you type AFiles("mypicture.png") into the command line? Does it produce a miniature picture of your screen capture?

Graph 3D | QPI | SolveSys
12-17-2020, 10:07 PM
Post: #19
 cahlucas Member Posts: 120 Joined: Mar 2016
RE: Keeping graphic objects in programs
(12-16-2020 01:56 AM)Han Wrote:  Type STARTVIEW in the command line (or in the program editor) and press the Help key to see more information on that command. This works on all commands, actually.
I know the numbers and their corresponding screens, but I don't know which one to take. Even though my program is a copy of the spreadsheet app, it produces its own interface to the user that has nothing to do with the original app. That means I probably can't use STARTVIEW.
Quote:Were you taking a screenshot of a still image? Or was the screen updating while you tried to capture the screen?
It was a still screen that I took a capture of. In my program there are no moving screens or parts thereof.
Quote:Did you check the app inside the CK? It should show up there (inside your app). Also, what happens when you type AFiles("mypicture.png") into the command line? Does it produce a miniature picture of your screen capture?
In the CK under files some .png files are listed, but they are just names and apparently not files, because I can't copy them. How do I make usable files from this? If I type AFiles("mypicture.png") in the command line then I get an "Invalid input" error, but with AFiles("mypicture.png"):=G0 I get a thumbnail of the home screen. But this thumbnail is still in my calculator and not on my MAC. And that is why I doubt the use of this. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
12-19-2020, 04:44 PM
Post: #20
 Han Senior Member Posts: 1,842 Joined: Dec 2013
RE: Keeping graphic objects in programs
The CK should have a "Content" pane. Drag your png files from the calculator to the Content area. This is a directory in the computer -- you can find the directory in Edit > Preferences.

Graph 3D | QPI | SolveSys
 « Next Oldest | Next Newest »

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