Syntax for Method Pixmap Paste(source:TPixmap,x,y)

BlitzMax Forums/BlitzMax Programming/Syntax for Method Pixmap Paste(source:TPixmap,x,y)

Ian Martin(Posted 2014) [#1]
I see lots of references to it in posts, but no examples of the syntax used to make this happen. I have stored a pixmap like this:
UndoPixmap:TPixmap=CopyPixmap:TPixmap( EditingPixmap:TPixmap )


...and then I'm trying to paste it back on the pixmap later, basically like an Undo function. Here are several tries that do not work:

'paste the old version on the pixmap
EditingPixmap:TPixmap=pixmap.paste( UndoPixmap:TPixmap, 0, 0 )
EditingPixmap:TPixmap.paste=( UndoPixmap:TPixmap )			
EditingPixmap.paste:TPixmap=( UndoPixmap:TPixmap )		
EditingPixmap:TPixmap=TPixmap.paste( UndoPixmap:TPixmap, 0, 0 )

All of these cause an error and won't compile.
I'm not seeing the syntax in any of the posts and don't really understand how to use this method of the pixmap class...not very good with methods at all yet since I've never used them...so maybe it's a total noob question...but it doesn't seem like the docs explain this.
Someone said it was pixmap.paste which I get is a method of the pixmap somehow...but what are the X and Y values? Is that where in the pixmap to paste it to?
Can anyone explain the syntax of this command or post some code of pasting a pixmap onto another pixmap?
Any help appreciated!


TomToad(Posted 2014) [#2]
CopyPixmap() will make an exact copy of a pixmap and assign it to another pixmap. If you want to copy back, just reverse the parameters.
EditingPixmap = CopyPixmap(UndoPixmap)

BTW, you don't need to continue adding :TPixmap after the variable is declared.

Paste is used to paste a smaller pixmap onto a larger one.

In BlitzMAX, you sometimes have two ways to call a method for an object. You can use the OOP way Object.Method(Parameters) or a more conventional function call Function(Object,paramters). So a call such as UndoPixmap = CopyPixmap(EditingPixmap) can be written as UndoPixmap = EditingPixmap.Copy() Not all functions have OOP versions, and not all OOP calls have functions. Paste is one which doesn't have a function and needs to be called the OOP way.


Jur(Posted 2014) [#3]
methods are used in this way:
EditingPixmap.paste( UndoPixmap, 0, 0 )

yes, x,y are coordinates of the upper left corner of the pasted pixmap


Henri(Posted 2014) [#4]
Hello,

sense I already wrote this, might as well paste it here for variation:
SuperStrict

'Load some test png/jpeg
Local src_pix:TPixmap = LoadPixmap("C:\test.png")	' <--change path for your test image

'Copy the original pixmap
Local dst_pix:TPixmap = CopyPixmap(src_pix)

'Draw something to source pixmap
For Local i:Int=0 Until src_pix.width
	WritePixel(src_pix,i,i,Int(Rnd(0,1000000)))
Next

'Paste original pixmap back
'src_pix.paste(dst_pix,0,0)	' <---uncomment this line to use undo

Graphics 640,480,0

Repeat
	Cls
	DrawPixmap(src_pix,MouseX(),MouseY())
	Flip
Until KeyHit(key_escape)


-Henri


Ian Martin(Posted 2014) [#5]
Thanks TomToad! I got some time to try it out today and I was able to get it working using code like you suggested. I ran your example code and it explained everything. Hopefully it will help some other people who are having the same problem too! :)

I'm not very good with the OOP stuff yet...I need to learn more.

Also thanks to Jur! I was stumped on the syntax for this.

Thanks to Henri too! That does the job too. It's always good to have more than one way to do something or more than one example to look at :)

I've got an undo function working in my code now...so all I have to do now is save a version every time something is changed and I can have a multi-layered undo system :D