I'm being thick today!

Just starting out? Need help? Post your questions and find answers here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Here's what I was trying to do, but was hoping to avoid the api in this case.

Drag and drop which avoids the problematic ImageList_ dragging functions which seem not to work properly on many setups.

Code: Select all

;Drag and drop the contents of gadgets. 
;This can be changed to accommodate just about any kind of gadget. 

;By Stephen Rodriguez. 
;Purebasic 4 beta 11. Tested on Win XP only. 


#text1=1 
#text2=2 
#text3=3 

dragfrom=-1
x=-1:y=-1
rc.rect


If OpenWindow(0, 0, 0, 600, 300,"Drag and drop between gadgets.", #PB_Window_ScreenCentered|#PB_Window_SystemMenu) 

  If CreateGadgetList(WindowID(0)) 
    TextGadget(#text1,25,20,180,20, "Drag between any of these gadgets") 
    StringGadget(#text2,25,50,180,20, "Drop on to any of these gadgets") 
    ListViewGadget(#text3, 25, 90, 250, 120) 
      For a = 0 To 3 
        AddGadgetItem (#text3, -1, "Item " + Str(a)) ; define listview content 
      Next 
    Repeat 
    ev=WaitWindowEvent() 
    Select ev 
      Case #WM_LBUTTONDOWN 
        dragfrom=GetDlgCtrlID_(ChildWindowFromPoint_(WindowID(0), WindowMouseX(0),WindowMouseY(0))) 
        If dragfrom>=#text1 And dragfrom<=#text3 
          SendMessage_(GadgetID(dragfrom),#WM_SETREDRAW,0,0)
          text$=GetGadgetText(dragfrom)
;Create an image for the text.
;First calculate the required dimensions.
          wdc=GetDC_(WindowID(0))
          SetTextAlign_(wdc,#TA_LEFT|#TA_TOP|#TA_NOUPDATECP) 
          rc\right=1
          rc\bottom=1
          DrawText_(wdc,text$,Len(text$),rc.rect,#DT_CALCRECT)
          im=CreateImage(#PB_Any,rc\right,rc\bottom)
          hdc=StartDrawing(ImageOutput(im))
            SetTextAlign_(hDC,#TA_LEFT|#TA_TOP|#TA_NOUPDATECP) 
            DrawText_(hdc,text$,Len(text$),rc.rect,#DT_WORDBREAK)
          StopDrawing()
          IsDragging=#True
          SetCapture_(WindowID(0))
          ShowCursor_(0)
        EndIf 
      Case #WM_MOUSEMOVE 
        If IsDragging
;First restore any background.
          hdc=StartDrawing(ImageOutput(im)) 
          If x>-1 And y>-1
            BitBlt_(wdc,x,y,ImageWidth(im),ImageHeight(im),hdc,0,0,#SRCINVERT) 
            x=-1:y=-1
          EndIf
;Now redraw image.
          tempx=WindowMouseX(0) : tempy=WindowMouseY(0)
          If tempx>0 And tempy>0
;Debug "("+Str(x)+", "+Str(y)+")"
            x=tempx:y=tempy
            BitBlt_(wdc,x,y,ImageWidth(im),ImageHeight(im),hdc,0,0,#SRCINVERT) 
          EndIf          
          StopDrawing()
        EndIf
      Case #WM_LBUTTONUP 
        If IsDragging 
          If x>-1 And y>-1
          hdc=StartDrawing(ImageOutput(im)) 
            BitBlt_(wdc,x,y,ImageWidth(im),ImageHeight(im),hdc,0,0,#SRCINVERT) 
          StopDrawing()
          EndIf
          SendMessage_(GadgetID(dragfrom),#WM_SETREDRAW,1,0)
          ReleaseCapture_() 
          ShowCursor_(#True) 
          ReleaseDC_(WindowID(0),wdc)
          FreeImage(im)
;          FreeGadget(templisticon) 
          IsDragging = #False 
          x=-1 : y=-1
;Check to see if the text was dropped onto another text gadget. 
          dragto=GetDlgCtrlID_(ChildWindowFromPoint_(WindowID(0), WindowMouseX(0),WindowMouseY(0))) 
          Select dragto 
            Case #text1, #text2 
;Drop the text onto the targetted gadget. 
              SetGadgetText(dragto, GetGadgetText(dragfrom)) 
            Case #text3 ;ListView gadget. 
              AddGadgetItem (dragto, -1, GetGadgetText(dragfrom)) 
          EndSelect 
        EndIf 
    EndSelect    
    Until ev = #PB_Event_CloseWindow 
  EndIf 
EndIf 
End 
It's very rough and ready at the moment.

Next step is to integrate this into EasyVENT.
I may look like a mule, but I'm not a complete ass.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

Code: Select all

Box(0,0,80,20,#Green)
= Button
StartDrawing(ImageOutput(0))
= Button with rollover effects
...when drawing images on images here?
= You are experimenting with the same stuff as I am aren't you.. I was fiddling with drawing images on an
imagegadget myself 20 minutes ago, is that what you're trying to do? :wink:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

No, I'm messing around with drag and drop.
I may look like a mule, but I'm not a complete ass.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

Ok, good luck with the drag and drop. Your snippets seems to suggest I can load and draw images on another image,
and if I could XOR them, I wouldn't have to worry about preserving the background.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

The Xoring works well with the API and BitBlt_(). With the PB commands, however, I still think there's something amis there!
I may look like a mule, but I'm not a complete ass.
Post Reply