Esempio n. 1
0
        /// <summary>
        /// Draws the item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.DrawItemEventArgs"/> instance containing the event data.</param>
        /// <param name="itemIsDropped">if set to <c>true</c> item is dropped.</param>
        private void DrawItem(KillLogItem item, DrawItemEventArgs e, bool itemIsDropped = false)
        {
            Graphics g = e.Graphics;

            // Draw background
            g.FillRectangle(itemIsDropped ? Brushes.Green : Brushes.LightGray, e.Bounds);

            int itemQty        = itemIsDropped ? item.QtyDropped : item.QtyDestroyed;
            int inContainerPad = item.IsInContainer ? PadLeft * 2 : 0;

            // Texts size measure
            Size itemTextSize    = TextRenderer.MeasureText(g, item.Name, m_fittingFont, Size.Empty, Format);
            Size itemQtyTextSize = TextRenderer.MeasureText(g, itemQty.ToNumericString(0), m_fittingFont);

            Rectangle itemTextRect = new Rectangle(e.Bounds.Left + inContainerPad + PadLeft * 2 + ItemImageSize,
                                                   e.Bounds.Top + (e.Bounds.Height - itemTextSize.Height) / 2,
                                                   itemTextSize.Width + PadRight, itemTextSize.Height);
            Rectangle itemQtyTextRect = new Rectangle(e.Bounds.Right - itemQtyTextSize.Width - PadRight,
                                                      e.Bounds.Top + (e.Bounds.Height - itemTextSize.Height) / 2,
                                                      itemQtyTextSize.Width + PadRight, itemQtyTextSize.Height);

            // Draw texts
            TextRenderer.DrawText(g, item.Name, m_fittingFont, itemTextRect, Color.Black);
            TextRenderer.DrawText(g, itemQty.ToNumericString(0), m_fittingFont, itemQtyTextRect, Color.Black);

            // Draw the image
            if (Settings.UI.SafeForWork)
            {
                return;
            }

            g.DrawImage(item.ItemImage, new Rectangle(e.Bounds.Left + inContainerPad + PadLeft * 2,
                                                      e.Bounds.Top + (e.Bounds.Height - ItemImageSize) / 2,
                                                      ItemImageSize, ItemImageSize));
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the MouseDown event of the FittingContentListBox control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
        private void FittingContentListBox_MouseDown(object sender, MouseEventArgs e)
        {
            // Retrieve the item at the given point and quit if none
            int index = FittingContentListBox.IndexFromPoint(e.Location);

            if (index < 0 || index >= FittingContentListBox.Items.Count)
            {
                return;
            }

            KillLogItem killLogItem = FittingContentListBox.Items[index] as KillLogItem;

            // Beware, this last index may actually means a click in the whitespace at the bottom
            // Let's deal with this special case
            if (index == FittingContentListBox.Items.Count - 1)
            {
                Rectangle itemRect = FittingContentListBox.GetItemRectangle(index);
                if (!itemRect.Contains(e.Location))
                {
                    killLogItem = null;
                }
            }

            if (e.Button != MouseButtons.Right)
            {
                return;
            }

            // Right click reset the cursor
            FittingContentListBox.Cursor = Cursors.Default;

            // Set the selected item
            m_selectedItem = killLogItem?.Item;

            // Display the context menu
            contextMenuStrip.Show(FittingContentListBox, e.Location);
        }
Esempio n. 3
0
        /// <summary>
        /// Handles the DrawItem event of the FittingContentListBox control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.DrawItemEventArgs"/> instance containing the event data.</param>
        private void FittingContentListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0 || e.Index >= FittingContentListBox.Items.Count)
            {
                return;
            }

            object      listItem = FittingContentListBox.Items[e.Index];
            KillLogItem item     = listItem as KillLogItem;

            if (item != null)
            {
                // If item is the same with previous item then we previously have drawn a destroyed item
                // and now we need to draw a dropped one
                if (FittingContentListBox.Items[e.Index - 1] == item)
                {
                    DrawItem(item, e, true);
                }
                else
                {
                    // Draw a destroyed item or dropped one
                    if (item.QtyDestroyed > 0)
                    {
                        DrawItem(item, e);
                    }
                    else
                    {
                        DrawItem(item, e, true);
                    }
                }
            }
            else
            {
                DrawItem((KillLogFittingContentGroup)listItem, e);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Adds the item.
        /// </summary>
        /// <param name="item">The item.</param>
        private void AddItem(KillLogItem item)
        {
            bool eventHandlerAdded = false;

            // Add if the item was destroyed
            if (item.QtyDestroyed > 0)
            {
                FittingContentListBox.Items.Add(item);
                item.KillLogItemImageUpdated += item_KillLogItemImageUpdated;
                eventHandlerAdded             = true;
            }

            // Re-add if the item was also dropped
            if (item.QtyDropped <= 0)
            {
                return;
            }

            FittingContentListBox.Items.Add(item);
            if (!eventHandlerAdded)
            {
                item.KillLogItemImageUpdated += item_KillLogItemImageUpdated;
            }
        }