Graphic cursor problem
|
01-09-2021, 09:20 PM
Post: #1
|
|||
|
|||
Graphic cursor problem
Hi all,
[/code]Currently I am making a graphics program (app) where a cursor in the shape of a black square is projected on one of the squares on the screen, such that the character in the square is visible in reverse video. With one touch on the screen, the cursor can be moved to another square of your choice. When the program starts, the cursor is placed on the first square. So the idea is that you can move the cursor to any other square on the screen, with a touch on the screen. Unfortunately it goes wrong there, if the screen is touched, the cursor is not moved, but you will see the screen of the app from which the program is derived. Some explanation about the program is in order: All variables that appear in this program are all declared at the beginning of this program, but that declaration is not visible in the code presented here. The variables cx and cy contain the coordinates where the screen was touched. The content of variable 'cursor' determines whether the cursor is visible or not, and is initially 1. List L9 contains characters, and list L0 contains numbers and sometimes characters. G2 contains a .PNG file that is copied to G0, and on which some characters are projected on places predetermined by coordinates. The variable 'tcrd' contains coordinates for letters, and the variable 'mcrd' for numbers and sometimes letters. If possible, the touches on the screen are converted to an index, which then takes the correct coordinates from list 'mcrd' and has to place the cursor in the right place on the screen. Since the characters are placed in the center of a square as much as possible, the cursor needs some math to get it in the right place. Based on the code, what could possibly be wrong or what needs to be inserted in order for the program to work in the end? Sincerely, Karel. Code:
I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2. |
|||
01-10-2021, 09:45 PM
(This post was last modified: 01-10-2021 09:46 PM by Han.)
Post: #2
|
|||
|
|||
RE: Graphic cursor problem
Insert a DEBUG command right before the last IF-THEN-END block. This will allow you to enter your program in debug mode and examine the contents of the variables. This is the easiest way to track down bugs in a program.
Code: DEBUG; // <--- insert this command here Graph 3D | QPI | SolveSys |
|||
01-12-2021, 05:39 AM
Post: #3
|
|||
|
|||
RE: Graphic cursor problem
Dear Mr. Han,
During debugging, the program works properly. So it must be something else that the original image of the underlying app appears. The question now is what needs to be changed to ensure that this does not happen again. I could use some help with this, because there are a lot more people in this community who have a lot more experience programming the Prime, including you. Therefore, I would like to see suggestions on how to address this problem. Thanks in advance! Sincerely, Karel. I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2. |
|||
01-12-2021, 12:13 PM
(This post was last modified: 01-12-2021 12:17 PM by C.Ret.)
Post: #4
|
|||
|
|||
RE: Graphic cursor problem
(01-09-2021 09:20 PM)cahlucas Wrote: [...] Based on the code, what could possibly be wrong or what needs to be inserted in order for the program to work in the end? Sincerely, Karel. I am not sure, but I see a potential problem in the way index is initialized. To ease my explanation, I copy your code simplifying the tests which appear to be correct. Code:
The variable index is correctly set only when the user touch’s in one of the four Touch-Zone as expected, respectively 1 2 3 or 4 depending of the zone. But, what happen to index when the user miss any of the four zones ? I can not see where the variable index is set to a specific value (I may propose set to 0) to indicate a wrong touch ! And, more important, in the last portion of the code, no test is made to verify that index is correctly set and one of the four Touch Zone was actually touched : Code:
I hope this observation help a bit... Debugging on the HP Prime is sometime really hard, a source of stress and time consuming... (I just spend two hours realizing that the incorrect behavior of my CAS function was due to a capitalized local variable name, the calculator was using the global variable same value each time what ever were the specific samples I introduce ... How fool are we on ours doggy horses ?? ) Best Regards. C.Ret |
|||
01-13-2021, 02:27 AM
Post: #5
|
|||
|
|||
RE: Graphic cursor problem
(01-12-2021 05:39 AM)cahlucas Wrote: Dear Mr. Han, A likely reason why it seems to work during debugging is that (perhaps) you are not accounting for "mouse-up" events. So when a "mouse-down" even occurs (i.e. your finger touches the screen) and the code follows into DEBUG mode, everything looks fine. But the DEBUG mode probably gets in the way of the "mouse-up" event (when you lift your finger from the screen). So the cursor is indeed being drawn correctly at the precise moment you touch the screen, but perhaps your code is not accounting for what happens when your finger lifts up from the screen. But without the code in its entirety (at least without the mouse/keyboard handling portion), it's hard to say precisely what the cause is. A generic mouse/keyboard handler would look something like: Code: EXPORT KMINPUT() Graph 3D | QPI | SolveSys |
|||
01-13-2021, 05:52 AM
Post: #6
|
|||
|
|||
RE: Graphic cursor problem
Dear Mr. Han,
I hereby add the part of the mouse code as it is at the moment, so that you can see what possibly needs to be corrected. All variables used are declared at the beginning of the program, but this part is not included in this code snippet. I hope this helps you to solve this problem. Sincerely, Karel. Code:
I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)