/// <summary> /// ラベル項目描画時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void OnTechLabelPaint(object sender, PaintEventArgs e) { Label label = sender as Label; TechLabelInfo info = label?.Tag as TechLabelInfo; TechLabel labelItem = info?.Item as TechLabel; string s = labelItem?.ToString(); if (string.IsNullOrEmpty(s)) { return; } // 色指定文字列を解釈する Brush brush; if ((s[0] == '%' || s[0] == 'ァ' || s[0] == '§') && s.Length > 4 && s[1] >= '0' && s[1] <= '9' && s[2] >= '0' && s[2] <= '9' && s[3] >= '0' && s[3] <= '9') { brush = new SolidBrush(Color.FromArgb((s[3] - '0') << 5, (s[2] - '0') << 5, (s[1] - '0') << 5)); s = s.Substring(4); } else { brush = new SolidBrush(Color.White); } e.Graphics.DrawString(s, label.Font, brush, -2, 0); brush.Dispose(); }
/// <summary> /// 項目ラベルマウスダウン時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnItemLabelMouseDown(object sender, MouseEventArgs e) { Label label = sender as Label; TechLabelInfo info = label?.Tag as TechLabelInfo; if (info == null) { return; } // ドラッグアンドドロップの開始準備 if (AllowDragDrop) { // 左ボタンダウンでなければドラッグ状態を解除する if (e.Button != MouseButtons.Left) { _dragPoint = Point.Empty; Cursor.Current = Cursors.Default; return; } // ドラッグ開始位置を設定する _dragPoint = new Point(label.Left + e.X, label.Top + e.Y); } // イベントハンドラを呼び出す ItemMouseDown?.Invoke(sender, new ItemMouseEventArgs(info.Item, info.Position, e)); }
/// <summary> /// 項目ラベルマウスクリック時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnItemLabelMouseClick(object sender, MouseEventArgs e) { // イベントハンドラを呼び出す if (ItemMouseClick != null) { Label label = sender as Label; TechLabelInfo info = label?.Tag as TechLabelInfo; if (info == null) { return; } ItemMouseClick(sender, new ItemMouseEventArgs(info.Item, info.Position, e)); } }
/// <summary> /// 技術ツリーの項目を更新する /// </summary> /// <param name="item">更新対象の項目</param> /// <param name="position">更新対象の座標</param> public void UpdateItem(ITechItem item, TechPosition position) { Control.ControlCollection labels = _pictureBox.Controls; foreach (Label label in labels) { TechLabelInfo info = label.Tag as TechLabelInfo; if (info == null) { continue; } if (info.Item != item) { continue; } // ラベルの位置を更新する if (info.Position == position) { label.Location = new Point(DeviceCaps.GetScaledWidth(position.X), DeviceCaps.GetScaledHeight(position.Y)); } // 項目ラベルの表示に項目の状態を反映しないならば座標変更のみ if (!ApplyItemStatus || (QueryItemStatus == null)) { continue; } if (item is TechItem) { // ラベル画像を設定する QueryItemStatusEventArgs e = new QueryItemStatusEventArgs(item); QueryItemStatus(this, e); label.Image = e.Done ? (e.Blueprint ? _blueprintDoneTechLabelBitmap : _doneTechLabelBitmap) : (e.Blueprint ? _blueprintTechLabelBitmap : _techLabelBitmap); } else if (item is TechEvent) { // ラベル画像を設定する QueryItemStatusEventArgs e = new QueryItemStatusEventArgs(item); QueryItemStatus(this, e); label.Image = e.Done ? _doneEventLabelBitmap : _eventLabelBitmap; } } }
/// <summary> /// 技術ツリーの項目ラベルを更新する /// </summary> /// <param name="item">更新対象の項目</param> public void UpdateItem(ITechItem item) { Control.ControlCollection labels = _pictureBox.Controls; foreach (Label label in labels) { TechLabelInfo info = label.Tag as TechLabelInfo; if (info == null) { continue; } if (info.Item != item) { continue; } // ラベル項目の場合はサイズを再計算する if (item is TechLabel) { label.Size = Graphics.FromHwnd(label.Handle).MeasureString(item.ToString(), label.Font).ToSize(); } // 項目ラベルの表示に項目の状態を反映しないならば再描画のみ if (!ApplyItemStatus || (QueryItemStatus == null)) { label.Refresh(); continue; } if (item is TechItem) { // ラベル画像を設定する QueryItemStatusEventArgs e = new QueryItemStatusEventArgs(item); QueryItemStatus(this, e); label.Image = e.Done ? (e.Blueprint ? _blueprintDoneTechLabelBitmap : _doneTechLabelBitmap) : (e.Blueprint ? _blueprintTechLabelBitmap : _techLabelBitmap); } else if (item is TechEvent) { // ラベル画像を設定する QueryItemStatusEventArgs e = new QueryItemStatusEventArgs(item); QueryItemStatus(this, e); label.Image = e.Done ? _doneEventLabelBitmap : _eventLabelBitmap; } } }
/// <summary> /// 技術項目描画時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void OnTechItemPaint(object sender, PaintEventArgs e) { Label label = sender as Label; TechLabelInfo info = label?.Tag as TechLabelInfo; TechItem techItem = info?.Item as TechItem; string s = techItem?.GetShortName(); if (string.IsNullOrEmpty(s)) { return; } Brush brush = new SolidBrush(Color.Black); e.Graphics.DrawString(s, label.Font, brush, 6, 2); brush.Dispose(); }
/// <summary> /// 技術ツリーの項目を削除する /// </summary> /// <param name="item">削除対象の項目</param> /// <param name="position">削除対象の位置</param> public void RemoveItem(ITechItem item, TechPosition position) { Control.ControlCollection labels = _pictureBox.Controls; foreach (Label label in labels) { TechLabelInfo info = label.Tag as TechLabelInfo; if (info == null) { continue; } if (info.Item == item && info.Position == position) { _pictureBox.Controls.Remove(label); } } }
/// <summary> /// 技術ツリーピクチャーボックスにドロップした時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnPictureBoxDragDrop(object sender, DragEventArgs e) { // ドラッグアンドドロップが無効ならば何もしない if (!AllowDragDrop) { return; } // ラベルでなければ何もしない if (!e.Data.GetDataPresent(typeof(Label))) { return; } Label label = e.Data.GetData(typeof(Label)) as Label; if (label == null) { return; } // 技術ツリー上のドロップ座標を計算する Point p = new Point(e.X, e.Y); p = _pictureBox.PointToClient(p); p.X = label.Left + p.X - _dragPoint.X; p.Y = label.Top + p.Y - _dragPoint.Y; // ラベル情報の座標を更新する TechLabelInfo info = label.Tag as TechLabelInfo; if (info == null) { return; } info.Position.X = DeviceCaps.GetUnscaledWidth(p.X); info.Position.Y = DeviceCaps.GetUnscaledHeight(p.Y); // ラベルの座標を更新する label.Location = p; // イベントハンドラを呼び出す ItemDragDrop?.Invoke(this, new ItemDragEventArgs(info.Item, info.Position, e)); }
/// <summary> /// 項目ラベルマウス移動時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnItemLabelMouseMove(object sender, MouseEventArgs e) { // ドラッグアンドドロップが無効ならば何もしない if (!AllowDragDrop) { return; } // ドラッグ中でなければ何もしない if (_dragPoint == Point.Empty) { return; } Label label = sender as Label; if (label == null) { return; } // ドラッグ判定サイズを超えていなければ何もしない Size dragSize = SystemInformation.DragSize; Rectangle dragRect = new Rectangle(_dragPoint.X - dragSize.Width / 2, _dragPoint.Y - dragSize.Height / 2, dragSize.Width, dragSize.Height); if (dragRect.Contains(label.Left + e.X, label.Top + e.Y)) { return; } TechLabelInfo info = label.Tag as TechLabelInfo; if (info == null) { return; } // カーソル画像を作成する Bitmap bitmap = new Bitmap(label.Width, label.Height); bitmap.MakeTransparent(bitmap.GetPixel(0, 0)); label.DrawToBitmap(bitmap, new Rectangle(0, 0, label.Width, label.Height)); if (info.Item is TechItem) { _dragCursor = CursorFactory.CreateCursor(bitmap, _techLabelMask, _dragPoint.X - label.Left, _dragPoint.Y - label.Top); } else if (info.Item is TechLabel) { _dragCursor = CursorFactory.CreateCursor(bitmap, _dragPoint.X - label.Left, _dragPoint.Y - label.Top); } else { _dragCursor = CursorFactory.CreateCursor(bitmap, _eventLabelMask, _dragPoint.X - label.Left, _dragPoint.Y - label.Top); } // ドラッグアンドドロップを開始する label.DoDragDrop(sender, DragDropEffects.Move); // ドラッグ状態を解除する _dragPoint = Point.Empty; _dragCursor.Dispose(); bitmap.Dispose(); }