Author Topic: 32-bit Screen Transient and Persistent Images  (Read 5140 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
32-bit Screen Transient and Persistent Images
« on: September 03, 2018, 05:32:24 am »
With a Screen in 32-bit mode an image is persistent by default.  When the code executes a _PUTIMAGE statement (or other drawing command), that image will stay on the screen until the next CLS occurs.  This means that in a running loop with a _DISPLAY statement but no CLS, if the image position of a particular object moves, a trace of the object forms on on the screen.  As a matter of fact with _HARDWARE images, the opposite happens and no CLS is necessary to 'delete' previous image positions.

Is there a way in 32-bit _SOFTWARE mode to allow some images to be transient (ie only the last position on the object is displayed) whilst others are persistent (default with no CLS in the loop)?  I remember that Walter achieved something along these lines with _HARDWARE images, but I am using InForm which only allows _SOFTWARE images.  I don't believe that this is possible – either you have CLS every loop cycle (all transient images) or no CLS (all persistent), but if there is a way, I'd be glad to know.  Presently, I am creating a transient image in a persistent screen by putting an image with the background colour in the previous position before each transient image is placed.  This works, but also blanks any other image in the same region of the screen.

Richard

FellippeHeitor

  • Guest
Re: 32-bit Screen Transient and Persistent Images
« Reply #1 on: September 03, 2018, 07:59:47 am »
If all your images are hardware images you can make the form surface black and draw straight to it:

The program:
Code: QB64: [Select]
  1. ': This program uses
  2. ': InForm - GUI library for QB64 - Beta version 7
  3. ': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - @fellippeheitor
  4. ': https://github.com/FellippeHeitor/InForm
  5. '-----------------------------------------------------------
  6.  
  7. ': Controls' IDs: ------------------------------------------------------------------
  8. DIM SHARED hardwareImages AS LONG
  9. DIM SHARED ExitBT AS LONG
  10.  
  11. ': External modules: ---------------------------------------------------------------
  12. '$INCLUDE:'InForm\InForm.ui'
  13. '$INCLUDE:'InForm\xp.uitheme'
  14. '$INCLUDE:'hardwareImages.frm'
  15.  
  16. ': Event procedures: ---------------------------------------------------------------
  17. SUB __UI_BeforeInit
  18.  
  19.  
  20. SUB __UI_OnLoad
  21.  
  22.  
  23. SUB __UI_BeforeUpdateDisplay
  24.     'This event occurs at approximately 30 frames per second.
  25.     'You can change the update frequency by calling SetFrameRate DesiredRate%
  26.     STATIC hwImg AS LONG
  27.  
  28.     IF hwImg = 0 THEN
  29.         tempImg = _NEWIMAGE(64, 64, 32)
  30.         _DEST tempImg
  31.         FOR i = 0 TO _PI(2) - .1 STEP .1
  32.             PSET (_WIDTH / 2 + (COS(i) * 32), _HEIGHT / 2 + (SIN(i) * 32)), _RGB32(255 * RND, 255 * RND, 255 * RND)
  33.         NEXT
  34.         _DEST 0
  35.         hwImg = _COPYIMAGE(tempImg, 33)
  36.         _FREEIMAGE tempImg
  37.     END IF
  38.  
  39.     _PUTIMAGE (__UI_MouseLeft - 32, __UI_MouseTop - 32), hwImg
  40.  
  41. SUB __UI_BeforeUnload
  42.     'If you set __UI_UnloadSignal = False here you can
  43.     'cancel the user's request to close.
  44.  
  45.  
  46. SUB __UI_Click (id AS LONG)
  47.     SELECT CASE id
  48.         CASE hardwareImages
  49.  
  50.         CASE ExitBT
  51.             SYSTEM
  52.     END SELECT
  53.  
  54. SUB __UI_MouseEnter (id AS LONG)
  55.     SELECT CASE id
  56.         CASE hardwareImages
  57.  
  58.         CASE ExitBT
  59.  
  60.     END SELECT
  61.  
  62. SUB __UI_MouseLeave (id AS LONG)
  63.     SELECT CASE id
  64.         CASE hardwareImages
  65.  
  66.         CASE ExitBT
  67.  
  68.     END SELECT
  69.  
  70. SUB __UI_FocusIn (id AS LONG)
  71.     SELECT CASE id
  72.         CASE ExitBT
  73.  
  74.     END SELECT
  75.  
  76. SUB __UI_FocusOut (id AS LONG)
  77.     'This event occurs right before a control loses focus.
  78.     'To prevent a control from losing focus, set __UI_KeepFocus = True below.
  79.     SELECT CASE id
  80.         CASE ExitBT
  81.  
  82.     END SELECT
  83.  
  84. SUB __UI_MouseDown (id AS LONG)
  85.     SELECT CASE id
  86.         CASE hardwareImages
  87.  
  88.         CASE ExitBT
  89.  
  90.     END SELECT
  91.  
  92. SUB __UI_MouseUp (id AS LONG)
  93.     SELECT CASE id
  94.         CASE hardwareImages
  95.  
  96.         CASE ExitBT
  97.  
  98.     END SELECT
  99.  
  100. SUB __UI_KeyPress (id AS LONG)
  101.     'When this event is fired, __UI_KeyHit will contain the code of the key hit.
  102.     'You can change it and even cancel it by making it = 0
  103.     SELECT CASE id
  104.         CASE ExitBT
  105.  
  106.     END SELECT
  107.  
  108. SUB __UI_TextChanged (id AS LONG)
  109.     SELECT CASE id
  110.     END SELECT
  111.  
  112. SUB __UI_ValueChanged (id AS LONG)
  113.     SELECT CASE id
  114.     END SELECT
  115.  
  116. SUB __UI_FormResized
  117.  
  118.  

The form (save it as hardwareImages.frm):
Code: QB64: [Select]
  1. ': This form was generated by
  2. ': InForm - GUI library for QB64 - Beta version 7
  3. ': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - @fellippeheitor
  4. ': https://github.com/FellippeHeitor/InForm
  5. '-----------------------------------------------------------
  6. SUB __UI_LoadForm
  7.  
  8.     DIM __UI_NewID AS LONG
  9.  
  10.     __UI_NewID = __UI_NewControl(__UI_Type_Form, "hardwareImages", 300, 300, 0, 0, 0)
  11.     SetCaption __UI_NewID, "hardwareImages"
  12.     Control(__UI_NewID).Stretch = False
  13.     Control(__UI_NewID).Font = SetFont("arial.ttf", 12)
  14.     Control(__UI_NewID).BackColor = _RGB32(0, 0, 0)
  15.  
  16.     __UI_NewID = __UI_NewControl(__UI_Type_Button, "ExitBT", 80, 23, 210, 267, 0)
  17.     SetCaption __UI_NewID, "E&xit"
  18.     Control(__UI_NewID).Stretch = False
  19.     Control(__UI_NewID).CanHaveFocus = True
  20.  
  21.  
  22. SUB __UI_AssignIDs
  23.     hardwareImages = __UI_GetID("hardwareImages")
  24.     ExitBT = __UI_GetID("ExitBT")

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: 32-bit Screen Transient and Persistent Images
« Reply #2 on: September 03, 2018, 08:41:03 am »
PCOPY is the easiest way I know to achieve the effect you're speaking of.

SCREEN _NEWIMAGE(800,600,32)
RANDOMIZE TIMER

'Create the persistent image
FOR I = 1 TO 100
    LINE (RND * 800, RND * 600)-(RND * 800, RND * 600), _RGB32(RND * 255, RND * 255, RND * 255), BF
NEXT

'Now PCOPY that background to preserve it
PCOPY 0,1

'Now create the transient image and display it:
DO
     PCOPY 1,0 'place background (no CLS needed)
     X = X + 1: IF X > 800 THEN X = 0
     LINE (X, 200)-STEP(200,200), _RGB(0,0,0), BF 'a black box for the colored background should show up nice for a transient image
    _LIMIT 30
    _DISPLAY
LOOP UNTIL _KEYHIT
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: 32-bit Screen Transient and Persistent Images
« Reply #3 on: September 03, 2018, 09:35:31 am »
Next method, which use is the LINE command with the BF parameter only across the area I need to overwrite. (the same can be done in the circular or elliptical area of the image, it just wants to prepare such a picture, for example, via CIRCLE and areas that have nothing to overwite just set transparent through CLEARCOLOR or SETALPHA.)

Pcopy is good, is possible saving more than 1 screens, i also use in some programs.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: 32-bit Screen Transient and Persistent Images
« Reply #4 on: September 03, 2018, 10:00:19 am »
Well, Shiver Me Timbers, Mateys!

If what Fellippe suggest works for both _hardware & _software images, then this has probably become another InForm topic.  The last time I discussed writing images in InForm, Fellippe told me that _hardware images wouldn't work in InForm (that's what I tried first).  I was writing to a PictureBox and using Begin/EndDraw.  But the new method puts a  _hardware image straight to the Form (I have checked it out and it works).

