Ghidra is a software reverse engineering (SRE) framework
GP-3172 fixed issue in dark mode where byteview selections were hard to s
ghidragon107244de89b4
diff --git a/Ghidra/Framework/Docking/certification.manifest b/Ghidra/Framework/Docking/certification.manifestindex 547046e3d8..5482cd86b5 100644--- a/Ghidra/Framework/Docking/certification.manifest+++ b/Ghidra/Framework/Docking/certification.manifest@@ -73,7 +73,6 @@ src/main/resources/images/hourglass24_11.png||GHIDRA||reviewed||END|src/main/resources/images/info_small.png||GHIDRA||||END|src/main/resources/images/info_small_hover.png||GHIDRA||||END|src/main/resources/images/inode-directory.png||Oxygen Icons - LGPL 3.0|||Oxygen icon theme (dual license; LGPL or CC-SA-3.0)|END|-src/main/resources/images/list-remove.png||Oxygen Icons - LGPL 3.0|||Oxygen icon theme (dual license; LGPL or CC-SA-3.0)|END|src/main/resources/images/magnifier.png||FAMFAMFAM Icons - CC 2.5|||famfamfam silk icon set|END|src/main/resources/images/mail-folder-outbox.png||Oxygen Icons - LGPL 3.0|||Oxygen icon theme (dual license; LGPL or CC-SA-3.0)|END|src/main/resources/images/mail-receive.png||Oxygen Icons - LGPL 3.0|||Oxygen icon theme (dual license; LGPL or CC-SA-3.0)|END|diff --git a/Ghidra/Framework/Docking/data/docking.theme.properties b/Ghidra/Framework/Docking/data/docking.theme.propertiesindex aa2b22ce07..986ec2f8d1 100644--- a/Ghidra/Framework/Docking/data/docking.theme.properties+++ b/Ghidra/Framework/Docking/data/docking.theme.properties@@ -15,8 +15,8 @@ color.fg.dialog.status.error = color.fg.messages.errorcolor.fg.dialog.status.normal = color.fg.messages.normalcolor.fg.dialog.status.warning = color.fg.messages.warning-color.bg.selection = rgb(180, 255, 180) // pale green-color.bg.highlight = rgb(255,255,150) // pale yellow+color.bg.selection = rgb(180, 240, 180) // pale green+color.bg.highlight = rgb(240,240,150) // pale yellowcolor.bg.currentline = rgb(232,242,254)@@ -43,7 +43,6 @@ color.bg.fieldpanel = color.bgcolor.fg.fieldpanel = color.fgcolor.bg.fieldpanel.selection = color.bg.selectioncolor.bg.fieldpanel.highlight = color.bg.highlight-color.bg.fieldpanel.selection.and.highlight = green// docking buttonscolor.fg.button = black@@ -166,10 +165,8 @@ color.bg.textfield.hint.invalid = marooncolor.bg.filterfield = color.bg.filteredcolor.fg.filterfield = darkSlateGray-color.bg.selection = #003333 // greenish-color.bg.highlight = #404028 // yellowish--color.bg.fieldpanel.selection.and.highlight = #344028 // yellow greenish+color.bg.selection = #14564f // greenish+color.bg.highlight = #703401 // orangish// docking buttonsdiff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.javaindex 3bb62a7ff5..ac4f6594c3 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java@@ -1142,20 +1142,15 @@ public class FieldPanel extends JPanelColor highlightColor = paintContext.getHighlightColor();Color mixedColor = paintContext.getSelectedHighlightColor();if (!isDefault) {- selectionColor = blend(selectionColor, backgroundColor);- highlightColor = blend(highlightColor, backgroundColor);- mixedColor = blend(mixedColor, backgroundColor);+ selectionColor = ColorUtils.addColors(selectionColor, backgroundColor);+ highlightColor = ColorUtils.addColors(highlightColor, backgroundColor);+ mixedColor = ColorUtils.addColors(mixedColor, backgroundColor);}return LayoutColorMapFactory.getLayoutColorMap(layoutIndex, selection, highlight,backgroundColor, selectionColor, highlightColor, mixedColor);}- private Color blend(Color primary, Color secondary) {-- return ColorUtils.blend(primary, secondary, 0.75);- }-private void paintLayoutBackground(Graphics g, Rectangle rect, AnchoredLayout layout,LayoutBackgroundColorManager layoutSelectionMap) {Color layoutBackgroundColor = layoutSelectionMap.getBackgroundColor();diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/PaintContext.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/PaintContext.javaindex fb90b3ad23..05a4e6a8b4 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/PaintContext.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/PaintContext.java@@ -17,7 +17,7 @@ package docking.widgets.fieldpanel.internal;import java.awt.Color;-import generic.theme.GColor;+import generic.theme.*;import generic.theme.GThemeDefaults.Colors.Palette;import ghidra.util.ColorUtils;@@ -39,6 +39,7 @@ public class PaintContext {private boolean printing = false;private boolean textCopying = false;+ private ThemeListener themeListener = this::themeChanged;/*** Create a new PaintContext with default color values.@@ -48,23 +49,16 @@ public class PaintContext {foreground = new GColor("color.fg.fieldpanel");selectionColor = new GColor("color.bg.fieldpanel.selection");highlightColor = new GColor("color.bg.fieldpanel.highlight");- selectedHighlightColor = new GColor("color.bg.fieldpanel.selection.and.highlight");+ updateSelectedHighlightColor();focusedCursorColor = new GColor("color.cursor.focused");notFocusedCursorColor = new GColor("color.cursor.unfocused");cursorColor = focusedCursorColor;invisibleCursorColor = Palette.NO_COLOR;+ Gui.addThemeListener(themeListener);}- public PaintContext(PaintContext other) {- background = other.background;- foreground = other.foreground;- selectionColor = other.selectionColor;- highlightColor = other.highlightColor;- selectedHighlightColor = other.selectedHighlightColor;- cursorColor = other.cursorColor;- focusedCursorColor = other.focusedCursorColor;- notFocusedCursorColor = other.notFocusedCursorColor;- invisibleCursorColor = other.invisibleCursorColor;+ private void themeChanged(ThemeEvent ev) {+ updateSelectedHighlightColor();}/**@@ -121,16 +115,16 @@ public class PaintContext {public void setSelectionColor(Color c) {selectionColor = c;- adjustSelectedHighlightColor();+ updateSelectedHighlightColor();}public void setHighlightColor(Color c) {highlightColor = c;- adjustSelectedHighlightColor();+ updateSelectedHighlightColor();}- private void adjustSelectedHighlightColor() {- selectedHighlightColor = ColorUtils.blend(selectionColor, highlightColor, 0.5);+ private void updateSelectedHighlightColor() {+ selectedHighlightColor = ColorUtils.addColors(highlightColor, selectionColor);}public void setBackgroundColor(Color c) {diff --git a/Ghidra/Framework/Gui/src/main/java/ghidra/util/ColorUtils.java b/Ghidra/Framework/Gui/src/main/java/ghidra/util/ColorUtils.javaindex 79d4f26d90..5b133d5066 100644--- a/Ghidra/Framework/Gui/src/main/java/ghidra/util/ColorUtils.java+++ b/Ghidra/Framework/Gui/src/main/java/ghidra/util/ColorUtils.java@@ -20,6 +20,9 @@ import java.util.Comparator;public class ColorUtils {+ private static final int MAX_COLOR_VALUE = 255;+ private static final int MID_COLOR_VALUE = MAX_COLOR_VALUE / 2;+ private static final int MAX_NUDGE = 32;public static final float HUE_RED = 0.0f / 12;public static final float HUE_ORANGE = 1.0f / 12;public static final float HUE_YELLOW = 2.0f / 12;@@ -182,6 +185,65 @@ public class ColorUtils {return new Color(red, green, blue, alpha);}+ /**+ * Combines colors in a way the makes them stand out from each other more than just averaging+ * them together. Basically if the colors are bright, the result is a darker value than the+ * primary, adjusted based on the values in the secondary. If the colors are dark, then the+ * result is a brighter version of the primary color adjusted based on values in the secondary+ * color.+ * @param primary the primary color to be tweaked+ * @param secondary the color to used to determine the amount to tweak the red,green,blue values+ * @return a new color that is a combination of the two colors+ */+ public static Color addColors(Color primary, Color secondary) {+ boolean bright1 = isBright(primary);+ boolean bright2 = isBright(secondary);+ if (bright1 && bright2) {+ return combineDarker(primary, secondary);+ }+ if (!bright1 && !bright2) {+ return combineBrighter(primary, secondary);+ }+ return average(primary, secondary);+ }++ private static Color combineDarker(Color primary, Color secondary) {+ int red = combineDarker(primary.getRed(), secondary.getRed());+ int green = combineDarker(primary.getGreen(), secondary.getGreen());+ int blue = combineDarker(primary.getBlue(), secondary.getBlue());+ return new Color(red, green, blue);+ }++ private static Color combineBrighter(Color primary, Color secondary) {+ int red = combineBrighter(primary.getRed(), secondary.getRed());+ int green = combineBrighter(primary.getGreen(), secondary.getGreen());+ int blue = combineBrighter(primary.getBlue(), secondary.getBlue());+ return new Color(red, green, blue);+ }++ private static int combineDarker(int primary, int secondary) {+ int nudge = Math.min(MAX_COLOR_VALUE - secondary, MAX_NUDGE);+ return primary - nudge;+ }++ private static int combineBrighter(int primary, int secondary) {+ int nudge = Math.min(secondary, MAX_NUDGE);+ return primary + nudge;+ }++ private static boolean isBright(Color color) {+ if (color.getRed() > MID_COLOR_VALUE) {+ return true;+ }+ if (color.getGreen() > MID_COLOR_VALUE) {+ return true;+ }+ if (color.getBlue() > MID_COLOR_VALUE) {+ return true;+ }+ return false;+ }+private static int blend(int colorValue1, int colorValue2, double ratio) {double value = colorValue1 * ratio + colorValue2 * (1.0 - ratio);int result = (int) (value + 0.5);diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/app/plugin/gui/ThemeChooserDialog.java b/Ghidra/Framework/Project/src/main/java/ghidra/app/plugin/gui/ThemeChooserDialog.javaindex f5a4221f47..925fb7eddf 100644--- a/Ghidra/Framework/Project/src/main/java/ghidra/app/plugin/gui/ThemeChooserDialog.java+++ b/Ghidra/Framework/Project/src/main/java/ghidra/app/plugin/gui/ThemeChooserDialog.java@@ -31,29 +31,53 @@ public class ThemeChooserDialog extends DialogComponentProvider {private ThemeManager themeManager;private ListPanel<GTheme> listPanel;- private GTheme originalTheme;public ThemeChooserDialog(ThemeManager themeManager) {super("Change Theme");this.themeManager = themeManager;- originalTheme = themeManager.getActiveTheme();addWorkPanel(buildMainPanel());addOKButton();+ addApplyButton();addCancelButton();setRememberSize(false);setHelpLocation(new HelpLocation("Theming", "Switch_Theme"));+ updateOkApplyButtons();+ }++ private void updateOkApplyButtons() {++ GTheme selectedValue = listPanel.getSelectedValue();+ GTheme currentTheme = themeManager.getActiveTheme();+ boolean canApplyTheme = selectedValue != null && !currentTheme.equals(selectedValue);+ setOkEnabled(canApplyTheme);+ setApplyEnabled(canApplyTheme);}@Overrideprotected void okCallback() {+ applyTheme();close();}- protected void cancelCallback() {+ @Override+ protected void applyCallback() {+ applyTheme();+ }++ private void applyTheme() {+ GTheme selectedValue = listPanel.getSelectedValue();+ if (selectedValue == null) {+ return;+ }GTheme activeTheme = themeManager.getActiveTheme();- if (activeTheme != originalTheme) {- themeManager.setTheme(originalTheme);+ if (selectedValue != activeTheme) {+ Swing.runLater(() -> themeManager.setTheme(selectedValue));}+ setOkEnabled(false);+ setApplyEnabled(false);+ }++ protected void cancelCallback() {close();}@@ -74,14 +98,7 @@ public class ThemeChooserDialog extends DialogComponentProvider {}private void selectionChanged() {- GTheme selectedValue = listPanel.getSelectedValue();- if (selectedValue == null) {- return;- }- GTheme activeTheme = themeManager.getActiveTheme();- if (selectedValue != activeTheme) {- Swing.runLater(() -> themeManager.setTheme(selectedValue));- }+ updateOkApplyButtons();}private class ThemeListModel extends AbstractListModel<GTheme> {