//──────────────────────────────────────── /// <summary> /// マウスアップ /// </summary> /// <param name="e"></param> /// <param name="modelOfSpriteDic"></param> public void OnMouseUpped( MouseEventArgs e, Point parentLocation, MemorySpriteDictionary spriteDictionaryModel ) { // ドラッグしている画像を離します。 foreach (Sprite sprite in spriteDictionaryModel.Dictionary_Sprite.Values) { sprite.BDragging = false; } // 選択解除の要求が利いていれば、画像選択を切り替えます。 foreach (Sprite sprite in spriteDictionaryModel.Dictionary_Sprite.Values) { if (sprite.BSelectToggled) { sprite.BSelected = !sprite.BSelected; // // ■スプライトの選択状態変化 // spriteDictionaryModel.Dlgt_OnSpriteSelectionChangedPerform( sprite, parentLocation ); } } }
//──────────────────────────────────────── #endregion #region イベントハンドラー //──────────────────────────────────────── /// <summary> /// マウスに重なっている画像をドラッグできる状態にします。 /// </summary> /// <param name="e"></param> /// <param name="modelOfSpriteDic"></param> public void OnMouseDowned( MouseEventArgs e, Point o_OLt, MemorySpriteDictionary moSpDic ) { // リストの後ろから判定します。 int nSpriteCount = moSpDic.List_SpriteZOrder.Count; for (int nSpriteIndex = nSpriteCount - 1; nSpriteIndex >= 0; nSpriteIndex--) { Sprite sprite = moSpDic.List_SpriteZOrder[nSpriteIndex].Value; if (sprite.BoundsLefttopScaled.Contains( e.Location.X - o_OLt.X, e.Location.Y - o_OLt.Y )) { // ドラッグ開始 sprite.BDragging = true;// どこでfalseにしてる? // クリックした画像内の座標と、画像の左上隅座標との差を求めます。 this.grabbedLefttopInImg = new Point( e.X - sprite.BoundsLefttopScaled.X - o_OLt.X, e.Y - sprite.BoundsLefttopScaled.Y - o_OLt.Y ); // 最初の1件を見つけた時点で終了します。 break; } } // マウスに重なっている画像の選択/非選択を切り替える可能性が発生します。マウス・ムーブを挟むと、切り替えの意思を解除。 moSpDic.CheckSelectToggledAll( e.Location, o_OLt ); }
//──────────────────────────────────────── /// <summary> /// スプライト ドラッグ中 /// </summary> private void OnSpriteDragging( Point o_OLt, MemorySpriteDictionary moSpDic, Point zure ) { //.Console.WriteLine(this.GetType().Name + "#OnSpriteDragging: pointedLocation=(" + this.pointedLocation.X + ", " + this.pointedLocation.Y + ") ずれ("+zure.X+", "+zure.Y+")"); // スプライト左上座標=(" + spriteLeftTopLocation.X + ", " + spriteLeftTopLocation.Y + ") // マウス ターゲットがどれほど移動するか、移動距離を算出します。 // スプライトの移動量は、「ずらしたスプライト」で計算します。 // (※マウスで今抑えているスプライトと、それ以外の選択スプライトでは計算方法が変わります。) int nDx = 0; int nDy = 0; // 選択されている画像がドラッグされているのなら、他の選択されている画像も一緒に動きます。 // 選択されていない画像がドラッグされているのなら、他の画像は動きません。 bool bSelectedOfDraggingImage = false; { foreach (Sprite sprite in moSpDic.Dictionary_Sprite.Values) { if (sprite.BDragging) { if (sprite.BMouseTarget) { // ドラッグしており、かつマウス ターゲットになっているスプライトがあれば(1つだけ存在する?) // // グリッドのクロスポイントからはズレていることがある。 int nXInAreaZure = this.mouseLefttopOnGrid.X - o_OLt.X; int nYInAreaZure = this.mouseLefttopOnGrid.Y - o_OLt.Y; // // X // // 画像の左上隅の位置を動かすので、マウスカーソルの位置から、画像内座標を引いて、左上隅の座標を算出します。 nDx = nXInAreaZure - this.grabbedLefttopInImg.X - sprite.BoundsLefttopScaled.X; // マウスカーソルにぴったりと くっついてくる計算式。 // nDx = nXInArea - this.grabbedLocationInImage.X - sprite.BoundsLtScaled.X - zure.X; // マウスカーソルに、左上隅が ぴったりと くっついてくる計算式。 // nDx = nXInArea - sprite.BoundsLtScaled.X - zure.X; //.Console.WriteLine(this.GetType().Name + "#OnSpriteDragging: translateX[" + translateX + "] = xInArea[" + xInArea + "] - this.grabbedLocationInImage.X[" + this.grabbedLocationInImage.X + "] - sprite.BoundsLtScaled.X[" + sprite.BoundsLtScaled.X + "]"); // // Y // nDy = nYInAreaZure - this.grabbedLefttopInImg.Y - sprite.BoundsLefttopScaled.Y; // -8 ほどずれてる。 // マウスカーソルにぴったりと くっついてくる計算式。 // nDy = nYInArea - this.grabbedLocationInImage.Y - sprite.BoundsLtScaled.Y - zure.Y; // マウスカーソルに、左上隅が ぴったりと くっついてくる計算式。 //nDy = nYInArea - sprite.BoundsLtScaled.Y - zure.Y; //.Console.WriteLine(this.GetType().Name + "#OnSpriteDragging: translateY[" + translateY + "] = yInArea[" + yInArea + "] - this.grabbedLocationInImage.Y[" + this.grabbedLocationInImage.Y + "] - sprite.BoundsLtScaled.Y[" + sprite.BoundsLtScaled.Y + "]"); } if (sprite.BSelected) { // ドラッグしており、かつ選択しているスプライトがあれば bSelectedOfDraggingImage = true; } } } } foreach (Sprite sprite in moSpDic.Dictionary_Sprite.Values) { // ドラッグ中か、ドラッグ中の画像として選択されていて、選択中のスプライトなら。 // その画像の位置を動かします。 if (sprite.BDragging || (bSelectedOfDraggingImage && sprite.BSelected)) { // 移動前、移動後の移動量チェック //int nPreX = sprite.BoundsLtOriginal.X; //int nPreY = sprite.BoundsLtOriginal.Y; //.Console.WriteLine(this.GetType().Name + "#OffsetLocationOfSelectedSprite: ▲ドラッグで移動 スプライト インデックス=[" + sprite.Index + "] 移動量=[" + translateX + ", " + translateY + "] スプライト左上[" + sprite.BoundsLtOriginal.X + ", " + sprite.BoundsLtOriginal.Y + "] ドラッグしてないときに動いてないか?"); //sprite.Dragging[" + sprite.Dragging + "] //selectedOfDraggingImage[" + selectedOfDraggingImage + "] //sprite.Selected[" + sprite.Selected + "] // // 画像の左上隅の位置を動かすので、マウスカーソルの位置から、画像内座標を引いて、左上隅の座標を算出します。 // // TODO スナップに吸着しているとき動かなくしたい。 sprite.OffsetLefttopLocation( nDx, nDy ); //int nMovedX = sprite.BoundsLtOriginal.X - nPreX; //int nMovedY = sprite.BoundsLtOriginal.Y - nPreY; //.Console.WriteLine(this.GetType().Name + "#OffsetLocationOfSelectedSprite: △ドラッグで移動後 スプライト インデックス=[" + sprite.Index + "] 移動した量[" + movedX + ", " + movedY + "]"); } } }
//──────────────────────────────────────── /// <summary> /// マウスムーブ /// </summary> /// <param name="e"></param> /// <param name="modelOfSpriteDic"></param> public void OnMouseMoved( MouseEventArgs e,//コントロールの中でのマウス座標 Point o_GridViewLt,//基本、(0,0)? MemorySpriteDictionary moSpDic ) { // マウスカーソルの座標を取得します。 this.mouseLocation.X = e.X; //スクリーン上での位置。 this.mouseLocation.Y = e.Y; // // マウスをドラッグしても、スナップ吸着していると スプライトが移動しないこともあります。 // スプライトが移動したら、真です。 // //bool moved = false; Point zure = Point.Empty;//ずれ。 if (this.BGridSnapped) { // グリッド・スナップが有効です。 // 全てのグリッド領域について、当たり判定を調査。 // TODO 先に有効なものがあれば、それを優先します。 //マウスカーソルの位置は、スプライト画像の適当な場所を掴んでいる。 int nSpWidth = 0; int nSpHeight = 0; // ドラッグ中になっているスプライトの内、マウスターゲットを1つ取得。 foreach (Sprite draggingSp in moSpDic.DraggingSprites().Values) { if (draggingSp.BMouseTarget) { nSpWidth = draggingSp.Bmp.Width; nSpHeight = draggingSp.Bmp.Height; break; } } // 掴んでいるスプライトの左上隅の座標は、 // 現在のマウス位置から、「スプライトの中の掴んでいる座標」を引いたものになります。 Point spLt = new Point();// スプライトの左上座標 spLt.X = this.mouseLocation.X - this.GrabbedLefttopInImg.X; spLt.Y = this.mouseLocation.Y - this.GrabbedLefttopInImg.Y; Point spCt = new Point();// スプライトの中心座標 spCt.X = spLt.X + (int)((double)nSpWidth / 2.0d); spCt.Y = spLt.Y + (int)((double)nSpHeight / 2.0d); // 「スプライトの中心」の近くにある、グリッドの十字の交差点を取得 Point nearCt = Point.Empty; foreach (Grid grid in this.Dictionary_Grid.Values) { // // グリッドビュー全体が、同じグリッド線上の形に収まるなら正しく動きます。 // //if (grid.Contains(spCt))//中心座標で、陣形の中にいるかを判定。 //{ nearCt = grid.NearCrosspoint(spCt); //} } if (Point.Empty == nearCt) { // 近くに、吸着するような 交差点がなければ。 nearCt = new Point(spCt.X, spCt.Y); } // 左上座標に変換。 Point nearLt = new Point( nearCt.X - (int)((double)nSpWidth / 2.0d), nearCt.Y - (int)((double)nSpHeight / 2.0d) ); // マウスで掴んでいるズレを足す? this.mouseLefttopOnGrid.X = nearLt.X + this.grabbedLefttopInImg.X; this.mouseLefttopOnGrid.Y = nearLt.Y + this.grabbedLefttopInImg.Y; // // 指している位置が、「グリッド交差点とスプライト左上隅点とのズレ」分、ずれます。 // // // ズレを求めます。 // zure.X = this.MouseLefttopOnGrid.X - this.MouseLocation.X; zure.Y = this.MouseLefttopOnGrid.Y - this.MouseLocation.Y; } else { // グリッド・スナップが無効です。 //moved = true; this.mouseLefttopOnGrid.X = this.MouseLocation.X;// e.X; this.mouseLefttopOnGrid.Y = this.MouseLocation.Y;// e.Y; } // 画像の選択のキャンセルを解除。 moSpDic.CancelSelectToggleAll(); // 画像をドラッグしているか否かで処理を分けます。 if (moSpDic.IsDraggingAnything()) { // 現在、画像をドラッグしています。 this.OnSpriteDragging(o_GridViewLt, moSpDic, zure); } else { // 現在、画像をドラッグしていません。 // スプライトの上に、マウスカーソルが重なっているか判定します。 moSpDic.CheckMouseOveredAll(e.Location, o_GridViewLt); } }
//──────────────────────────────────────── /// <summary> /// マウスに重なっている画像をドラッグできる状態にします。 /// </summary> /// <param name="e"></param> /// <param name="modelOfSpriteDic"></param> public void OnMouseDowned( MouseEventArgs e, Point o_OLt, MemorySpriteDictionary moSpDic ) { // リストの後ろから判定します。 int nSpriteCount = moSpDic.List_SpriteZOrder.Count; for (int nSpriteIndex = nSpriteCount - 1; nSpriteIndex >= 0; nSpriteIndex--) { Sprite sprite = moSpDic.List_SpriteZOrder[nSpriteIndex].Value; if (sprite.BoundsLefttopScaled.Contains( e.Location.X - o_OLt.X, e.Location.Y - o_OLt.Y )) { // ドラッグ開始 sprite.BDragging = true;// どこでfalseにしてる? // クリックした画像内の座標と、画像の左上隅座標との差を求めます。 this.grabbedLefttopInImg = new Point( e.X - sprite.BoundsLefttopScaled.X - o_OLt.X, e.Y - sprite.BoundsLefttopScaled.Y - o_OLt.Y ); // 最初の1件を見つけた時点で終了します。 break; } } // マウスに重なっている画像の選択/非選択を切り替える可能性が発生します。マウス・ムーブを挟むと、切り替えの意思を解除。 moSpDic.CheckSelectToggledAll( e.Location, o_OLt ); }
//──────────────────────────────────────── /// <summary> /// マウスムーブ /// </summary> /// <param name="e"></param> /// <param name="modelOfSpriteDic"></param> public void OnMouseMoved( MouseEventArgs e, //コントロールの中でのマウス座標 Point o_GridViewLt, //基本、(0,0)? MemorySpriteDictionary moSpDic ) { // マウスカーソルの座標を取得します。 this.mouseLocation.X = e.X; //スクリーン上での位置。 this.mouseLocation.Y = e.Y; // // マウスをドラッグしても、スナップ吸着していると スプライトが移動しないこともあります。 // スプライトが移動したら、真です。 // //bool moved = false; Point zure = Point.Empty;//ずれ。 if (this.BGridSnapped) { // グリッド・スナップが有効です。 // 全てのグリッド領域について、当たり判定を調査。 // TODO 先に有効なものがあれば、それを優先します。 //マウスカーソルの位置は、スプライト画像の適当な場所を掴んでいる。 int nSpWidth = 0; int nSpHeight = 0; // ドラッグ中になっているスプライトの内、マウスターゲットを1つ取得。 foreach (Sprite draggingSp in moSpDic.DraggingSprites().Values) { if (draggingSp.BMouseTarget) { nSpWidth = draggingSp.Bmp.Width; nSpHeight = draggingSp.Bmp.Height; break; } } // 掴んでいるスプライトの左上隅の座標は、 // 現在のマウス位置から、「スプライトの中の掴んでいる座標」を引いたものになります。 Point spLt = new Point();// スプライトの左上座標 spLt.X = this.mouseLocation.X - this.GrabbedLefttopInImg.X; spLt.Y = this.mouseLocation.Y - this.GrabbedLefttopInImg.Y; Point spCt = new Point();// スプライトの中心座標 spCt.X = spLt.X + (int)((double)nSpWidth / 2.0d); spCt.Y = spLt.Y + (int)((double)nSpHeight / 2.0d); // 「スプライトの中心」の近くにある、グリッドの十字の交差点を取得 Point nearCt = Point.Empty; foreach (Grid grid in this.Dictionary_Grid.Values) { // // グリッドビュー全体が、同じグリッド線上の形に収まるなら正しく動きます。 // //if (grid.Contains(spCt))//中心座標で、陣形の中にいるかを判定。 //{ nearCt = grid.NearCrosspoint(spCt); //} } if (Point.Empty == nearCt) { // 近くに、吸着するような 交差点がなければ。 nearCt = new Point(spCt.X, spCt.Y); } // 左上座標に変換。 Point nearLt = new Point( nearCt.X - (int)((double)nSpWidth / 2.0d), nearCt.Y - (int)((double)nSpHeight / 2.0d) ); // マウスで掴んでいるズレを足す? this.mouseLefttopOnGrid.X = nearLt.X + this.grabbedLefttopInImg.X; this.mouseLefttopOnGrid.Y = nearLt.Y + this.grabbedLefttopInImg.Y; // // 指している位置が、「グリッド交差点とスプライト左上隅点とのズレ」分、ずれます。 // // // ズレを求めます。 // zure.X = this.MouseLefttopOnGrid.X - this.MouseLocation.X; zure.Y = this.MouseLefttopOnGrid.Y - this.MouseLocation.Y; } else { // グリッド・スナップが無効です。 //moved = true; this.mouseLefttopOnGrid.X = this.MouseLocation.X; // e.X; this.mouseLefttopOnGrid.Y = this.MouseLocation.Y; // e.Y; } // 画像の選択のキャンセルを解除。 moSpDic.CancelSelectToggleAll(); // 画像をドラッグしているか否かで処理を分けます。 if (moSpDic.IsDraggingAnything()) { // 現在、画像をドラッグしています。 this.OnSpriteDragging(o_GridViewLt, moSpDic, zure); } else { // 現在、画像をドラッグしていません。 // スプライトの上に、マウスカーソルが重なっているか判定します。 moSpDic.CheckMouseOveredAll(e.Location, o_GridViewLt); } }
//──────────────────────────────────────── /// <summary> /// 赤い枠と×印を描画します。 /// </summary> /// <param name="e"></param> /// <param name="parentLocation"></param> /// <param name="sMsg">「画像が見つかりません」「配置場所が不妥当です」など</param> /// <param name="modelOfSprDic"></param> private void PaintRedCross( Graphics g, Point parentLocation, string sMsg, MemorySpriteDictionary moSpriteMouse ) { // 等倍表示も、倍角表示も 描画処理は同じ。 // 矩形(4px桃色) g.DrawRectangle( moSpriteMouse.BorderPen4OnInvalid,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); // ×印の斜線(4px桃色) g.DrawLine( moSpriteMouse.BorderPen4OnInvalid,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.X + this.BoundsLefttopScaled.Width + parentLocation.X, this.BoundsLefttopScaled.Y + this.BoundsLefttopScaled.Height + parentLocation.Y ); // ×印の斜線(4px桃色) g.DrawLine( moSpriteMouse.BorderPen4OnInvalid,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + this.BoundsLefttopScaled.Height + parentLocation.Y, this.BoundsLefttopScaled.X + this.BoundsLefttopScaled.Width + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y ); // 等倍表示も、倍角表示も 描画処理は同じ。 // 矩形(2px赤色) g.DrawRectangle( moSpriteMouse.BorderPen2OnInvalid,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); // ×印の斜線(2px赤色) g.DrawLine( moSpriteMouse.BorderPen2OnInvalid,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.X + this.BoundsLefttopScaled.Width + parentLocation.X, this.BoundsLefttopScaled.Y + this.BoundsLefttopScaled.Height + parentLocation.Y ); // ×印の斜線(2px赤色) g.DrawLine( moSpriteMouse.BorderPen2OnInvalid,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + this.BoundsLefttopScaled.Height + parentLocation.Y, this.BoundsLefttopScaled.X + this.BoundsLefttopScaled.Width + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y ); g.DrawString( sMsg, WARNING_MESSAGE_FONT, moSpriteMouse.BorderBrushOnInvalid, this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + this.BoundsLefttopScaled.Height + parentLocation.Y ); }
//──────────────────────────────────────── /// <summary> /// 描画 /// </summary> /// <param name="e"></param> /// <param name="modelOfSprDic"></param> /// <param name="pg_Logging"></param> public void Paint( Graphics g, Point parentLocation, MemorySpriteDictionary moSprDic, Log_Reports pg_Logging ) { Log_Method pg_Method = new Log_MethodImpl(0); pg_Method.BeginMethod(Info_Sprite.SName_Library, this, "Paint",pg_Logging); Exception err_Excp; try { if (null == this.Bmp) { // 画像の読取りに失敗している場合は、 // 白い影を持った赤い線の四角を表示します。中には×を描きます。 this.PaintRedCross( g, parentLocation, "画像が見つかりません", moSprDic ); } else { // 画像の読取に成功している場合のみ // 等倍表示も、倍角表示も 描画処理は同じ。 g.DrawImage( this.Bmp, this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); } // 選択時:2x2ブロックに枠を表示。 if (this.BSelected) { // 等倍表示も、倍角表示も 描画処理は同じ。 g.DrawRectangle( moSprDic.BorderPen4OnSelected, this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); g.FillRectangle( moSprDic.BorderBrushOnSelected, this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); } // // 不妥当配置の警告表示 // // // if (null != this.dlgt_CheckLocationValid) { string sMsg = "";//不妥当だった場合、原因。 bool locationValid = this.dlgt_CheckLocationValid(this, parentLocation, ref sMsg); if (!locationValid) { // 不妥当な位置にスプライトが配置されていれば、 // 警告を表示します。 // 白い影を持った赤い線の四角を表示します。中には×を描きます。 this.PaintRedCross( g, parentLocation, sMsg, moSprDic ); } } // マウスが指しているスプライトの時:2x2ブロックに枠を表示。 if (this.BMouseTarget) { // 等倍表示も、倍角表示も 描画処理は同じ。 g.DrawRectangle( moSprDic.BorderPen4OnOver,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); g.DrawRectangle( moSprDic.BorderPen2OnOver,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); // 十字を表示します。(中心位置の縦軸、横軸が分かりやすいように) { int lineWidth = this.BoundsLefttopScaled.Width; int lineHeight = this.BoundsLefttopScaled.Height; // 縦線 g.DrawLine( moSprDic.BorderPen2OnOver,//ペン this.BoundsLefttopScaled.X + parentLocation.X + this.BoundsLefttopScaled.Width / 2, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.X + parentLocation.X + this.BoundsLefttopScaled.Width / 2, this.BoundsLefttopScaled.Y + parentLocation.Y + this.BoundsLefttopScaled.Height ); // 横線 g.DrawLine( moSprDic.BorderPen2OnOver,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y + this.BoundsLefttopScaled.Height / 2, this.BoundsLefttopScaled.X + parentLocation.X + this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Y + parentLocation.Y + this.BoundsLefttopScaled.Height / 2 ); } } //// デバッグ用 //{ // // スプライト名を表示します。 // e.Graphics.DrawString(this.Index.ToString(), this.font, modelOfSprDic.BorderBrushOnSelected, this.BoundsLtScaled.Location); // System.Console.WriteLine(Info_Sprite.LibraryName + ":" + this.GetType().Name + "#Paint: スプライト番号=[" + this.Index.ToString() + "]"); //} //// エラーメッセージが登録されていれば、それを表示します。 //if ("" != this.errorMessage) //{ // e.Graphics.DrawString(this.errorMessage, this.font, modelOfSprDic.BorderBrushOnSelected, this.BoundsLtScaled.Location); //} } catch (Exception e1) { err_Excp = e1; goto gt_Error_Exception; } goto gt_EndMethod; // // #region 異常系 //──────────────────────────────────────── gt_Error_Exception: if (pg_Logging.CanCreateReport) { Log_RecordReports r = pg_Logging.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー451!", pg_Method); r.Message = "予期しないエラー:" + err_Excp.Message; pg_Logging.EndCreateReport(); } goto gt_EndMethod; //──────────────────────────────────────── #endregion // // gt_EndMethod: pg_Method.EndMethod(pg_Logging); }
//──────────────────────────────────────── /// <summary> /// 描画 /// </summary> /// <param name="e"></param> /// <param name="modelOfSprDic"></param> /// <param name="pg_Logging"></param> public void Paint( Graphics g, Point parentLocation, MemorySpriteDictionary moSprDic, Log_Reports pg_Logging ) { Log_Method pg_Method = new Log_MethodImpl(0); pg_Method.BeginMethod(Info_Sprite.SName_Library, this, "Paint", pg_Logging); Exception err_Excp; try { if (null == this.Bmp) { // 画像の読取りに失敗している場合は、 // 白い影を持った赤い線の四角を表示します。中には×を描きます。 this.PaintRedCross( g, parentLocation, "画像が見つかりません", moSprDic ); } else { // 画像の読取に成功している場合のみ // 等倍表示も、倍角表示も 描画処理は同じ。 g.DrawImage( this.Bmp, this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); } // 選択時:2x2ブロックに枠を表示。 if (this.BSelected) { // 等倍表示も、倍角表示も 描画処理は同じ。 g.DrawRectangle( moSprDic.BorderPen4OnSelected, this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); g.FillRectangle( moSprDic.BorderBrushOnSelected, this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); } // // 不妥当配置の警告表示 // // // if (null != this.dlgt_CheckLocationValid) { string sMsg = "";//不妥当だった場合、原因。 bool locationValid = this.dlgt_CheckLocationValid(this, parentLocation, ref sMsg); if (!locationValid) { // 不妥当な位置にスプライトが配置されていれば、 // 警告を表示します。 // 白い影を持った赤い線の四角を表示します。中には×を描きます。 this.PaintRedCross( g, parentLocation, sMsg, moSprDic ); } } // マウスが指しているスプライトの時:2x2ブロックに枠を表示。 if (this.BMouseTarget) { // 等倍表示も、倍角表示も 描画処理は同じ。 g.DrawRectangle( moSprDic.BorderPen4OnOver,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); g.DrawRectangle( moSprDic.BorderPen2OnOver,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Height ); // 十字を表示します。(中心位置の縦軸、横軸が分かりやすいように) { int lineWidth = this.BoundsLefttopScaled.Width; int lineHeight = this.BoundsLefttopScaled.Height; // 縦線 g.DrawLine( moSprDic.BorderPen2OnOver,//ペン this.BoundsLefttopScaled.X + parentLocation.X + this.BoundsLefttopScaled.Width / 2, this.BoundsLefttopScaled.Y + parentLocation.Y, this.BoundsLefttopScaled.X + parentLocation.X + this.BoundsLefttopScaled.Width / 2, this.BoundsLefttopScaled.Y + parentLocation.Y + this.BoundsLefttopScaled.Height ); // 横線 g.DrawLine( moSprDic.BorderPen2OnOver,//ペン this.BoundsLefttopScaled.X + parentLocation.X, this.BoundsLefttopScaled.Y + parentLocation.Y + this.BoundsLefttopScaled.Height / 2, this.BoundsLefttopScaled.X + parentLocation.X + this.BoundsLefttopScaled.Width, this.BoundsLefttopScaled.Y + parentLocation.Y + this.BoundsLefttopScaled.Height / 2 ); } } //// デバッグ用 //{ // // スプライト名を表示します。 // e.Graphics.DrawString(this.Index.ToString(), this.font, modelOfSprDic.BorderBrushOnSelected, this.BoundsLtScaled.Location); // System.Console.WriteLine(Info_Sprite.LibraryName + ":" + this.GetType().Name + "#Paint: スプライト番号=[" + this.Index.ToString() + "]"); //} //// エラーメッセージが登録されていれば、それを表示します。 //if ("" != this.errorMessage) //{ // e.Graphics.DrawString(this.errorMessage, this.font, modelOfSprDic.BorderBrushOnSelected, this.BoundsLtScaled.Location); //} } catch (Exception e1) { err_Excp = e1; goto gt_Error_Exception; } goto gt_EndMethod; // // #region 異常系 //──────────────────────────────────────── gt_Error_Exception: if (pg_Logging.CanCreateReport) { Log_RecordReports r = pg_Logging.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー451!", pg_Method); r.Message = "予期しないエラー:" + err_Excp.Message; pg_Logging.EndCreateReport(); } goto gt_EndMethod; //──────────────────────────────────────── #endregion // // gt_EndMethod: pg_Method.EndMethod(pg_Logging); }