I've just tried Fellippe's Form & .bas and not converted the image into _hardware (,33) but left it as _software (,32), and then it doesn't display.  So, I can't do both _hardware & _software?

I'll look into Steve's & Petr's methods.  Next reply I'll attach a video of the effect I'm trying to achieve.

Richard (every day, in every way I get more & more flummoxed).

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: 32-bit Screen Transient and Persistent Images
« Reply #5 on: September 03, 2018, 10:19:08 am »
Attached is a screen capture video of my Gravity Simulation InForm program, with the program in Demonstration mode.  The program calculates all the gravitational interactions between a number of bodies and plots their progress in a perspective view.  In theis case, we are simulating the Solar System.  In the video, we are zoomed into just the sun, mercury and venus.  Their paths are traces so you can see where they have travelled, but then I give a shrinking image (in this case of the sun) which points to a given body.

All images are software.  The normal view for the gravitational progress is a trace, so CLS is not used.  For the shrinking image, I put a blank before the actual image so it does not leave a trace.  The jittery progress of the shrinking image does not happen if screen capturing is not done.

Richard

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: 32-bit Screen Transient and Persistent Images
« Reply #6 on: September 03, 2018, 10:22:48 am »
Another method I use is to simply get the background area I want to preserve with a temporary _PUTIMAGE, then I place the transient image and display it over it.  When finished, I simply _PUTIMAGE the background back.

