Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic.PowerPacks
Friend Class GraphicRectInfoEditor
	Inherits System.Windows.Forms.Form
	
	'UPGRADE_WARNING: Arrays can't be declared with New. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC9D3AE5-6B95-4B43-91C7-28276302A5E8"'
    Private graphicrects() As graphicrect = ADGEDotNetUt.ArrayUt(Of graphicrect).NewArray1(171)
	Public selectedrect As Short
	'Public selectedsublocation As Integer
	Public subchange As Boolean
	
	
    Public Sub init()
        Dim i As Short

        'graphics.resetmodifiedcolorarray

        'CeilingGraphic.Picture = graphics.loadgraphic(77, 0)
        'Floorgraphic.Picture = graphics.loadgraphic(76, 0)


        graphics.curPalette = graphics.gPALETTE_MAIN
        Dim offscreen As Bitmap = New Bitmap(GraphicB.ClientSize.Width, GraphicB.ClientSize.Height)
        Using cv As Drawing.Graphics = Drawing.Graphics.FromImage(offscreen)
            graphics.fill(cv, 0, 0, GraphicB.Width, GraphicB.Height, System.Drawing.Color.Black)
            graphics.stretchbmpby(cv, 76, 0, 0, 0, 0, 200, 200)
            graphics.stretchbmpby(cv, 75, 0, 132, 0, 0, 200, 200)
        End Using
        GraphicB.BackgroundImage = offscreen
        GraphicB.BackgroundImageLayout = ImageLayout.None
        GraphicB.Refresh()

        For i = 1 To 171
            graphicrects(i).x1 = graphics.f558.graphicrect(i).x1
            graphicrects(i).x2 = graphics.f558.graphicrect(i).x2
            graphicrects(i).y1 = graphics.f558.graphicrect(i).y1
            graphicrects(i).y2 = graphics.f558.graphicrect(i).y2
            graphicrects(i).width = graphics.f558.graphicrect(i).width
            graphicrects(i).height = graphics.f558.graphicrect(i).height
            graphicrects(i).srcx = graphics.f558.graphicrect(i).srcx
            graphicrects(i).srcy = graphics.f558.graphicrect(i).srcy
            graphicrects(i).name = graphics.f558.graphicrect(i).name
            graphicrects(i).description = graphics.f558.graphicrect(i).description
            graphicrects(i).displayedGraphic = graphics.f558.graphicrect(i).displayedGraphic
            graphicrects(i).mirrored = graphics.f558.graphicrect(i).mirrored
        Next

        CGRectList.Items.Clear()
        For i = 1 To 171
            CGRectList.Items.Add(zerostr(i, 3)).SubItems.Add(graphicrects(i).name)
        Next

        subchange = True
        selectrect((1))
        subchange = False

        update_Renamed()
    End Sub
	
    Private Sub Cancel_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub
	
	
    Private Sub CGRectList_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CGRectList.SelectedIndexChanged
        If CGRectList.FocusedItem Is Nothing Then Exit Sub
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        selectrect((CGRectList.FocusedItem.Index + 1))
        subchange = False
    End Sub
	
	
	
	
	
	'UPGRADE_WARNING: Event GX1.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub GX1_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles GX1.TextChanged
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		graphicrects(selectedrect).x1 = App.EFChange8(GX1, 0, 255)
		subchange = False
		update_Renamed()
	End Sub
	'UPGRADE_WARNING: Event Gx2.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub Gx2_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gx2.TextChanged
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		graphicrects(selectedrect).x2 = App.EFChange8(GX2, 0, 255)
		subchange = False
		update_Renamed()
	End Sub
	'UPGRADE_WARNING: Event Gy1.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub Gy1_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gy1.TextChanged
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		graphicrects(selectedrect).y1 = App.EFChange8(GY1, 0, 255)
		subchange = False
		update_Renamed()
	End Sub
	'UPGRADE_WARNING: Event Gy2.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub Gy2_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gy2.TextChanged
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		graphicrects(selectedrect).y2 = App.EFChange8(GY2, 0, 255)
		subchange = False
		update_Renamed()
	End Sub
	'UPGRADE_WARNING: Event Gwidth.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub Gwidth_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gwidth.TextChanged
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		graphicrects(selectedrect).width = App.EFChange8(GWidth, 0, 255)
		subchange = False
		update_Renamed()
	End Sub
	'UPGRADE_WARNING: Event Gheight.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub Gheight_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gheight.TextChanged
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		graphicrects(selectedrect).height = App.EFChange8(GHeight, 0, 255)
		subchange = False
		update_Renamed()
	End Sub
	'UPGRADE_WARNING: Event Gsrcx.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub Gsrcx_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gsrcx.TextChanged
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		graphicrects(selectedrect).srcx = App.EFChange8(GSrcX, 0, 255)
		subchange = False
		update_Renamed()
	End Sub
	'UPGRADE_WARNING: Event Gsrcy.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub Gsrcy_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gsrcy.TextChanged
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		graphicrects(selectedrect).srcy = App.EFChange8(GSrcY, 0, 255)
		subchange = False
		update_Renamed()
	End Sub
	
    Private Sub Ok_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Ok.Click
        Dim i As Short
        For i = 1 To 171
            graphics.f558.graphicrect(i).x1 = graphicrects(i).x1
            graphics.f558.graphicrect(i).x2 = graphicrects(i).x2
            graphics.f558.graphicrect(i).y1 = graphicrects(i).y1
            graphics.f558.graphicrect(i).y2 = graphicrects(i).y2
            graphics.f558.graphicrect(i).width = graphicrects(i).width
            graphics.f558.graphicrect(i).height = graphicrects(i).height
            graphics.f558.graphicrect(i).srcx = graphicrects(i).srcx
            graphics.f558.graphicrect(i).srcy = graphicrects(i).srcy
        Next
        App.graphics.f558.update()
        Me.Close()

    End Sub
	'UPGRADE_NOTE: mapfile was upgraded to mapfile_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
	Public Sub selectrect(ByVal num As Short)
        selectedrect = num
        CGRectList.Items(num - 1).Focused = True
        MyUt.CheckSel(CGRectList, num - 1, "BlueGem")
		
		GX1.Text = Str(graphicrects(num).x1)
		GX2.Text = Str(graphicrects(num).x2)
		GY1.Text = Str(graphicrects(num).y1)
		GY2.Text = Str(graphicrects(num).y2)
		GWidth.Text = Str(graphicrects(num).width)
		GHeight.Text = Str(graphicrects(num).height)
		GSrcX.Text = Str(graphicrects(num).srcx)
		GSrcY.Text = Str(graphicrects(num).srcy)
		
		GName.Text = graphicrects(num).name
		GGraphicNum.Text = Str(graphicrects(num).displayedGraphic - 1)
        GGraphicNumText.Text = mapfile.getname(graphicrects(num).displayedGraphic)
		GDescription.Text = graphicrects(num).description
		
		If graphicrects(num).mirrored > 0 Then
			CBMirrored.CheckState = System.Windows.Forms.CheckState.Checked
		Else
			CBMirrored.CheckState = False
		End If
		update_Renamed()
	End Sub
	
	
	'Public Sub selectsublocation(ByVal num As Integer)
	'    selectedsublocation = num
	'    CGSubLocationList.ListIndex = num - 1
	'    update
	'End Sub
	
    Public Sub update_Renamed()
        Dim x2, x1, y2, y1 As Short
        Dim width_Renamed As Short
        Dim height_Renamed As Short


        x1 = graphicrects(selectedrect).x1
        x2 = graphicrects(selectedrect).x2
        y1 = graphicrects(selectedrect).y1
        y2 = graphicrects(selectedrect).y2

        width_Renamed = (x2 - x1)
        height_Renamed = (y2 - y1)
        If width_Renamed < 0 Then
            width_Renamed = 0
        End If
        If height_Renamed < 0 Then
            height_Renamed = 0
        End If

        GRectShape.Left = 2 * x1 + 1
        GRectShape.Top = 2 * y1 + 1
        GRectShape.Width = 2 * width_Renamed + 1
        GRectShape.Height = 2 * height_Renamed + 1


        GSrcRectShape.Left = graphicrects(selectedrect).srcx + 1
        GSrcRectShape.Top = graphicrects(selectedrect).srcy + 1
        GSrcRectShape.Width = width_Renamed + 1
        GSrcRectShape.Height = height_Renamed + 1
        If graphicrects(selectedrect).displayedGraphic > 0 Then
            Dim cx As Integer = graphics.getgbitmapwidth(graphicrects(selectedrect).displayedGraphic - 1)
            Dim cy As Integer = graphics.getgbitmapheight(graphicrects(selectedrect).displayedGraphic - 1)
            Dim offscreen As Bitmap = New Bitmap(cx, cy)
            Using cv As Drawing.Graphics = Drawing.Graphics.FromImage(offscreen)
                graphics.drawbmp(cv, graphicrects(selectedrect).displayedGraphic - 1)
            End Using
            GraphicA.BackgroundImage = offscreen
            GraphicA.BackgroundImageLayout = ImageLayout.None

            'graphics.resetmodifiedcolorarray
            'ImageB.Picture = graphics.loadgraphic(graphicrects(selectedrect).displayedGraphic, graphicrects(selectedrect).mirrored)
            'ImageB.Visible = True
            GSrcRectShape.Visible = True
            GraphicA.Width = cx + 4
            GraphicA.Height = cy + 4
            GraphicA.Visible = True
            GraphicA.Refresh()
        Else
            'graphics.fill GraphicA.hdc, 0, 0, GraphicA.width, GraphicA.height, vbBlack
            GraphicA.Visible = False
            'ImageB.Visible = False
            GSrcRectShape.Visible = False
        End If

    End Sub

    Private Sub GraphicRectInfoEditor_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If e.CloseReason = CloseReason.UserClosing Then
            e.Cancel = True
            Hide()
        End If
    End Sub

    Private Sub GraphicRectInfoEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CGRectList.SmallImageList = App.JewelIL
    End Sub
End Class