Пример #1
0
        /// <summary>
        /// チップ一覧エリアの初期化
        /// </summary>
        public void initChipArea()
        {
            var m = model as MccModel;
            chips = new List<MapChip>();

            var datMgr = new KaBmpDatMgr( m.ChipEmptyImg as Bitmap );
            var img = datMgr.magnify( ChipSize / m.ChipEmptyImg.Width );
            for ( var col = 0; col < ChipCols; ++col )
            {
                for ( var row = 0; row < ChipRows; ++row )
                {
                    var chip = new MapChip();
                    chip.Location = new Point(
                        col * ChipSize + Margin,
                        row * ChipSize + Margin );
                    chip.Size = new Size( ChipSize, ChipSize );
                    chip.BackgroundImage = img;
                    chip.SizeMode = PictureBoxSizeMode.Zoom;
                    chip.BackgroundImageLayout = ImageLayout.Zoom;
                    chip.AllowDrop = true;
                    chips.Add( chip );
                }
            }

            mainForm.Controls.KaAdd( chips );
        }
Пример #2
0
        /// <summary>
        /// チップ詳細情報の初期化
        /// </summary>
        private void initChipInfoArea()
        {
            var m = model as MccModel;

            // チップエリアの上の値を得る
            var chipAreaTop = Margin;
            // チップエリアの一番右の値を得る
            var chipAreaR = ChipCols * ChipSize + Margin;

            detailChip = new MapChip();
            var left = chipAreaR + Margin;
            var datMgr = new KaBmpDatMgr( m.ChipEmptyImg as Bitmap );

            detailChip.Location = new Point( left, chipAreaTop );
            detailChip.Size = new Size( ChipSize * DetailSizeRate, ChipSize * DetailSizeRate );
            detailChip.Image = datMgr.magnify( DetailSizeRate );
            detailChip.SizeMode = PictureBoxSizeMode.Zoom;
            detailChip.BackgroundImageLayout = ImageLayout.Zoom;
            mainForm.Controls.Add( detailChip );
        }
Пример #3
0
        // チップにイベントを設定
        private void bindChips()
        {
            var m = model as MccModel;
            var v = view as MccView;

            var bgImgMgr = new KaBmpDatMgr( m.ChipEmptyImg as Bitmap );
            var overImgMgr = new KaBmpDatMgr( m.ChipOverImg as Bitmap );

            Bitmap dropImg = null;

            var chips = v.chips;

            foreach ( var chip in chips )
            {
                // マウスオーバーイベント
                chip.MouseEnter += ( s, e ) =>
                {
                    chip.Image = overImgMgr.magnify( MccView.ChipSize / m.ChipOverImg.Width );
                };
                chip.MouseLeave += ( s, e ) =>
                {
                    chip.Image = null;
                };

                // D&D イベント
                /// ドラッグオーバー
                chip.DragEnter += ( s, e ) =>
                {
                    var fileNames = e.Data.GetData( DataFormats.FileDrop ) as string[];

                    // エラー処理
                    /// null の場合
                    if ( !fileNames.KaIs() ) return;
                    /// ドラッグ対象が1つ以外
                    if ( fileNames.Length != 1 ) return;
                    /// ドラッグ対象が画像以外
                    try { dropImg = new Bitmap( fileNames[ 0 ] ); }
                    catch( ArgumentException ) { return; }

                    // ドラッグ対象が1つで、画像ファイルの場合
                    e.Effect = DragDropEffects.All;
                    chip.Image = overImgMgr.magnify( MccView.ChipSize / m.ChipOverImg.Width );
                };
                /// ドラッグリーブ
                chip.DragLeave += ( s, e ) =>
                {
                    chip.Image = null;
                };
                /// ドロップ
                chip.DragDrop += ( s, e ) =>
                {
                    // サイズチェック
                    /// チップサイズ以下のサイズなら OK
                    if( dropImg.Width > chip.Width
                        || dropImg.Height > chip.Height )
                    {
                        return;
                    }
                    /// 縦 : 横 = 1 : 1 のみを許可
                    if ( dropImg.Width != dropImg.Height )
                    {
                        return;
                    }

                    var dropImgMgr = new KaBmpDatMgr( dropImg );
                    chip.BackgroundImage = dropImgMgr.magnify( MccView.ChipSize / dropImg.Width );
                };

                // クリックイベント
                chip.Click += ( s, e ) =>
                {
                    var mgr = new KaBmpDatMgr( chip.BackgroundImage as Bitmap );
                    v.detailChip.Image = mgr.magnify( MccView.DetailSizeRate );
                };
            }
        }