I'm in town ATM, On my iPad, but when I get home, I'll grab a copy of my TextToImage library and share it for you; it has 2 simple routines in it which'll probably serve your needs:  SaveBackground and RestoreBackground.  Both work with whatever specific region which you set.

SavedHandle= SaveBackground (100,100,200,200) 'saves from (100,100)-(200,200)
'Do stuff (like a pop up)
RestoreBackground SavedHandle 'restore that background when finished
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: 32-bit Screen Transient and Persistent Images
« Reply #7 on: September 03, 2018, 10:26:26 am »
I've just tried Fellippe's Form & .bas and not converted the image into _hardware (,33) but left it as _software (,32), and then it doesn't display.  So, I can't do both _hardware & _software?

Maybe BeginDraw __UI_FormID will allow software drawing to the form surface. Didn't test it though.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: 32-bit Screen Transient and Persistent Images
« Reply #8 on: September 03, 2018, 10:28:51 am »
I've just tried Fellippe's Form & .bas and not converted the image into _hardware (,33) but left it as _software (,32), and then it doesn't display.  So, I can't do both _hardware & _software?

Maybe BeginDraw __UI_FormID will allow software drawing to the form surface. Didn't test it though.

May need to check _DISPLAYORDER as well.  (If that's the name of the command; I'm winging it from memory here.)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: 32-bit Screen Transient and Persistent Images
« Reply #9 on: September 03, 2018, 10:38:02 am »
Can't change _DISPLAYORDER with InForm.

FellippeHeitor

  • Guest
Re: 32-bit Screen Transient and Persistent Images
« Reply #10 on: September 03, 2018, 10:43:38 am »
Maybe BeginDraw __UI_FormID will allow software drawing to the form surface. Didn't test it though.

Ok, just tested it now and realized I'd made sure BeginDraw/EndDraw would only work with PictureBox controls. Here's a hack/workaround. Replace this sub in the example I gave you above:

Code: QB64: [Select]
  1. SUB __UI_BeforeUpdateDisplay
  2.     'This event occurs at approximately 30 frames per second.
  3.     'You can change the update frequency by calling SetFrameRate DesiredRate%
  4.     STATIC hwImg AS LONG, sfImg AS LONG
  5.  
  6.     IF hwImg = 0 THEN
  7.         sfImg = _NEWIMAGE(64, 64, 32)
  8.         _DEST sfImg
  9.         FOR i = 0 TO _PI(2) - .1 STEP .1
  10.             PSET (_WIDTH / 2 + (COS(i) * 32), _HEIGHT / 2 + (SIN(i) * 32)), _RGB32(255 * RND, 255 * RND, 255 * RND)
  11.         NEXT
  12.         _DEST 0
  13.         hwImg = _COPYIMAGE(sfImg, 33)
  14.     END IF
  15.  
  16.     _PUTIMAGE (__UI_MouseLeft - 32, __UI_MouseTop - 32), hwImg
  17.  
  18.     _DEST Control(__UI_FormID).Canvas
  19.     _PUTIMAGE (0, 0), sfImg
  20.     _DEST 0

That'll place a software colorful circle at 0, 0 and have a hardware colorful circle following the mouse.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: 32-bit Screen Transient and Persistent Images
« Reply #11 on: September 18, 2018, 04:49:33 am »
If all your images are hardware images you can make the form surface black and draw straight to it:

@Fellippe:  For my next project, in which I'm using all hardware images, I've just tried the "Draw Straight to the Form" method, and it works Right Out of the Box.  Brilliant!
[If you've time, you might move this topic into the InForm Section].
Richard