PDA

View Full Version : Yet another question, Scroll bars



RobbeK
18-12-2013, 14:39
Hi all,

Is it possible to put some scroll bars on a Canvas / TBGL window (or do I have to create a separate form for it ?).
I need to look into a very wide BMP at pixel level (math related)

Thanks in advance ,

Rob

Petr Schreiber
18-12-2013, 18:46
Hi Rob,

the easiest way to achieve this is to use concept of viewports. You can nest dialog into dialog this way.

So you will have one main dialog, and one secondary, while the secondary will contain just the CANVAS/TBGL surface.

There are some examples in SampleScripts, but I crafted a simpler one here for you:


Uses "UI"

' -- ID numbers of controls
Begin ControlID
%Main_Viewport
End ControlID

Begin Const
%MAIN_WIDTH = 320
%MAIN_HEIGHT = 240
End Const

' -- Create dialog here
Function TBMain()
Local hDlg As DWord
Local hViewport As DWord

Dialog New Pixels, 0, "Minimalistic viewport demo",-1,-1, %MAIN_WIDTH, %MAIN_HEIGHT, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg

' -- Place controls here
hViewport = Control Add VIEWPORT, hDlg, %Main_Viewport, "", 10, 10, %MAIN_WIDTH-20, %MAIN_HEIGHT-20
Dialog_WithCanvas(hViewport)

Dialog Show Modal hDlg, Call cbDialog

End Function

' -- Callback for main dialog
CallBack Function cbDialog()

' -- Test for messages
Select Case CBMSG

Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here

Case %WM_COMMAND
' -- You can handle controls here

Case %WM_CLOSE
' -- Put code to be executed before dialog end here

End Select

End Function

Begin ControlID
%Viewport_Canvas
End ControlID

'----------------------------------------------------------------------------

Function Dialog_WithCanvas(hViewPort As DWord)

Local hDlg As Long

Dialog New Pixels, hViewPort, "", 0, 0, 500, 500, %WS_CHILD Or %WS_CLIPCHILDREN To hDlg

Control Add Canvas , hDlg, %Viewport_Canvas, "", 0, 0, 500, 500
Canvas_Attach(hDlg, %Viewport_Canvas, TRUE)
Canvas_Clear(%BLACK)
Canvas_Line((0,0), (500, 500), %GREEN)
Canvas_Line((500,0), (0, 500), %GREEN)
Canvas_Redraw

Dialog Show Modeless hDlg, Call cbCanvasDialog

ViewPort_SetChild(hViewPort, hDlg, FALSE )

Function = hDlg
End Function

' -- Callback for canvas dialog
CallBack Function cbCanvasDialog()

' -- Test for messages
Select Case CBMSG

Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here

Case %WM_COMMAND
' -- You can handle controls here

Case %WM_CLOSE
' -- Put code to be executed before dialog end here

End Select

End Function


Petr

RobbeK
19-12-2013, 11:02
Thanks alot , Petr .... perfect !