Skip to content

Commit 197825c

Browse files
committed
Rect changes - now using width and height rather than x2,y2
1 parent f67affb commit 197825c

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/WIP/stdCanvas.cls

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Public Enum CanvasRectFields
1111
[_First] = 0
1212
cvfRectLeft = 0
1313
cvfRectTop
14-
cvfRectRight
15-
cvfRectBottom
16-
[_Last] = cvfRectBottom
14+
cvfRectWidth
15+
cvfRectHeight
16+
[_Last] = cvfRectHeight
1717
End Enum
1818

1919
Public Enum CanvasObjectStyles
@@ -204,22 +204,22 @@ Private Sub Class_Terminate()
204204
End Sub
205205

206206
'Draw a rectangle
207-
'@param x1 - X Coord of top left corner
208-
'@param y1 - Y Coord of top left corner
209-
'@param x2 - X Coord of bottom right corner
210-
'@param y2 - Y Coord of bottom right corner
207+
'@param left - X Coord of left edge
208+
'@param top - Y Coord of top edge
209+
'@param width - Width of rectangle
210+
'@param height - Height of rectangle
211211
'@returns - Pointer to a rectangle handle
212-
Public Function DrawRectangle(ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, Optional ByVal fillColor As Long = 0, Optional ByVal borderColor As Long = 0, Optional ByVal borderWeight As Long = 1) As Long
212+
Public Function DrawRectangle(ByVal left As Long, ByVal top As Long, ByVal width As Long, ByVal height As Long, Optional ByVal fillColor As Long = 0, Optional ByVal borderColor As Long = 0, Optional ByVal borderWeight As Long = 1) As Long
213213
Dim index As Long: index = getNewObject()
214214
With This.objects(index)
215215
.ObjectType = cvtRectangle
216216
ReDim .ObjectParams(CanvasRectFields.[_First] To CanvasRectFields.[_Last])
217217
ReDim .ObjectStyle(CanvasObjectStyles.[_First] To CanvasObjectStyles.[_Last])
218218
End With
219-
Data(index, CanvasRectFields.cvfRectLeft) = x1
220-
Data(index, CanvasRectFields.cvfRectTop) = y1
221-
Data(index, CanvasRectFields.cvfRectRight) = x2
222-
Data(index, CanvasRectFields.cvfRectBottom) = y2
219+
Data(index, CanvasRectFields.cvfRectLeft) = left
220+
Data(index, CanvasRectFields.cvfRectTop) = top
221+
Data(index, CanvasRectFields.cvfRectWidth) = width
222+
Data(index, CanvasRectFields.cvfRectHeight) = height
223223
Style(index, cvsFillColor) = fillColor
224224
Style(index, cvsLineColor) = borderColor
225225
Style(index, cvsLineWidth) = borderWeight
@@ -238,12 +238,14 @@ Public Property Let Data(ByVal handle As Long, ByVal param As Long, ByVal RHS As
238238
Select Case param
239239
Case CanvasRectFields.cvfRectLeft
240240
.bbox.Left = RHS
241-
Case CanvasRectFields.cvfRectRight
242-
.bbox.Right = RHS
241+
.bbox.Right = RHS + .ObjectParams(CanvasRectFields.cvfRectWidth)
243242
Case CanvasRectFields.cvfRectTop
244243
.bbox.Top = RHS
245-
Case CanvasRectFields.cvfRectBottom
246-
.bbox.Bottom = RHS
244+
.bbox.Bottom = RHS + .ObjectParams(CanvasRectFields.cvfRectHeight)
245+
Case CanvasRectFields.cvfRectWidth
246+
.bbox.Right = .ObjectParams(CanvasRectFields.cvfRectLeft) + RHS
247+
Case CanvasRectFields.cvfRectHeight
248+
.bbox.Bottom = .ObjectParams(CanvasRectFields.cvfRectTop) + RHS
247249
End Select
248250
End Select
249251
End With
@@ -306,14 +308,14 @@ Public Sub Redraw()
306308
If .ObjectStyle(CanvasObjectStyles.[_cvsFillVisible]) Then
307309
Dim fillBrush As LongPtr
308310
If GdipCreateSolidFill(.ObjectStyle(cvsFillColor), fillBrush) = 0 Then
309-
Call GdipFillRectangle(G, fillBrush, .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectTop), .ObjectParams(cvfRectRight) - .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectBottom) - .ObjectParams(cvfRectTop))
311+
Call GdipFillRectangle(G, fillBrush, .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectTop), .ObjectParams(cvfRectWidth), .ObjectParams(cvfRectHeight))
310312
Call GdipDeleteBrush(fillBrush)
311313
End If
312314
End If
313315
If .ObjectStyle(CanvasObjectStyles.[_cvsLineVisible]) Then
314316
Dim strokePen As LongPtr
315317
If GdipCreatePen1(.ObjectStyle(cvsLineColor), .ObjectStyle(cvsLineWidth), UnitPixel, strokePen) = 0 Then
316-
Call GdipDrawRectangle(G, strokePen, .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectTop), .ObjectParams(cvfRectRight) - .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectBottom) - .ObjectParams(cvfRectTop))
318+
Call GdipDrawRectangle(G, strokePen, .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectTop), .ObjectParams(cvfRectWidth), .ObjectParams(cvfRectHeight))
317319
Call GdipDeletePen(strokePen)
318320
End If
319321
End If
@@ -350,14 +352,14 @@ Private Sub RedrawDirect()
350352
If .ObjectStyle(CanvasObjectStyles.[_cvsFillVisible]) Then
351353
Dim fillBrush As LongPtr
352354
If GdipCreateSolidFill(.ObjectStyle(cvsFillColor), fillBrush) = 0 Then
353-
Call GdipFillRectangle(G, fillBrush, .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectTop), .ObjectParams(cvfRectRight) - .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectBottom) - .ObjectParams(cvfRectTop))
355+
Call GdipFillRectangle(G, fillBrush, .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectTop), .ObjectParams(cvfRectWidth), .ObjectParams(cvfRectHeight))
354356
Call GdipDeleteBrush(fillBrush)
355357
End If
356358
End If
357359
If .ObjectStyle(CanvasObjectStyles.[_cvsLineVisible]) Then
358360
Dim strokePen As LongPtr
359361
If GdipCreatePen1(.ObjectStyle(cvsLineColor), .ObjectStyle(cvsLineWidth), UnitPixel, strokePen) = 0 Then
360-
Call GdipDrawRectangle(G, strokePen, .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectTop), .ObjectParams(cvfRectRight) - .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectBottom) - .ObjectParams(cvfRectTop))
362+
Call GdipDrawRectangle(G, strokePen, .ObjectParams(cvfRectLeft), .ObjectParams(cvfRectTop), .ObjectParams(cvfRectWidth), .ObjectParams(cvfRectHeight))
361363
Call GdipDeletePen(strokePen)
362364
End If
363365
End If

0 commit comments

Comments
 (0)