Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hardware / Software Any better way to achieve this?
#1
Working in Screen 0 with displaying hardware images under or over software images.

This is what works for me, but in case I'm missing a better method, I'd thought I'd ask before committing this method for future applications.

Code: (Select All)
_Title "Hardware Image Under and Over Demo"
Dim As Long t, HardwarePage ' This TYPE is per wiki but default single works just as well. Go figure.
Screen 0 ' Active display screen.
Palette 7, 63 ' Increases the color white intensity to maximum.
Cls , 7 ' Make a white screen.
Color 1, 7: Locate 2, 1: Print " We want to keep a white screen for this demo. Press any key...": Sleep: _KeyClear
t = _NewImage(_Width * _FontWidth, _Height * _FontHeight, 32) ' Creation screen.
_Dest t ' Make creation screen the active, but hidden (not the display) screen.
Cls , _RGB(255, 255, 255) ' Make the creation screen bright white.
HardwarePage = _CopyImage(t, 33) ' Hardware screen layer #1 to create a white background.
_FreeImage t ' Free the creation screen from memory.
t = _NewImage(150, 150, 32) ' Creation screen of our hardware image 150 x 150 BLOCK.
_Dest t ' Yes, we need to do this again, becaue we opened a  new screen.
Line (0, 0)-(150, 150), _RGB32(0, 0, 150), BF ' This solid blue BLOCK will become our Hardware image.
block = _CopyImage(t, 33) ' Copy our blue BLOCK to hardware memory.
_FreeImage t ' Free the creation screen from memory.
_Dest 0 ' Get back to the displayscreen.
_DisplayOrder _Hardware , _Software ' Place hardware layer under software layer.
DisplayOrder$ = "HardwareUnderSoftware" ' Assign this array to keep track of display order switching.
_PaletteColor 5, _RGB32(255, 255, 255, 0) ' Assigns color 5 as transparent white, which appears 'black' without an underlay added, software screen.
Cls , 5 ' Apply transparent 'black' screen to software layer.
Color 14, 4: a$ = " Software Banner to Display Over and Under Hardware Block ": Locate 12, 13: Print a$ ' Place software image on transparent page.
'---------------------------------------------------------------------------------------------------------------------------------------------------
Color 7, 0: Locate 2, 1: Print " Notice the screen is now black."
Print " Don't worry, we will get our white screen back in a flash!"
Print " Press a key to continue then press keys to toggle the display order...": Sleep: _KeyClear: Locate 2, 1: Color 0, 5: Print Space$(_Width * 3)
'---------------------------------------------------------------------------------------------------------------------------------------------------
Do
    _Limit 30
    b$ = InKey$
    If Len(b$) Then
        switch` = Not switch` 'This _bit variable is flipped when a key is pressed.
        If switch` And DisplayOrder$ = "HardwareUnderSoftware" Then _DisplayOrder _Software , _Hardware: DisplayOrder$ = "HardwareOverSoftware"
        If switch` = 0 And DisplayOrder$ = "HardwareOverSoftware" Then _DisplayOrder _Hardware , _Software: DisplayOrder$ = "HardwareUnderSoftware"
        If b$ = Chr$(27) Then System ' End routine and close program window.
    End If
    If DisplayOrder$ = "HardwareUnderSoftware" Then _PutImage (0, 0), HardwarePage ' Our hardware BLOCK will now be displayed on this white surface.
    _PutImage (250, 110), block ' Sends our blue BLOCK to the screen.
    _Display
Loop

Now if we make the software image(s) first, instead of after changing the display order, no problemo. We just copy that screen as follows...

Code: (Select All)
_Title "Hardware Image Under and Over Demo 2"
Dim As Long t, HardwarePage ' This TYPE is per wiki but default single works just as well. Go figure.
Screen 0 ' Active display screen.
_PaletteColor 5, _RGB32(255, 255, 255, 0) ' Assigns color 5 as transparent white, which appears 'black' without an underlay added, software screen.
Cls , 5 ' Make a transparent background for our software image.
Color 14, 4: a$ = " Software Banner to Display Over and Under Hardware Block ": Locate 12, 13: Print a$ ' Place software image on transparent page.
s& = _CopyImage(0) ' Copy the software image.
t = _NewImage(_Width * _FontWidth, _Height * _FontHeight, 32) ' Creation screen.
_Dest t ' Make creation screen the active, but hidden (not the display) screen.
Cls , _RGB(255, 255, 255) ' Make the creation screen bright white.
HardwarePage = _CopyImage(t, 33) ' Hardware screen layer #1 to create a white background.
_FreeImage t ' Free the creation screen from memory.
t = _NewImage(150, 150, 32) ' Creation screen of our hardware image 150 x 150 BLOCK.
_Dest t ' Yes, we need to do this again, becaue we opened a  new screen.
Line (0, 0)-(150, 150), _RGB32(0, 0, 150), BF ' This solid blue BLOCK will become our Hardware image.
block = _CopyImage(t, 33) ' Copy our blue BLOCK to hardware memory.
_FreeImage t ' Free the creation screen from memory.
_Dest 0 ' Get back to the displayscreen.
_DisplayOrder _Hardware , _Software ' Place hardware layer under software layer.
DisplayOrder$ = "HardwareUnderSoftware" ' Assign this array to keep track of display order switching.
PCopy s&, 0 ' Send the copied software image to the display screen.
Do
    _Limit 30
    b$ = InKey$
    If Len(b$) Then
        switch` = Not switch` 'This _bit variable is flipped when a key is pressed.
        If switch` And DisplayOrder$ = "HardwareUnderSoftware" Then _DisplayOrder _Software , _Hardware: DisplayOrder$ = "HardwareOverSoftware"
        If switch` = 0 And DisplayOrder$ = "HardwareOverSoftware" Then _DisplayOrder _Hardware , _Software: DisplayOrder$ = "HardwareUnderSoftware"
        If b$ = Chr$(27) Then System ' End routine and close program window.
    End If
    If DisplayOrder$ = "HardwareUnderSoftware" Then _PutImage (0, 0), HardwarePage ' Our hardware BLOCK will now be displayed on this white surface.
    _PutImage (250, 110), block ' Sends our blue BLOCK to the screen.
    _Display
Loop

Now maybe there's a better approach (way) to do this, as well.

Pete

PS: A BIG THANKS to Steve. I was on my tablet, on top of the Empire State building, trying to sort all of this out in a 1,500 line program. Steve talked me down! Big Grin
Reply
#2
And...  I'll always regret it.   /sigh
Reply
#3
Well, if I jumped, no worries. I was wearing a parachute designed by Clippy. Oh wait, when you pull the cord, it doesn't fully open. Instead, it forms the shape of a BIG ASCII exclamation mark!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Pete  Big Grin
Reply




Users browsing this thread: 1 Guest(s)