home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form AspectForm
- Caption = "Aspect"
- ClientHeight = 4230
- ClientLeft = 1980
- ClientTop = 1695
- ClientWidth = 4710
- Height = 4920
- Left = 1920
- LinkTopic = "Form1"
- ScaleHeight = 4230
- ScaleWidth = 4710
- Top = 1065
- Width = 4830
- Begin VB.TextBox AspectText
- Height = 285
- Left = 1080
- TabIndex = 1
- Text = "1"
- Top = 120
- Width = 735
- End
- Begin VB.Label Label1
- Caption = "Aspect Ratio"
- Height = 255
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 975
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Attribute VB_Name = "AspectForm"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Dim SelectInProgress As Boolean
- Dim StartX As Single
- Dim StartY As Single
- Dim LastX As Single
- Dim LastY As Single
- Dim OldMode As Integer
- Dim ViewAspect As Single
- Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
- SelectInProgress = True
- ' For demonstration purposes, get the desired
- ' aspect ratio from a TextBox.
- ViewAspect = CSng(AspectText.Text)
- ' Save the current drawing mode.
- OldMode = DrawMode
- ' Use invert mode for the rubberband box.
- DrawMode = vbInvert
- StartX = X
- StartY = Y
- LastX = X
- LastY = Y
- Line (StartX, StartY)-(LastX, LastY), , B
- End Sub
- Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Dim wid As Single
- Dim hgt As Single
- If Not SelectInProgress Then Exit Sub
- ' Erase the old box.
- Line (StartX, StartY)-(LastX, LastY), , B
- wid = X - StartX
- hgt = Y - StartY
- AdjustAspect wid, hgt, ViewAspect
- LastX = StartX + wid
- LastY = StartY + hgt
- ' Draw the new box.
- Line (StartX, StartY)-(LastX, LastY), , B
- End Sub
- Sub AdjustAspect(ww_wid As Single, ww_hgt As Single, view_aspect As Single)
- Dim ww_aspect As Single
- Dim sign As Integer
- ' Don't divide by zero.
- If ww_wid = 0 Or ww_hgt = 0 Or view_aspect = 0 Then Exit Sub
- ww_aspect = ww_hgt / ww_wid
- If ww_aspect < 0 Then
- sign = -1
- Else
- sign = 1
- End If
- ww_aspect = Abs(ww_aspect)
- If ww_aspect > view_aspect Then
- ' The world window is too tall and thin. Make it wider.
- ww_wid = sign * ww_hgt / view_aspect
- Else
- ' The world window is too short and squat. Make it taller.
- ww_hgt = sign * view_aspect * ww_wid
- End If
- End Sub
- Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Dim wid As Single
- Dim hgt As Single
- If Not SelectInProgress Then Exit Sub
- SelectInProgress = False
- ' Erase the old box.
- Line (StartX, StartY)-(LastX, LastY), , B
- ' Restore the original drawing mode.
- DrawMode = OldMode
- wid = X - StartX
- hgt = Y - StartY
- AdjustAspect hgt, wid, ViewAspect
- LastX = StartX + wid
- LastY = StartY + hgt
- ' Do something with the region
- ' (StartX, StartY) - (LastX, LastY).
- End Sub
- Private Sub mnuFileExit_Click()
- Unload Me
- End Sub
-