Announcement

Collapse
No announcement yet.

Graphic Undo/redo

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Graphic Undo/redo

    I am missing the GRAPHIC UNDO and GRAPHIC REDO statements
    I am sure we can implement it with a workaround. Has anybody done that?

    Thanks,

    Peter Redei

    #2
    Graphic Set Mix ?

    For certain purposes Graphic Set Mix may do the job.
    It is especially useful for moving selectboxes or crosshairs over the screen.

    Arie Verheul


    Code:
       
    [FONT="Courier New"][SIZE="3"]#Dim All
       
    Function PBMain
        
        Local hWnd As Dword
        
        Graphic Window "",200,200,200,200 To hWnd
        Graphic Attach hWnd,0
        Graphic Color %white,%black
        Graphic Clear
        
        Graphic Box (80,80)-(120,120)
        
        Sleep 2000
       
        Graphic Set Mix %mix_xorsrc
        
        Graphic Box (50,50)-(150,150),20,%blue,%red
        
        Sleep 2000
        
        Graphic Box (50,50)-(150,150),20,%blue,%red
        
        Sleep 2000    
        
    End Function[/SIZE][/FONT]

    Comment


      #3
      Thanks Arie. Using mix can indeed result in a variety of effects, but I cannot see how it can be used for undo/redo. My first choice for undo/redo would be using GRAPHIC GET BITS TO sPrior to save the image to sPrior string and on Undo using GRAPHIC SET BITS sPrior followed with GRAPHIC REDRAW. This is actually working nicely.


      Peter Redei

      Comment


        #4
        Never did it, but you can implement a kind of "layer" technology

        You need to save the portion of window with graphics before any graphics
        operations. It is possible by saving them to BMP in temp folder and restoring when needed.Here is a pseudocode
        Code:
           '.. in your application
           ' this is our procedure to save a portion/window etc.. 
           ' before any graphical operation  
           PSAVE_UNDO (grHwn, UndoPageCounter)  
           GRAPHIC LINE ...
           GRAPHIC PRINT ... 
           ..etc
           ' now save for redo
           PSAVE_REDO (grHwn, RedoPageCounter)  ' save after graphics operations
           INCR UndoPageCounter: MAXUNDO = UndoPageCounter
           INCR RedoPageCounter: MAXREDO = RedoPageCounter
           ..
           ..
           '------------------
           ' UNDO action
           '------------------
           DECR UndoPageCounter
           DECR RedoPageCounter
           IF UndoPageCounter <=1 THEN UndoPageCounter = 1
           IF RedoPageCounter <=1 THEN RedoPageCounter = 1
               PLOAD_UNDO (gwHwn, UndoPageCounter)
           ..
           ..
           '------------------ 
           ' REDO action
           '------------------
           INCR UndoPageCounter
           INCR RedoPageCounter
           IF UndoPageCounter >= MAXUNDO THEN UndoPageCounter >= MAXUNDO
           IF RedoPageCounter >= MAXREDO THEN RedoPageCounter >= MAXREDO
               PLOAD_REDO (gwHwn, RedoPageCounter)
        
        
         SUB PSAVE_REDO (gwHwn, c)
            GRAPHIC ATTACH gwHwn
            GRAPHIC SAVE "redo" & LTRIM$(STR$(c)) & ".bmp"
         ....
         SUB PSAVE_UNDO (gwHwn, c)
            GRAPHIC ATTACH gwHwn
            GRAPHIC SAVE "undo" & LTRIM$(STR$(c)) & ".bmp"
         ....
         SUB PLOAD_UNDO (gwHwn, c)
            GRAPHIC ATTACH gwHwn
            GRAPHIC BITMAP LOAD  "undo" & LTRIM$(STR$(c)) & ".bmp" ....
         ....
         SUB PLOAD_REDO (gwHwn, c)
            GRAPHIC ATTACH gwHwn
             GRAPHIC BITMAP LOAD "redo" & LTRIM$(STR$(c)) & ".bmp"
        ghHwn - is the handle of graphics window you want to undo/redo

        Not tested - but this should work
        Also, you need to define the number and type of graphical operations to be stored as a one layer.

        Comment


          #5
          Thanks Aslan. You are right in creating layers. You do not need to save bitmaps though, GRAPHIC GET/SET BITS offers better option. Here is a pseudo version:

          Code:
          GLOBAL sGraphic_Undo() AS STRING
          GLOBAL sGraphic_Redo() AS STRING    
          function PBMAIN()
               ClearLayers
               'whenever the cancas changes call SaveGRAPHIC
               'call UndoGRAPHIC to restore the prior canvas
               'call RedoGRAPHIC to redo after undo
          end function
          SUB AddLayer(BYVAL sLayer AS STRING)
          
              ARRAY INSERT sGraphic_Undo(0), sLayer
          
          END SUB
          SUB UndoGRAPHIC()
              LOCAL sPrior AS STRING
              IF LEN(sGraphic_Undo(0)) THEN
                  GRAPHIC GET BITS TO sPrior
                  ARRAY INSERT sGraphic_Redo(0), sPrior
                  GRAPHIC SET BITS sGraphic_Undo(0)
                  GRAPHIC REDRAW
                  ARRAY DELETE sGraphic_Undo(0)
              ELSE
                  REDIM sGraphic_Undo(0 TO 11)
              END IF
              
          END SUB
          
          SUB RedoGRAPHIC()
              LOCAL sPrior AS STRING
              IF LEN(sGraphic_Redo(0)) THEN
                  SaveGRAPHIC
                  GRAPHIC SET BITS sGraphic_Redo(0)
                  GRAPHIC REDRAW
                  ARRAY DELETE sGraphic_Redo(0)
               ELSE
                  REDIM sGraphic_Redo(0 TO 11)
              END IF
          END SUB
          
          SUB ClearLayers()
              REDIM sGraphic_Undo(0 TO 11)
              REDIM sGraphic_Redo(0 TO 11)
          END SUB
          SUB SaveGRAPHIC()
              LOCAL sPrior AS STRING
              GRAPHIC GET BITS TO sPrior:AddLayer sPrior
          END SUB
          Thanks,


          Peter Redei
          Last edited by Peter Redei; 20 Jan 2009, 11:33 PM.

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