Page 1 of 1
painting to a DC
Posted: Wed Dec 03, 2003 6:52 pm
by Codemonger
Any ideas of how to paint to a DC using the Purebasic 2D Drawing Commands. The reason why I ask, is I got user defined buttons working good, but I don't want to use win32 API - GDI for handling drawing the buttons... I would prefer to use the PB internal commands, much easier. Any ideas or thoughts on this.
Posted: Sun Dec 07, 2003 10:12 pm
by einander
Codemonger:
As nobody answers you, may be this helps. Sorry, with some API

but also ImageGadtet()
Code: Select all
;Paint to a DC mixing API and PB commands, allowing some interesting modes (as #NOTSRCCOPY, #PATPAINT, etc.) with ImageGadget().
#IMG0=0
#IMG1=1
hWnd=OpenWindow(0, x,y,600,400, #WS_OVERLAPPEDWINDOW | #PB_Window_WindowCentered, "NotSrcCopy")
hDC = GetDC_(hWnd)
hIMG0 = LoadImage(#IMG0, "********your SMALL BMP here*********")
WI = ImageWidth() : HE = ImageHeight()
hIMG1 = CreateImage(#IMG1, WI, HE) ; For BITBLT
Src_DC = CreateCompatibleDC_(hDC)
SelectObject_(Src_DC, hIMG0)
Dest_DC = CreateCompatibleDC_(hDC)
SelectObject_(Dest_DC, hIMG1)
BitBlt_(Dest_DC, 0, 0, WI, HE, Src_DC, 0, 0, #notsrccopy)
DeleteDC_(Src_DC)
DeleteDC_(Dest_DC)
CreateGadgetList(hWnd)
StartDrawing(WindowOutput())
ImageGadget(#IMG1, 300, WindowHeight()-200, 0, 0, 0) ; x, y Position
SetGadgetState(#IMG1, UseImage(#IMG1)) ; For BITBLIT
ImageGadget(#IMG0, 300, 10, 0, 0, 0) ; x, y Posistion
SetGadgetState(#IMG0, UseImage(#IMG0)) ; ORIGINAL Image
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End
Regards
Einander
Posted: Mon Dec 08, 2003 5:59 pm
by Codemonger
Thanks Einander, your code wasn't exactly what I was looking for but it gave me some great ideas ... API is ok, I was just hoping I could draw to a user defined button with the PB draw commands, they are so much easier. But your code might provide me with a solution. Thanks

Posted: Mon Dec 08, 2003 6:47 pm
by Fred
In fact, you can take a look to the LibrarySDK help file, you should have the structure of PB 2DrawingInfo DC. It's still a bit obscure, I will try to write a little example to do what you want.
Posted: Mon Dec 08, 2003 7:38 pm
by einander
Codemonger:
Just playing with the above code, and there is a procedure to take some advantage of it.
Code: Select all
Enumeration
#SRC1
#SRC2
#SRC3
#SRC4
#Blit1
#Blit2
#Blit3
#Blit4
EndEnumeration
Procedure Blit_Image(SRC,Dest,Style)
Orig=UseImage(SRC)
WI=ImageWidth() : He=ImageHeight()
Dest = CreateImage(Dest, wi,he) ; IMAGE PARA BITBLT
Src_DC = CreateCompatibleDC_(0)
SelectObject_(Src_DC, orig)
Dest_DC = CreateCompatibleDC_(0)
SelectObject_(Dest_DC, Dest)
BitBlt_(Dest_DC, 0, 0, WI, HE, Src_DC, 0, 0, Style)
DeleteDC_(Src_DC)
DeleteDC_(Dest_DC)
ProcedureReturn IMG
EndProcedure
Procedure Put(IMG,x,y)
FreeGadget(IMG)
ImageGadget(IMG, x,y, 0, 0, UseImage(img)) ; posic x, y
EndProcedure
OpenWindow(22, x,y,600,400, #WS_OVERLAPPEDWINDOW | #PB_Window_WindowCentered, "Titulo")
CreateImage(#SRC1,WindowWidth()-40,WindowHeight()-40)
StartDrawing(ImageOutput())
Box(0,0,ImageWidth(),ImageHeight(),#blue)
StopDrawing()
CreateGadgetList(WindowID())
;========================
;Original image
LoadImage(#SRC2, "******** Your Bitmap Here ")
;========================
StartDrawing(WindowOutput())
Blit_Image(#SRC2,#BLIT1,#mergepaint) ; First param= Source Image ID, Second param = Destination Image ID for new Blit_Image
Blit_Image(#SRC2,#BLIT2,#mergecopy) ; First param= Source Image ID, Second param = Destination Image ID for new Blit_Image
blit_image(#SRC1,#BLIT3,#srcinvert)
put(#BLIT1,200,120) ; First param = Desired Image_ID
Put(#BLIT2,200,10) ; First param = Desired Image_ID
put(#BLIT3,20,20)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End
Regards
Einander
Posted: Mon Dec 08, 2003 10:07 pm
by Codemonger
Thanks Fred, already had a look at the LibrarySDK help file, it's pretty self explanatory. It's just me wrapping my head around the whole thing as WinAPI is not my thing. If I could change the DC of lets say the 2ddraing structure to the user defined button, could I then use PB drawing commands on the user defined button.
This would be great because I would like to skin my app, and have full access to the button events ...
Anyway Einander I'll have a look at your code when I get home tonight, at work right now. Gotta go!