Пример #1
0
 public RoomDefinition(int size, NodeType type)
 {
     this.size   = size;
     moduleGrid  = new int[size, size];
     itemGrid    = new int[size, size];
     visualTheme = VisualTheme.Ancient;
     roomType    = type;
 }
Пример #2
0
        internal static void ChangeFormThemeMode(
            VisualTheme theme,
            Form form,
            List <KeyValuePair <Control, ControlOriginalColors?> > controlColors,
            Func <Component, bool>?excludePredicate = null,
            bool alsoCreateControlHandles           = false,
            int capacity = -1
            )
        {
            bool darkMode = theme == VisualTheme.Dark;

            // @DarkModeNote(FillControlDict): Controls might change their colors after construct
            // Remember to handle this if new controls are added that this applies to.
            if (controlColors.Count == 0)
            {
                if (capacity >= 0)
                {
                    controlColors.Capacity = capacity;
                }
                FillControlDict(form, controlColors, alsoCreateControlHandles);
            }

            foreach (var item in controlColors)
            {
                Control control = item.Key;

                // Separate if because a control could be IDarkable AND be a ToolStrip
                if (control is ToolStrip ts)
                {
                    foreach (ToolStripItem tsItem in ts.Items)
                    {
                        if (tsItem is IDarkable darkableTSItem && (excludePredicate == null || !excludePredicate(tsItem)))
                        {
                            darkableTSItem.DarkModeEnabled = darkMode;
                        }
                    }
                }

                // We might want to exclude a ToolStrip but not its subcomponents, so we put this check after the
                // ToolStrip component check
                if (excludePredicate?.Invoke(control) == true)
                {
                    continue;
                }

                if (control is IDarkable darkableControl)
                {
                    darkableControl.DarkModeEnabled = darkMode;
                }
                else
                {
                    (control.ForeColor, control.BackColor) =
                        darkMode
                            ? (DarkColors.LightText, DarkColors.Fen_ControlBackground)
                            : (item.Value !.ForeColor, item.Value !.BackColor);
                }
            }
        }
Пример #3
0
 public void GetBitmapTest()
 {
     using (var th = new VisualTheme("Button"))
     {
         Assert.That(th.GetBitmap(2, 1, VisualTheme.BitmapProperty.BackgroundImage), Is.Null);
         Assert.That(th.GetBitmap(2, 1, VisualTheme.BitmapProperty.GlyphImage), Is.Not.Null);
         Assert.That(th.GetBitmap(2, 1, VisualTheme.BitmapProperty.Handle), Is.Null);
     }
 }
Пример #4
0
        private static VisualTheme GetBasicWindowVisualTheme(IWin32Window w = null)
        {
            var theme = new VisualTheme(BasicClassListValue);

            if (w != null)
            {
                theme.GetType().GetField("hTheme", BindingFlags.Instance | BindingFlags.NonPublic)
                ?.SetValue(theme, LoadBasicThemeData(w));
            }
            return(theme);
        }
        private static Image GetImageAtlasFromTheme(VisualTheme vs, Kernel32.SafeLibraryHandle hInstance)
        {
            var byteStream = vs.GetDiskStream(hInstance, 0, 0, 213);

            if (byteStream == null)
            {
                return(null);
            }
            using (var ms = new MemoryStream(byteStream))
            {
                return(Image.FromStream(ms));
            }
        }
Пример #6
0
        public void SetVisualTheme(VisualTheme theme)
        {
            var themeColors = _visualThemes[theme];

            Application.Current.Resources[Constants.Style.BackgroundColorKey]        = themeColors[Constants.Style.BackgroundColorKey].ToColor();
            Application.Current.Resources[Constants.Style.ArticleBackgroundColorKey] = themeColors[Constants.Style.ArticleBackgroundColorKey].ToColor();
            Application.Current.Resources[Constants.Style.TextColorKey]       = themeColors[Constants.Style.TextColorKey].ToColor();
            Application.Current.Resources[Constants.Style.AccentTextColorKey] = themeColors[Constants.Style.AccentTextColorKey].ToColor();
            Application.Current.Resources[Constants.Style.NavBarColorKey]     = themeColors[Constants.Style.NavBarColorKey].ToColor();
            Application.Current.Resources[Constants.Style.SeparatorColorKey]  = themeColors[Constants.Style.SeparatorColorKey].ToColor();
            Application.Current.Resources[Constants.Style.EntryColorKey]      = themeColors[Constants.Style.EntryColorKey].ToColor();

            Preferences.Set(nameof(VisualTheme), value: theme.ToString());
        }
Пример #7
0
    public void ResetRoom(RoomDefinition floorRoom)
    {
        room      = floorRoom;
        roomTheme = floorRoom.visualTheme;

        DestroyModules();

        for (var i = 0; i < room.size; i++)
        {
            for (var j = 0; j < room.size; j++)
            {
                if (i > 0 && j > 0 && i < room.size - 1 && j < room.size - 1)
                {
                    InitializeScenery(i, j);
                }

                InitializeModule(i, j);
                InitializeItem(i, j);
            }
        }
    }
