You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
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.
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.
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.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment