Page 1 of 1

Flicker free splitter example (uses EasyVENT)

Posted: Mon Jul 10, 2006 11:19 pm
by srod
Code updated For 5.20+

Hi,

I was in need of a flicker-free splitter and quickly found that my EasyVENT library provided the quickest way of doing this.

The following only shows a vertical splitter but can easily be extended. You will obviously need the EasyVENT library which you can find in the Announcement forum.

Code: Select all

;EasyVENT demonstration program - Splitter.
;*********************************************************************************
;This demonstration shows how to use EasyVENT to quickly implement a flicker free splitter.
;It does not use a Purebasic SplitterGadget or any kind of container.
;*********************************************************************************

;ESSENTIAL INCLUDE.
;*********************************************************************************
XIncludeFile "EasyVENT.pbi"
;*********************************************************************************

Declare.l MouseOverSplitter(*sender.PB_Sender)
Declare.l MouseDownSplitter(*sender.PB_Sender)
Declare.l MouseOver(*sender.PB_Sender)
Declare.l MouseUp(*sender.PB_Sender)

Define Event.l
Global splitter,mousedown,splitterwidth=4

OpenWindow(0, 100, 100, 600, 600, "Event example - Flicker free splitter.", #PB_Window_SystemMenu |#PB_Window_Maximize)

;Create a couple of gadgets.

  ContainerGadget(0, 0, 25, 506, 250, #PB_Container_Raised) 
    ButtonGadget(1, 5, 15, 80, 24, "Button") 
    ListIconGadget(2,5,65,140,80,"ListIcon",100) 
    StringGadget(3, 5, 180, 120, 20, "String gadget")
  CloseGadgetList() 
  ListIconGadget(4, GadgetWidth(0)+10+splitterwidth,25, WindowWidth(0)-(GadgetWidth(0)+10+splitterwidth), 250, "ListIcon",200) 

;Our splitter will 'split' the container and the listicon.
  splitter=ImageGadget(#PB_Any, GadgetWidth(0)+5,GadgetY(0)+5,splitterwidth,GadgetHeight(0)-10, 0,#PB_Image_Border)

;Set event handlers.
  SetEventHandler(GadgetID(splitter), #OnMouseDown, @MouseDownSplitter())
  SetEventHandler(GadgetID(splitter), #OnMouseOver, @MouseOverSplitter())
  SetEventHandler(WindowID(0), #OnMouseOver, @MouseOver())
  SetEventHandler(WindowID(0), #OnMouseUp, @MouseUp())


Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End


;*********************************************************************************
;                                 EVENT HANDLERS
;*********************************************************************************

;Instigate the resize.
Procedure.l MouseDownSplitter(*sender.PB_Sender)
  mousedown=1
  SetCursor_(LoadCursor_(0,#IDC_SIZEWE))
  SetCapture_(WindowID(0))
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

;Show size cursor if the mouse is over the splitter.
Procedure.l MouseOverSplitter(*sender.PB_Sender)
  SetCursor_(LoadCursor_(0,#IDC_SIZEWE))
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

;Called if a splitter resize is in progress.
Procedure.l MouseOver(*sender.PB_Sender)
  If mousedown
    SetCursor_(LoadCursor_(0,#IDC_SIZEWE))
    ResizeGadget(splitter,*sender\mousex,#PB_Ignore,#PB_Ignore,#PB_Ignore)
  EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

;Complete the resize operation by resizing the gadgets either side of the repositioned splitter.
Procedure.l MouseUp(*sender.PB_Sender)
  If mousedown
    ReleaseCapture_()
    HideGadget(splitter,1)
    mousedown=0
    ResizeGadget(0,#PB_Ignore,#PB_Ignore,*sender\mousex-5,#PB_Ignore)
    ResizeGadget(4,GadgetWidth(0)+10+splitterwidth,#PB_Ignore,WindowWidth(0)-(GadgetWidth(0)+10+splitterwidth),#PB_Ignore)
    HideGadget(splitter,0)
  EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Regards.