ladyk General User

Joined: 16 Nov 2006 Posts: 6
|
Posted: Wed Dec 27, 2006 3:09 pm Post subject: [c++] How to draw on dialog? |
|
|
Hi,
I want to draw some simple things on a dialog using c++.
I found an example for OOoBasic (see below) that works well, and I can translate it to c++, but the following line gives me problems:
| Code: | | oDlgGraph = oDlg.getPeer.createGraphics |
How can i get an XGraphics to draw on from a dialog when using c++?
Thanks in advance!
k
complete OOoBasic code listing:
| Code: | REM ***** BASIC *****
Dim oDlg As Object
Dim oPaintListener As Object
Dim oDlgGraph As Object
Sub ShowDialog
Dim oDlgModel As Object
Dim oWindow As Object
oDlgModel=CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
oDlgModel.PositionX = 50
oDlgModel.PositionY = 50
oDlgModel.Width = 150
oDlgModel.Height = 150
oDlgModel.Title = "Dialog Example"
oDlg = CreateUnoService("com.sun.star.awt.UnoControlDialog")
oWindow = CreateUnoService("com.sun.star.awt.Toolkit")
oDlg.setModel(oDlgModel)
oDlg.createPeer(oWindow, null)
oDlgGraph = oDlg.getPeer.createGraphics
With oDlgGraph
.setFillColor(RGB(255,255,255))
.setLineColor(RGB(200,200,200))
.drawRect(0,0,100,100)
End With
oPaintListener = CreateUnoListener("ThisDialog_", "com.sun.star.awt.XPaintListener")
oDlg.addPaintListener( oPaintListener )
oDlg.execute
oDlg.removePaintListener( oPaintListener )
End Sub
'__________________________________________________________________________________________________________
' This is a good place for drawing instructions.
' This routine is called whenever the dialog has to be repainted
Sub ThisDialog_windowPaint(oEvt)
'skip if there are other paint events in queue
If oEvt.count > 0 Then Exit Sub
Dim oGrad As New com.sun.star.awt.Gradient
With oGrad
.Style = com.sun.star.awt.GradientStyle.LINEAR
.StartColor = RGB( 255, 255, 255 )
.EndColor = RGB( 200, 230, 230 )
.Angle = 450 ' 45.0 degrees
' .Border = 0
' .XOffset = 0
' .YOffset = 0
.StartIntensity = 100
.EndIntensity = 100
.StepCount = 100
End With
nDlgWidth = oDlg.Peer.Size.Width
nDlgHeight = oDlg.Peer.Size.Height
'draw something
With oDlgGraph
.drawGradient(0,0, 100,220, oGrad)
.drawGradient(100,220, nDlgWidth,nDlgHeight, oGrad)
.drawText(10,10,"ciao a tutti")
.DrawLine(100,0,100,nDlgHeight)
.DrawLine(0,220,nDlgWidth,220)
.drawRect(0,0,100,100)
End With
'some nested rounded rect
For I = 10 To 100 Step 10
nX = 100 + I
nY = 0 + I
nWidth = nDlgWidth - 100 - 2*I
' nWidth = 300
nHeight = 220 - 2*I
nRound = 110-I
oDlgGraph.setFillColor(RGB(255-I, 255, 255-I))
oDlgGraph.drawRoundedRect(nX, nY, nWidth, nHeight ,nRound, nRound)
Next I
End Sub
'__________________________________________________________________________________________________________
Sub ThisDialog_disposing(oEvt As Object)
'nothing to do
End Sub
|
(modified example from code snippets) |
|