Пример #8
0
        private VisualTheme BuildTheme(string themeId, string nameResKey, bool lightTheme, Color accentColor)
        {
            var backgroundAcrylic = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.HostBackdrop,
                FallbackColor    = accentColor,
                TintColor        = accentColor,
                TintOpacity      = _settingsViewModel.BackgroundTintOpacity,
            };

            var backgroundAcrylic2 = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.HostBackdrop,
                FallbackColor    = accentColor,
                TintColor        = accentColor,
                TintOpacity      = (_settingsViewModel.BackgroundTintOpacity + .15) > 1 ? 1 : _settingsViewModel.BackgroundTintOpacity + .15
            };

            var backgroundAcrylicAccent = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = accentColor,
                TintColor        = accentColor,
                TintOpacity      = (_settingsViewModel.BackgroundTintOpacity + -.25) < 0 ? 0 : _settingsViewModel.BackgroundTintOpacity - .25
            };

            var inAppAcrylic = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = accentColor,
                TintColor        = accentColor,
                TintOpacity      = (_settingsViewModel.BackgroundTintOpacity + .05) > 1 ? 1 : _settingsViewModel.BackgroundTintOpacity + .05
            };

            var etheme = (lightTheme) ? ElementTheme.Light : ElementTheme.Dark;

            var descriptionResKey = (lightTheme)
                ? "ThemeGeneralLightDescription"
                : "ThemeGeneralDarkDescription";

            var theme = new VisualTheme
            {
                ThemeId                  = themeId,
                FriendlyName             = _loader.GetString(nameResKey),
                Description              = _loader.GetString(descriptionResKey),
                Theme                    = etheme,
                BackgroundAcrylicBrush   = backgroundAcrylic,
                BackgroundAcrylicBrush2  = backgroundAcrylic2,
                BackgroundAcrylicAccent  = backgroundAcrylicAccent,
                InAppAcrylicBrush        = inAppAcrylic,
                SolidBackgroundBrush     = new SolidColorBrush(accentColor),
                PreviewBrush             = new SolidColorBrush(accentColor),
                BaseThemeBackgroundBrush = etheme == ElementTheme.Dark
                    ? new SolidColorBrush(Color.FromArgb(255, 28, 28, 28))
                    : new SolidColorBrush(Colors.White),
            };

            _settingsViewModel.AfterTintOpacityChanged += theme.UpdateTintOpacity;

            return(theme);
        }
Пример #9
0
        private void Fill()
        {
            /*Priority Themes*/
            //Default:
            var defPreview = new LinearGradientBrush {
                StartPoint = new Point(0, 0), EndPoint = new Point(1, 1),
            };

            defPreview.GradientStops.Add(new GradientStop {
                Color = VisualTheme.DarkColor, Offset = .5d
            });
            defPreview.GradientStops.Add(new GradientStop {
                Color = VisualTheme.LightColor, Offset = .5d
            });

            var def = new VisualTheme
            {
                ThemeId      = "default",
                Description  = _loader.GetString("ThemeSystemDescription"),
                FriendlyName = _loader.GetString("ThemeSystemName"),
                Theme        = ElementTheme.Default,
                Kind         = VisualThemeKind.System,
                PreviewBrush = defPreview
            };

            _themes.Add(def);
            //Light
            _themes.Add(BuildTheme(LIGHT_KEY, "ThemeLightName", true, VisualTheme.LightColor));
            //Dark
            _themes.Add(BuildTheme(DARK_KEY, "ThemeDarkName", false, VisualTheme.DarkColor));

            //System Accent Color
            _themes.Add(BuildTheme("accent", "ThemeAccentName", false, (Color)Resources["SystemAccentColor"]));

            //Random:
            var rdmPreview = new LinearGradientBrush {
                StartPoint = new Point(0, 0), EndPoint = new Point(1, 1),
            };

            rdmPreview.GradientStops.Add(new GradientStop {
                Color = Colors.Red, Offset = 0d
            });
            rdmPreview.GradientStops.Add(new GradientStop {
                Color = Colors.Yellow, Offset = .25d
            });
            rdmPreview.GradientStops.Add(new GradientStop {
                Color = Colors.LightGreen, Offset = .50d
            });
            rdmPreview.GradientStops.Add(new GradientStop {
                Color = Colors.Teal, Offset = .75d
            });
            rdmPreview.GradientStops.Add(new GradientStop {
                Color = Colors.Violet, Offset = 1d
            });

            var rdm = new VisualTheme
            {
                ThemeId      = "random",
                FriendlyName = _loader.GetString("ThemeRandomName"),
                Description  = _loader.GetString("ThemeRandomDescription"),
                Theme        = ElementTheme.Default,
                Kind         = VisualThemeKind.Random,
                PreviewBrush = rdmPreview
            };

            _themes.Add(rdm);

            //Custom light themes:
            _themes.Add(BuildTheme("chick", "ThemeChickName", true, Color.FromArgb(255, 254, 255, 177)));
            _themes.Add(BuildTheme("lettuce", "ThemeLettuceName", true, Color.FromArgb(255, 177, 234, 175)));
            _themes.Add(BuildTheme("rosegold", "ThemeRoseGoldName", true, Color.FromArgb(255, 253, 220, 215)));

            //Custom dark themes:
            _themes.Add(BuildTheme("cobalt", "ThemeCobaltName", false, Color.FromArgb(255, 0, 71, 171)));
            _themes.Add(BuildTheme("leaf", "ThemeLeafName", false, Color.FromArgb(255, 56, 111, 54)));
            _themes.Add(BuildTheme("crimson", "ThemeCrimsonName", false, Color.FromArgb(255, 149, 0, 39)));
        }
Пример #10
0
 internal void Show(VisualTheme theme) => _splashScreenForm.Show(theme);
 public static Bitmap GetBitmap(this VisualTheme th, int partId, int stateId, int propId)
 {
     return(GetThemeBitmap(th.GetTheme(), partId, stateId, propId, 1, out var phBitmap).Succeeded ? Image.FromHbitmap(phBitmap) : null);
 }
 public static UxTheme.SafeThemeHandle GetTheme(this VisualTheme th)
 {
     return(th.GetType().GetField("hTheme", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(th) as UxTheme.SafeThemeHandle);
 }