Results 1 to 5 of 5

Thread: SetSourceSurface. Having your cake and beating it... to death.

  1. #1

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    SetSourceSurface. Having your cake and beating it... to death.

    Hi all,
    YAOQ, Yet Another Olaf Question.

    As ThIs SiTe WoN't LeT mE aTtAcH aNy FiLeS to posts anymore, for whatever reason, I've put the thing over to Dropbox.

    I'm trying to see if I can use the SetSourceSurface property.

    Instead of copying a surface, I am wondering if I can use it's reference instead?

    I was trying to push the number panels along when clicked, Ie: Spot 3 becomes Image 2, and cycle them over and over.

    https://www.dropbox.com/s/inlau65pk5...gTest.zip?dl=0

    I was wondering if I can use the flowerpot surface method and move entire miniature drawn surface tiles with full data onto another surface, by way of reference (or cache) instead of copying. For speed.

    The articles I've read suggest a pattern, but I can't get the thing to work. Plus the documentation is a headache in C with no examples.

    Thanks for helps!
    Last edited by -Corso->; Mar 20th, 2023 at 03:20 AM.

  2. #2
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,452

    Re: SetSourceSurface. Having your cake and beating it... to death.

    I found this re: cairo_set_source_surface():

    Code:
    This is a convenience function for creating a pattern from surface and setting it as the source in cr with cairo_set_source().
    Patterns are used for things like "textured" fills and strokes, so I don't think this is the method you are looking for to change a cCairoSurface variable reference to another cCairoSurface. You can instead just assign the reference directly (e.g. Set Third_Surface = Second_Surface).

    PS: I looked at your example code and it's a bit confusing that your *_Surface named variables are actually declared as cCairoContext types. I think it would be better to have separate variables for the Surfaces and Contexts (e.g. Master_Surface as cCairoSurface, Master_Context as cCairoContext, etc...).
    Last edited by jpbro; Mar 20th, 2023 at 11:29 AM.

  3. #3
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,452

    Re: SetSourceSurface. Having your cake and beating it... to death.

    Here's an example that will swap surfaces & contexts of a clicked PictureBox with the PB to the left (or wrap around to the far-right PB when the far-left PB is clicked):

    Code:
    Option Explicit
    
    Private ma_Surfaces() As cCairoSurface
    Private ma_Contexts() As cCairoContext
    
    Private Sub Form_Load()
       Dim ii As Long
       
       ' Dimension our Surface and Context arrays to match the number of PictureBoxes on the form
       ReDim ma_Surfaces(1 To Form1.Pic.Count)
       ReDim ma_Contexts(LBound(ma_Surfaces) To UBound(ma_Surfaces))
       
       For ii = LBound(ma_Surfaces) To UBound(ma_Surfaces)
          ' Load the appropriate image into the global imagelist
          Cairo.ImageList.AddIconFromFile "Plate " & ii, App.Path & "\Sur" & ii & ".png"
          
          'Create the surfaces and contexts
          Set ma_Surfaces(ii) = Cairo.CreateSurface(100, 100, ImageSurface)
          Set ma_Contexts(ii) = ma_Surfaces(ii).CreateContext
          
          ' Render the appropriate imagelist image into the context
          ma_Contexts(ii).RenderSurfaceContent Cairo.ImageList.Item("Plate " & ii), 0, 0, , , CAIRO_FILTER_BEST
          
          ' Draw the surface in the appropriate PictureBox
          ma_Surfaces(ii).DrawToDC Form1.Pic(ii).hDC
       Next ii
       
    End Sub
    
    Private Sub Pic_Click(Index As Integer)
       Dim lo_TmpSurface As cCairoSurface
       Dim lo_TmpContext As cCairoContext
       Dim l_SwapIndex As Long
       
       ' Get the Index to swap with (1 to the left of the clicked PictureBox or the far-right PB in case the left-most PB is clicked)
       l_SwapIndex = Index - 1
       If l_SwapIndex < 1 Then l_SwapIndex = Form1.Pic.Count
       
       ' Get the Surface & Context at the clicked index
       Set lo_TmpSurface = ma_Surfaces(Index)
       Set lo_TmpContext = ma_Contexts(Index)
       
       ' Swap the surfaces & contexts
       Set ma_Surfaces(Index) = ma_Surfaces(l_SwapIndex)
       Set ma_Surfaces(l_SwapIndex) = lo_TmpSurface
       Set ma_Contexts(Index) = ma_Contexts(l_SwapIndex)
       Set ma_Contexts(l_SwapIndex) = lo_TmpContext
       
       ' Draw the swapped surfaces
       ma_Surfaces(Index).DrawToDC Form1.Pic(Index).hDC
       ma_Surfaces(l_SwapIndex).DrawToDC Form1.Pic(l_SwapIndex).hDC
       
       ' Refresh the updated PictureBoxes
       Form1.Pic(Index).Refresh  ' Refresh the PictureBox, not the Form
       Form1.Pic(l_SwapIndex).Refresh  ' Refresh the PictureBox, not the Form
    End Sub

  4. #4

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: SetSourceSurface. Having your cake and beating it... to death.

    Quote Originally Posted by jpbro View Post
    PS: I looked at your example code and it's a bit confusing that your *_Surface named variables are actually declared as cCairoContext types.
    I had no idea, I was assuming CairoContext were surfaces with more applicable functions attached.??
    It's how I've done eVeRyThInG. I must have read the VB6Cairo book upside down. *COUGH!*

    Quote Originally Posted by jpbro View Post
    Set Third_Surface = Second_Surface
    It looks pretty, but what does it do? It does nothing for me. Is there some extra function required to make it copy.

    Ah, in your example, you've just used index swapping. Ok, that seems like a good idea. Thouh I'll have to think pretty majestically for doing that with a trimetric game grid with 8 movement directions. I'll have to ponder this.

  5. #5

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: SetSourceSurface. Having your cake and beating it... to death.

    Just updating, tried the shifting indexes to fixed cached surfaces on a 15x15 grid. Horrible horrible code, it's not a pretty system at all. Anyway, screen updates were 30ms, without shadows and without sun effects. So it's a bust.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width