Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Curve Art - Form1.vb

Form1.vb

Caricato da: Totem
Scarica il programma completo

  1. Imports Curve_Art.Mix
  2. Imports Microsoft.Win32
  3. Public Class Form1
  4.     Private CurveBuffer As ClosedCurve
  5.     Private LineBuffer As ClosedLine
  6.     Private MixBuffer As Mix
  7.     Private ActiveBuffer As FillableItem
  8.     Private CopiedItem As FillableItem
  9.  
  10.     Private PickingColor As Boolean = False
  11.     Private MaxIndex = 0
  12.  
  13.     Private Sub RegisterIcon()
  14.         Dim RegKey As RegistryKey = Registry.ClassesRoot.OpenSubKey(".cva")
  15.         Dim WParam As RegistryKeyPermissionCheck = RegistryKeyPermissionCheck.ReadWriteSubTree
  16.  
  17.         If RegKey IsNot Nothing Then
  18.             Exit Sub
  19.         Else
  20.             Dim Result As DialogResult
  21.             Result = MessageBox.Show("Impostare Curve Art come programma predefinito per aprire i file con estensione *.cva?", Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question)
  22.             If Result = Windows.Forms.DialogResult.No Then
  23.                 Exit Sub
  24.             End If
  25.         End If
  26.  
  27.         RegKey = Registry.ClassesRoot.CreateSubKey(".cva", WParam)
  28.         RegKey.SetValue("", "CurveArtProjectFile")
  29.         RegKey = Registry.ClassesRoot.CreateSubKey("CurveArtProjectFile", WParam)
  30.         RegKey.SetValue("", "File progetto di Curve Art")
  31.         RegKey = RegKey.CreateSubKey("DefaultIcon", WParam)
  32.         RegKey.SetValue("", Application.StartupPath & "\cva.ico")
  33.         RegKey = Registry.ClassesRoot.OpenSubKey("CurveArtProjectFile", True)
  34.         RegKey = RegKey.CreateSubKey("shell\open\command", WParam)
  35.         RegKey.SetValue("", String.Format("""{0}"" ""%1""", Application.ExecutablePath))
  36.     End Sub
  37.  
  38.     Private Function GetHexColor(ByVal C As Color) As String
  39.         Return String.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", C.A, C.R, C.G, C.B)
  40.     End Function
  41.  
  42.     Private Sub SetNodeInfo(ByVal Item As FillableItem, ByVal Node As TreeNode)
  43.         With Node
  44.             .Nodes.Clear()
  45.             .Nodes.Add("Spessore = " & Item.Width & " pt").ImageIndex = 2
  46.             .Nodes.Add("Colore tratto = " & GetHexColor(Item.Color)).ImageIndex = 2
  47.             .Nodes.Add("Tratto = " & IIf(Item.DrawOutline, "Sì", "No")).ImageIndex = 2
  48.             .Nodes.Add("Colore riempimento = " & GetHexColor(Item.FillColor)).ImageIndex = 2
  49.             .Nodes.Add("Riempimento = " & IIf(Item.Fill, "Sì", "No")).ImageIndex = 2
  50.             .Nodes.Add("Angolo di sfumatura = " & Item.BlendAngle).ImageIndex = 2
  51.             .Nodes.Add("Colore sfumatura = " & GetHexColor(Item.BlendColor)).ImageIndex = 2
  52.             .Nodes.Add("Sfumatura = " & IIf(Item.Blend, "Sì", "No")).ImageIndex = 2
  53.         End With
  54.     End Sub
  55.  
  56.     Private Sub SetItemInfo(ByVal Layer As Layer, ByVal Item As ListViewItem)
  57.         With Item
  58.             .Text = Layer.Name
  59.             .ImageIndex = 0
  60.             .Tag = Layer
  61.             .SubItems.Add(Layer.Index.ToString)
  62.             .SubItems.Add(Layer.Index.ToString)
  63.         End With
  64.     End Sub
  65.  
  66.     Private Sub SaveDrawing(ByVal File As String)
  67.         Dim B As New Bitmap(pnlCanavas.Width, pnlCanavas.Height)
  68.         Dim G As Graphics = Graphics.FromImage(B)
  69.  
  70.         G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
  71.         For Each L As ListViewItem In lstLayers.CheckedItems
  72.             Dim Layer As Layer = L.Tag
  73.             Layer.Draw(G)
  74.         Next
  75.  
  76.         B.Save(File)
  77.     End Sub
  78.  
  79.     Private Sub strAddLayer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAddLayer.Click
  80.         Dim Layer As New Layer
  81.         Dim L As New ListViewItem
  82.  
  83.         Layer.Name = "Nuovo livello"
  84.         If lstLayers.Items.Count = 0 Then
  85.             Layer.Name = "Sfondo"
  86.         End If
  87.         Layer.Index = MaxIndex * 10
  88.         MaxIndex += 1
  89.         SetItemInfo(Layer, L)
  90.         L.Checked = True
  91.         L.Selected = True
  92.  
  93.         lstLayers.Items.Add(L)
  94.     End Sub
  95.  
  96.     Private Sub lstLayers_AfterLabelEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LabelEditEventArgs) Handles lstLayers.AfterLabelEdit
  97.         Dim Layer As Layer = lstLayers.Items(e.Item).Tag
  98.         Layer.Name = e.Label
  99.     End Sub
  100.  
  101.     Private Sub lstLayers_ItemChecked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles lstLayers.ItemChecked
  102.         If e.Item.Index = 0 Then
  103.             Dim Layer0 As Layer = e.Item.Tag
  104.             If Not e.Item.Checked Then
  105.                 pnlCanavas.BackgroundImage = Nothing
  106.             Else
  107.                 If Layer0.BgImage IsNot Nothing Then
  108.                     pnlCanavas.BackgroundImage = Layer0.BgImage.Image
  109.                     If Layer0.BgImage.Center Then
  110.                         pnlCanavas.BackgroundImageLayout = ImageLayout.Center
  111.                     Else
  112.                         pnlCanavas.BackgroundImageLayout = ImageLayout.None
  113.                     End If
  114.                 End If
  115.             End If
  116.         End If
  117.         pnlCanavas.Refresh()
  118.     End Sub
  119.  
  120.     Private Sub lstLayers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstLayers.SelectedIndexChanged
  121.         If lstLayers.SelectedIndices.Count = 0 Then
  122.             Exit Sub
  123.         End If
  124.  
  125.         Dim Layer As Layer = lstLayers.SelectedItems(0).Tag
  126.  
  127.         Label2.Text = "Oggetti livello '" & Layer.Name & "' :"
  128.         trwItems.Nodes.Clear()
  129.         For Each Item As FillableItem In Layer.Items
  130.             Dim T As New TreeNode
  131.             T.Tag = Item
  132.             T.ImageIndex = 1
  133.  
  134.             If TypeOf Item Is ClosedCurve Then
  135.                 T.Text = "Curva"
  136.             ElseIf TypeOf Item Is ClosedLine Then
  137.                 T.Text = "Spezzata"
  138.             Else
  139.                 T.Text = "Spezzata + Curva"
  140.             End If
  141.  
  142.             SetNodeInfo(Item, T)
  143.             trwItems.Nodes.Add(T)
  144.         Next
  145.     End Sub
  146.  
  147.     Private Sub strCurve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strCurve.Click
  148.         If lstLayers.SelectedIndices.Count = 0 Then
  149.             MessageBox.Show("Nessun livello selezionato!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  150.             Exit Sub
  151.         End If
  152.  
  153.         Dim Layer As Layer = lstLayers.SelectedItems(0).Tag
  154.  
  155.         CurveBuffer = New ClosedCurve
  156.         ActiveBuffer = CurveBuffer
  157.         Layer.Items.Add(CurveBuffer)
  158.         lstLayers_SelectedIndexChanged(Me, EventArgs.Empty)
  159.         chbMixCurve.Visible = False
  160.         lblStatus.Text = "Strumento curva"
  161.     End Sub
  162.  
  163.     Private Sub pnlCanavas_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlCanavas.MouseClick
  164.         If PickingColor Then
  165.             Dim B As New Bitmap(pnlCanavas.Width, pnlCanavas.Height)
  166.             Dim P As New Point(MousePosition.X - Me.Location.X - 5, MousePosition.Y - Me.Location.Y - 55)
  167.             Dim C As Color
  168.             pnlCanavas.DrawToBitmap(B, New Rectangle(0, 0, pnlCanavas.Width, pnlCanavas.Height))
  169.             C = B.GetPixel(P.X, P.Y)
  170.             imgSavedColor.BackColor = C
  171.             Me.Cursor = Cursors.Default
  172.             PickingColor = False
  173.             Exit Sub
  174.         End If
  175.  
  176.         If e.Button = Windows.Forms.MouseButtons.Left And ActiveBuffer IsNot Nothing Then
  177.             If (TypeOf ActiveBuffer Is ClosedCurve) Or (TypeOf ActiveBuffer Is ClosedLine) Then
  178.                 DirectCast(ActiveBuffer, PointConnectionItem).Points.Add( _
  179.                     New Point(MousePosition.X - Me.Location.X - 5, MousePosition.Y - Me.Location.Y - 55))
  180.             ElseIf TypeOf ActiveBuffer Is Mix Then
  181.                 DirectCast(ActiveBuffer, Mix).Points.Add(New MixPoint( _
  182.                     New Point(MousePosition.X - Me.Location.X - 5, MousePosition.Y - Me.Location.Y - 55), chbMixCurve.Checked))
  183.             End If
  184.  
  185.             pnlCanavas.Refresh()
  186.         End If
  187.     End Sub
  188.  
  189.     Private Sub pnlCanavas_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pnlCanavas.Paint
  190.         Dim Temp As New List(Of Layer)
  191.         e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
  192.         For Each L As ListViewItem In lstLayers.CheckedItems
  193.             Dim Layer As Layer = L.Tag
  194.             Temp.Add(Layer)
  195.         Next
  196.         Temp.Sort(New LayerByIndexComparer)
  197.         For Each L As Layer In Temp
  198.             L.Draw(e.Graphics)
  199.         Next
  200.     End Sub
  201.  
  202.     Private Sub trwItems_NodeMouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles trwItems.NodeMouseDoubleClick
  203.         Dim Item As FillableItem = e.Node.Tag
  204.  
  205.         If e.Node.Parent IsNot Nothing Then
  206.             Exit Sub
  207.         End If
  208.  
  209.         Dim Dialog As New ItemPropertiesDialog(Item)
  210.         If Dialog.ShowDialog = Windows.Forms.DialogResult.OK Then
  211.             With Item
  212.                 .Color = Dialog.OutlineColor
  213.                 .DrawOutline = Dialog.DrawOutline
  214.                 .Fill = Dialog.Fill
  215.                 .FillColor = Dialog.FillColor
  216.                 .Width = Dialog.OutlineWidth
  217.             End With
  218.             SetNodeInfo(Item, e.Node)
  219.             pnlCanavas.Refresh()
  220.         End If
  221.     End Sub
  222.  
  223.     Private Sub strDelLayer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strDelLayer.Click
  224.         If lstLayers.SelectedIndices.Count = 0 Then
  225.             Exit Sub
  226.         End If
  227.  
  228.         If lstLayers.SelectedIndices(0) = 0 Then
  229.             MessageBox.Show("Impossibile eliminare il livello di sfondo!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  230.             Exit Sub
  231.         End If
  232.  
  233.         lstLayers.Items.RemoveAt(lstLayers.SelectedIndices(0))
  234.         Me.Refresh()
  235.     End Sub
  236.  
  237.     Private Sub strLayerProperties_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strLayerProperties.Click
  238.         If lstLayers.SelectedIndices.Count = 0 Then
  239.             Exit Sub
  240.         End If
  241.  
  242.         If lstLayers.SelectedIndices(0) = 0 Then
  243.             Dim N As New NewDrawingDialog
  244.             Dim Layer0 As Layer = lstLayers.SelectedItems(0).Tag
  245.             Dim LItem As ListViewItem = lstLayers.SelectedItems(0)
  246.  
  247.             If Layer0.BgImage IsNot Nothing Then
  248.                 N.BgImage = Layer0.BgImage.BufferImage
  249.                 N.trkAlpha.Value = Layer0.BgImage.Alpha
  250.                 N.chbCenter.Checked = Layer0.BgImage.Center
  251.             End If
  252.  
  253.             If Me.Text.Length >= "Curve Art - ".Length Then
  254.                 N.txtName.Text = Me.Text.Remove(0, "Curve Art - ".Length)
  255.             End If
  256.  
  257.             If N.ShowDialog = Windows.Forms.DialogResult.OK Then
  258.                 Dim BG As New BackgroundImage
  259.                 BG.Image = N.BgImage
  260.                 BG.Center = N.Center
  261.                 BG.Zoom = N.Zoom
  262.                 BG.Alpha = N.Alpha
  263.                 BG.CreateBuffer()
  264.                 pnlCanavas.BackgroundImage = BG.BufferImage
  265.                 If BG.Center Then
  266.                     pnlCanavas.BackgroundImageLayout = ImageLayout.Center
  267.                 End If
  268.                 Me.Text = "Curva Art - " & N.DrawingName
  269.  
  270.                 Layer0.BgImage = BG
  271.                 Layer0.Index = 0
  272.                 pnlCanavas.Refresh()
  273.             End If
  274.             Exit Sub
  275.         End If
  276.  
  277.         Try
  278.             Dim Layer As Layer = lstLayers.SelectedItems(0).Tag
  279.             Dim NewIndex As Int32 = _
  280.                 InputBox("L'indice di rendering di questo livello è " & Layer.Index & ". Inserire un nuovo indice:", Me.Text)
  281.             Layer.Index = NewIndex
  282.             SetItemInfo(Layer, lstLayers.SelectedItems(0))
  283.         Catch Ex As Exception
  284.         End Try
  285.     End Sub
  286.  
  287.     Private Sub strNewDrawing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strNewDrawing.Click
  288.         If lstLayers.Items.Count > 0 Then
  289.             Dim Result As DialogResult
  290.             Result = MessageBox.Show("C'è un altro disegno in corso. Salvarlo prima di continuare?", Me.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
  291.  
  292.             If Result = Windows.Forms.DialogResult.Yes Then
  293.                 strSave_Click(Me, EventArgs.Empty)
  294.             ElseIf Result = Windows.Forms.DialogResult.Cancel Then
  295.                 Exit Sub
  296.             End If
  297.         End If
  298.  
  299.         Dim N As New NewDrawingDialog
  300.         If N.ShowDialog = Windows.Forms.DialogResult.OK Then
  301.             Dim BG As New BackgroundImage
  302.             BG.Image = N.BgImage
  303.             BG.Center = N.Center
  304.             BG.Zoom = N.Zoom
  305.             BG.Alpha = N.Alpha
  306.             BG.CreateBuffer()
  307.             pnlCanavas.BackgroundImage = BG.BufferImage
  308.             If BG.Center Then
  309.                 pnlCanavas.BackgroundImageLayout = ImageLayout.Center
  310.             End If
  311.             Me.Text = "Curve Art - " & N.DrawingName
  312.  
  313.             Dim Layer0 As New Layer
  314.             Dim L As New ListViewItem
  315.             Layer0.Name = "Sfondo"
  316.             Layer0.BgImage = BG
  317.             Layer0.Index = 0
  318.             SetItemInfo(Layer0, L)
  319.             MaxIndex = 1
  320.  
  321.             lstLayers.Items.Add(L)
  322.             pnlCanavas.Refresh()
  323.         End If
  324.     End Sub
  325.  
  326.     Private Sub strUndo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strUndo.Click
  327.         If ActiveBuffer IsNot Nothing Then
  328.             Dim Un As IUndoable = ActiveBuffer
  329.             Un.Undo()
  330.             pnlCanavas.Refresh()
  331.         End If
  332.     End Sub
  333.  
  334.     Private Sub strCloseFigure_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strCloseFigure.Click
  335.         If ActiveBuffer IsNot Nothing Then
  336.             Dim Cl As ICloseable = ActiveBuffer
  337.             Cl.IsClosed = True
  338.             pnlCanavas.Refresh()
  339.         End If
  340.     End Sub
  341.  
  342.     Private Sub strLine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strLine.Click
  343.         If lstLayers.SelectedIndices.Count = 0 Then
  344.             MessageBox.Show("Nessun livello selezionato!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  345.             Exit Sub
  346.         End If
  347.  
  348.         Dim Layer As Layer = lstLayers.SelectedItems(0).Tag
  349.  
  350.         LineBuffer = New ClosedLine
  351.         ActiveBuffer = LineBuffer
  352.         Layer.Items.Add(LineBuffer)
  353.         lstLayers_SelectedIndexChanged(Me, EventArgs.Empty)
  354.         chbMixCurve.Visible = False
  355.         lblStatus.Text = "Strumento Spezzata"
  356.     End Sub
  357.  
  358.     Private Sub strMix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strMix.Click
  359.         If lstLayers.SelectedIndices.Count = 0 Then
  360.             MessageBox.Show("Nessun livello selezionato!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  361.             Exit Sub
  362.         End If
  363.  
  364.         Dim Layer As Layer = lstLayers.SelectedItems(0).Tag
  365.  
  366.         MixBuffer = New Mix
  367.         ActiveBuffer = MixBuffer
  368.         Layer.Items.Add(MixBuffer)
  369.         lstLayers_SelectedIndexChanged(Me, EventArgs.Empty)
  370.         chbMixCurve.Visible = True
  371.         lblStatus.Text = "Strumento Curva + Spezzata"
  372.     End Sub
  373.  
  374.     Private Sub trwItems_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles trwItems.AfterSelect
  375.         If trwItems.SelectedNode Is Nothing Then
  376.             Exit Sub
  377.         End If
  378.  
  379.         Dim Selected As TreeNode = trwItems.SelectedNode
  380.  
  381.         If Selected.Parent IsNot Nothing Then
  382.             Selected = Selected.Parent
  383.         End If
  384.  
  385.         ActiveBuffer = Selected.Tag
  386.     End Sub
  387.  
  388.     Private Sub strDelItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strDelItem.Click
  389.         If trwItems.SelectedNode Is Nothing Then
  390.             MessageBox.Show("Nessun oggetto selezionato!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  391.             Exit Sub
  392.         End If
  393.  
  394.         Dim Selected As TreeNode = trwItems.SelectedNode
  395.  
  396.         If Selected.Parent IsNot Nothing Then
  397.             MessageBox.Show("Nessun oggetto selezionato!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  398.             Exit Sub
  399.         End If
  400.  
  401.         Dim Layer As Layer = lstLayers.SelectedItems(0).Tag
  402.         Layer.Items.Remove(Selected.Tag)
  403.         trwItems.Nodes.Remove(Selected)
  404.         pnlCanavas.Refresh()
  405.     End Sub
  406.  
  407.     Private Sub strSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSave.Click
  408.         If lstLayers.Items.Count = 0 Then
  409.             MessageBox.Show("Non c'è niente da salvare.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
  410.             Exit Sub
  411.         End If
  412.  
  413.         Dim Save As New SaveFileDialog
  414.         Save.Filter = "Immagine JPEG|*.jpg|Immagine Bitmap|*.bmp|Immagine PNG|*.png|Immagine GIF|*.gif|Immagine TIFF|*.tif|Immagine WMF|*.wmf|File progetto di Curve Art|*.cva"
  415.         If Save.ShowDialog = Windows.Forms.DialogResult.OK Then
  416.             If Save.FilterIndex = 7 Then
  417.                 Dim Serializer As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
  418.                 Dim Current As New Project
  419.                 Dim Stream As New IO.FileStream(Save.FileName, IO.FileMode.Create)
  420.  
  421.                 Current.PickedColor = imgSavedColor.BackColor
  422.                 Current.CanavasWidth = splitMain.SplitterDistance
  423.                 Current.WindowState = Me.WindowState
  424.                 Current.WindowSize = Me.Size
  425.                 If Me.Text.Length >= "Curve Art - ".Length Then
  426.                     Current.Name = Me.Text.Replace(0, "Curve Art - ".Length)
  427.                 End If
  428.                 For Each L As ListViewItem In lstLayers.Items
  429.                     Current.Layers.Add(L.Tag)
  430.                 Next
  431.                 Serializer.Serialize(Stream, Current)
  432.                 Stream.Close()
  433.             Else
  434.                 SaveDrawing(Save.FileName)
  435.             End If
  436.         End If
  437.     End Sub
  438.  
  439.     Private Sub strOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strOpen.Click
  440.         If lstLayers.Items.Count > 0 Then
  441.             Dim Result As DialogResult
  442.             Result = MessageBox.Show("C'è un altro disegno in corso. Salvarlo prima di continuare?", Me.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
  443.  
  444.             If Result = Windows.Forms.DialogResult.Yes Then
  445.                 strSave_Click(Me, EventArgs.Empty)
  446.             ElseIf Result = Windows.Forms.DialogResult.Cancel Then
  447.                 Exit Sub
  448.             End If
  449.         End If
  450.  
  451.         Dim Open As New OpenFileDialog
  452.         Open.Filter = "File progetto di Curve Art|*.cva"
  453.         If Open.ShowDialog = Windows.Forms.DialogResult.OK Then
  454.             Dim Serializer As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
  455.             Dim Proj As Project
  456.             Dim Stream As New IO.FileStream(Open.FileName, IO.FileMode.Open)
  457.  
  458.             Proj = Serializer.Deserialize(Stream)
  459.             Stream.Close()
  460.             lstLayers.Items.Clear()
  461.             trwItems.Nodes.Clear()
  462.  
  463.             With Proj
  464.                 If .WindowState = FormWindowState.Normal Then
  465.                     Me.Size = .WindowSize
  466.                 Else
  467.                     Me.WindowState = .WindowState
  468.                 End If
  469.                 imgSavedColor.BackColor = .PickedColor
  470.                 splitMain.SplitterDistance = .CanavasWidth
  471.                 Me.Text = "Curve Art - " & .Name
  472.             End With
  473.             For Each Layer As Layer In Proj.Layers
  474.                 Dim L As New ListViewItem
  475.                 SetItemInfo(Layer, L)
  476.                 lstLayers.Items.Add(L)
  477.                 If Layer.Index > MaxIndex * 10 Then
  478.                     MaxIndex = Layer.Index \ 10 + 2
  479.                 End If
  480.             Next
  481.         End If
  482.     End Sub
  483.  
  484.     Private Sub strColorPicker_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strColorPicker.Click
  485.         PickingColor = True
  486.         Me.Cursor = Cursors.Cross
  487.         lblStatus.Text = "Strumento Preleva"
  488.     End Sub
  489.  
  490.     Private Sub strOpenFigure_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strOpenFigure.Click
  491.         If ActiveBuffer IsNot Nothing Then
  492.             Dim Cl As ICloseable = ActiveBuffer
  493.             Cl.IsClosed = False
  494.             pnlCanavas.Refresh()
  495.         End If
  496.     End Sub
  497.  
  498.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  499.         Dim Args As Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
  500.  
  501.         AddHandler My.Application.UnhandledException, AddressOf Exception_Manager
  502.  
  503.         RegisterIcon()
  504.         If Args.Count > 0 Then
  505.             Dim FileName As String = Args(0)
  506.  
  507.             Dim Serializer As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
  508.             Dim Proj As New Project
  509.             Dim Stream As New IO.FileStream(FileName, IO.FileMode.Open)
  510.  
  511.             Proj = Serializer.Deserialize(Stream)
  512.             Stream.Close()
  513.             lstLayers.Items.Clear()
  514.             trwItems.Nodes.Clear()
  515.  
  516.             With Proj
  517.                 If .WindowState = FormWindowState.Normal Then
  518.                     Me.Size = .WindowSize
  519.                 Else
  520.                     Me.WindowState = .WindowState
  521.                 End If
  522.                 imgSavedColor.BackColor = .PickedColor
  523.                 splitMain.SplitterDistance = .CanavasWidth
  524.                 Me.Text = "Curve Art - " & .Name
  525.             End With
  526.             For Each Layer As Layer In Proj.Layers
  527.                 Dim L As New ListViewItem
  528.                 SetItemInfo(Layer, L)
  529.                 lstLayers.Items.Add(L)
  530.                 If Layer.Index > MaxIndex * 10 Then
  531.                     MaxIndex = Layer.Index \ 10 + 2
  532.                 End If
  533.             Next
  534.         End If
  535.     End Sub
  536.  
  537.     Private Sub strExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strExit.Click
  538.         If lstLayers.Items.Count > 0 Then
  539.             Dim Result As DialogResult
  540.             Result = MessageBox.Show("C'è un altro disegno in corso. Salvarlo prima di uscire?", Me.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
  541.  
  542.             If Result = Windows.Forms.DialogResult.Yes Then
  543.                 strSave_Click(Me, EventArgs.Empty)
  544.             ElseIf Result = Windows.Forms.DialogResult.Cancel Then
  545.                 Exit Sub
  546.             End If
  547.             Me.Close()
  548.         End If
  549.     End Sub
  550.  
  551.     Private Sub strAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAbout.Click
  552.         My.Forms.The_Lair_AboutBox1.ShowDialog()
  553.     End Sub
  554.  
  555.     Private Sub strSortLevel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSortLevel.Click
  556.         Dim Layers As New List(Of ListViewItem)
  557.  
  558.         For Each L As ListViewItem In lstLayers.Items
  559.             Layers.Add(L)
  560.         Next
  561.  
  562.         Layers.Sort(New ItemByIndexComparer())
  563.         lstLayers.Items.Clear()
  564.  
  565.         For Each L As ListViewItem In Layers
  566.             lstLayers.Items.Add(L)
  567.         Next
  568.     End Sub
  569.  
  570.     Private Sub strListDetails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strListDetails.Click
  571.         If lstLayers.View = View.List Then
  572.             lstLayers.View = View.Details
  573.             strListDetails.Text = "Lista"
  574.         Else
  575.             lstLayers.View = View.List
  576.             strListDetails.Text = "Dettagli"
  577.         End If
  578.     End Sub
  579.  
  580.     Private Sub strCheckAllLayers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strCheckAllLayers.Click
  581.         For Each L As ListViewItem In lstLayers.Items
  582.             L.Checked = True
  583.         Next
  584.         pnlCanavas.Refresh()
  585.     End Sub
  586.  
  587.     Private Sub strUncheckAllLayers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strUncheckAllLayers.Click
  588.         For Each L As ListViewItem In lstLayers.Items
  589.             L.Checked = False
  590.         Next
  591.         pnlCanavas.Refresh()
  592.     End Sub
  593.  
  594.     Private Sub strDupeItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strDupeItem.Click
  595.         If trwItems.SelectedNode Is Nothing Then
  596.             MessageBox.Show("Nessun oggetto selezionato!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  597.             Exit Sub
  598.         End If
  599.  
  600.         Dim Selected As TreeNode = trwItems.SelectedNode
  601.         Dim Copy As TreeNode = Selected.Clone
  602.         trwItems.Nodes.Add(Copy)
  603.     End Sub
  604.  
  605.     Private Sub strCopyPoints_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strCopyPoints.Click
  606.         If trwItems.SelectedNode Is Nothing Then
  607.             MessageBox.Show("Nessun oggetto selezionato!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  608.             Exit Sub
  609.         End If
  610.  
  611.         Dim Selected As TreeNode = trwItems.SelectedNode
  612.         Dim Item As FillableItem = Selected.Tag
  613.         Dim PDialog As New CopyPointsDialog(Item)
  614.  
  615.         If PDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
  616.             CopiedItem = PDialog.FinalItem
  617.         End If
  618.     End Sub
  619.  
  620.     Private Sub strPastePoints_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strPastePoints.Click
  621.         If lstLayers.SelectedIndices.Count = 0 Then
  622.             MessageBox.Show("Nessun livello selezionato!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  623.             Exit Sub
  624.         End If
  625.  
  626.         If CopiedItem Is Nothing Then
  627.             MessageBox.Show("Non sono stati copiati punti da incollare!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  628.             Exit Sub
  629.         End If
  630.  
  631.         Dim Layer As Layer = lstLayers.SelectedItems(0).Tag
  632.  
  633.         Layer.Items.Add(CopiedItem)
  634.         lstLayers_SelectedIndexChanged(Me, EventArgs.Empty)
  635.         If TypeOf CopiedItem Is Mix Then
  636.             chbMixCurve.Checked = True
  637.         End If
  638.         lblStatus.Text = "Punti copiati sul livello '" & Layer.Name & "'"
  639.     End Sub
  640.  
  641.     Private Sub Exception_Manager(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs)
  642.         Dim ErrorData As String
  643.  
  644.         ErrorData = e.Exception.GetType.FullName & vbCrLf
  645.         ErrorData &= e.Exception.Message & vbCrLf & vbCrLf
  646.         MessageBox.Show(ErrorData & "Si è verificato un errore nell'applicazione. Contattare lo sviluppatore.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  647.         e.ExitApplication = False
  648.     End Sub
  649. End Class