private void OnRestoreBackground(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            // copy original background to associated bitmap
            BackgroundBuffer.Read(BackgroundBitmap);
            BackgroundBuffer.Write();
        }
Example #2
0
 private void InitBackgroundBuffer()
 {
     if (BackgroundBuffer != null)
     {
         BackgroundBuffer.Dispose();
     }
     BackgroundBuffer = new Bitmap(MapPWidth, MapPHeight);
     using (var g = Graphics.FromImage(BackgroundBuffer))
     {
         g.FillRectangle(Brushes.Black, 0, 0, MapPWidth, MapPHeight);
     }
 }
        private void Overlay(byte alpha, Color color)
        {
            if (UseBitmapBuffer)
            {
                // restore original background first
                BackgroundBuffer.Read(BackgroundBitmap);

                // use alpha cutoff, color substitution, or regular alpha blending
                if (alpha != 0)
                {
                    BackgroundBuffer.Overlay(0, 0, ForegroundBuffer, ForegroundBuffer.Bounds, alpha);
                }
                else if (color != Colors.Transparent)
                {
                    BackgroundBuffer.Overlay(0, 0, ForegroundBuffer, ForegroundBuffer.Bounds, color);
                }
                else
                {
                    BackgroundBuffer.Overlay(0, 0, ForegroundBuffer, ForegroundBuffer.Bounds);
                }

                BackgroundBuffer.Write();
            }
            else
            {
                // restore original background first
                WriteableBitmap bitmap = BackgroundBuffer.Bitmap;
                bitmap.Lock();
                bitmap.Read(0, 0, BackgroundBitmap);

                // use alpha cutoff, color substitution, or regular alpha blending
                if (alpha != 0)
                {
                    bitmap.Overlay(0, 0, ForegroundBuffer.Bitmap, ForegroundBuffer.Bounds, alpha);
                }
                else if (color != Colors.Transparent)
                {
                    bitmap.Overlay(0, 0, ForegroundBuffer.Bitmap, ForegroundBuffer.Bounds, color);
                }
                else
                {
                    bitmap.Overlay(0, 0, ForegroundBuffer.Bitmap, ForegroundBuffer.Bounds);
                }

                bitmap.Unlock();
            }
        }
        private void OnMakeOpaque(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            if (UseBitmapBuffer)
            {
                BackgroundBuffer.MakeOpaque();
                BackgroundBuffer.Write();
            }
            else
            {
                WriteableBitmap bitmap = BackgroundBuffer.Bitmap;
                bitmap.Lock();
                bitmap.MakeOpaque();
                bitmap.Unlock();
            }
        }
Example #5
0
        public void SetupBackground(string draw_mode, string draw_option, Color filter_color, double filter_trans_par)
        {
            Map.MapDrawMode               = draw_mode;
            Map.MapDrawFilterColor        = filter_color;
            Map.MapDrawFilterTransPercent = filter_trans_par;

            Map.IsMapDirty       = false;
            GUI.IsPictureVisible = false;
            GUI.IsCursorVisible  = false;

            // TODO Impl SetupBackground
            using (var g = Graphics.FromImage(BackgroundBuffer))
            {
                switch (draw_option ?? "")
                {
                case "ステータス":
                    g.FillRectangle(Brushes.Black, 0, 0, BackgroundBuffer.Width, BackgroundBuffer.Height);
                    return;

                default:
                    GUI.MapX = (GUI.MainWidth / 2 + 1);
                    GUI.MapY = (GUI.MainHeight / 2 + 1);
                    break;
                }

                // 各マスのマップ画像を表示
                for (var x = 1; x <= Map.MapWidth; x++)
                {
                    for (var y = 1; y <= Map.MapHeight; y++)
                    {
                        var cell = Map.MapData[x, y];
                        var xpx  = (x - 1) * MapCellPx;
                        var ypx  = (y - 1) * MapCellPx;

                        // 画像を描き込み
                        var bitmapPath = Map.SearchTerrainImageFile(cell);
                        if (!string.IsNullOrEmpty(bitmapPath))
                        {
                            g.DrawImage(ImageBuffer.Get(bitmapPath), xpx, ypx);
                        }
                        else
                        {
                            g.FillRectangle(Brushes.Black, xpx, ypx, MapCellPx, MapCellPx);
                        }
                        //g.DrawString($"{cell.TerrainType}", SystemFonts.DefaultFont, Brushes.Gray, xpx + 2, ypx + 2);
                    }
                }
            }

            // マップ設定によって表示色を変更
            switch (draw_mode ?? "")
            {
            case "夜":
                BackgroundBuffer.Dark();
                break;

            case "セピア":
                BackgroundBuffer.Sepia();
                break;

            case "白黒":
                BackgroundBuffer.Monotone();
                break;

            case "夕焼け":
                BackgroundBuffer.Sunset();
                break;

            case "水中":
                BackgroundBuffer.Water();
                break;

            case "フィルタ":
                BackgroundBuffer.ColorFilter(filter_color, (float)filter_trans_par);
                break;
            }

            // マス目の表示
            if (SRC.ShowSquareLine)
            {
                using (var g = Graphics.FromImage(BackgroundBuffer))
                {
                    g.DrawRectangle(MapLinePen, 0, 0, MapPWidth, MapPHeight);
                    for (var x = 1; x <= Map.MapWidth - 1; x++)
                    {
                        g.DrawLine(MapLinePen, x * MapCellPx, 0, x * MapCellPx, MapPHeight);
                    }
                    for (var y = 1; y <= Map.MapHeight - 1; y++)
                    {
                        g.DrawLine(MapLinePen, 0, y * MapCellPx, MapPWidth, y * MapCellPx);
                    }
                }
            }

            // 画面を更新
            if (!Map.IsStatusView && string.IsNullOrEmpty(draw_option))
            {
                GUI.RefreshScreen();
            }
        }