From c6fb35ed52621d026ab88f21ac97831d3863c9d8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 30 Jun 2016 10:27:14 +0200 Subject: [PATCH 1/3] - added per-item colors for static text items in the menu. For option menus this replaces the 'highlighted' parameter with an actual color, for list menus it adds a new parameter. --- src/menu/menudef.cpp | 39 +++++++++++++++++++++++++------------- src/menu/optionmenuitems.h | 12 +++++++++--- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index d1753c405..6d5e3dd64 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -306,7 +306,15 @@ static void ParseListMenuBody(FScanner &sc, FListMenuDescriptor *desc) int y = sc.Number; sc.MustGetStringName(","); sc.MustGetString(); - FListMenuItem *it = new FListMenuItemStaticText(x, y, sc.String, desc->mFont, desc->mFontColor, centered); + FString label = sc.String; + EColorRange cr = desc->mFontColor; + if (sc.CheckString(",")) + { + sc.MustGetString(); + cr = V_FindFontColor(sc.String); + if (cr == CR_UNTRANSLATED && !sc.Compare("untranslated")) cr = desc->mFontColor; + } + FListMenuItem *it = new FListMenuItemStaticText(x, y, label, desc->mFont, cr, centered); desc->mItems.Push(it); } else if (sc.Compare("PatchItem")) @@ -648,6 +656,21 @@ static void ParseOptionSettings(FScanner &sc) // //============================================================================= +static EColorRange ParseOptionColor(FScanner &sc, FOptionMenuDescriptor *desc) +{ + EColorRange cr = OptionSettings.mFontColor; + if (sc.CheckString(",")) + { + sc.MustGetString(); + EColorRange cr = V_FindFontColor(sc.String); + if (cr == CR_UNTRANSLATED && !sc.Compare("untranslated") && isdigit(sc.String[0])) + { + if (strtol(sc.String, NULL, 0)) cr = OptionSettings.mFontColorHeader; + } + } + return cr; +} + static void ParseOptionMenuBody(FScanner &sc, FOptionMenuDescriptor *desc) { sc.MustGetStringName("{"); @@ -784,12 +807,7 @@ static void ParseOptionMenuBody(FScanner &sc, FOptionMenuDescriptor *desc) { sc.MustGetString(); FString label = sc.String; - bool cr = false; - if (sc.CheckString(",")) - { - sc.MustGetNumber(); - cr = !!sc.Number; - } + EColorRange cr = ParseOptionColor(sc, desc); FOptionMenuItem *it = new FOptionMenuItemStaticText(label, cr); desc->mItems.Push(it); } @@ -803,12 +821,7 @@ static void ParseOptionMenuBody(FScanner &sc, FOptionMenuDescriptor *desc) sc.MustGetStringName(","); sc.MustGetString(); FName action = sc.String; - bool cr = false; - if (sc.CheckString(",")) - { - sc.MustGetNumber(); - cr = !!sc.Number; - } + EColorRange cr = ParseOptionColor(sc, desc); FOptionMenuItem *it = new FOptionMenuItemStaticTextSwitchable(label, label2, action, cr); desc->mItems.Push(it); } diff --git a/src/menu/optionmenuitems.h b/src/menu/optionmenuitems.h index 8a1840027..3131e35f7 100644 --- a/src/menu/optionmenuitems.h +++ b/src/menu/optionmenuitems.h @@ -483,7 +483,13 @@ public: FOptionMenuItemStaticText(const char *label, bool header) : FOptionMenuItem(label, NAME_None, true) { - mColor = header? OptionSettings.mFontColorHeader : OptionSettings.mFontColor; + mColor = header ? OptionSettings.mFontColorHeader : OptionSettings.mFontColor; + } + + FOptionMenuItemStaticText(const char *label, EColorRange cr) + : FOptionMenuItem(label, NAME_None, true) + { + mColor = cr; } int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) @@ -512,10 +518,10 @@ class FOptionMenuItemStaticTextSwitchable : public FOptionMenuItem int mCurrent; public: - FOptionMenuItemStaticTextSwitchable(const char *label, const char *label2, FName action, bool header) + FOptionMenuItemStaticTextSwitchable(const char *label, const char *label2, FName action, EColorRange cr) : FOptionMenuItem(label, action, true) { - mColor = header? OptionSettings.mFontColorHeader : OptionSettings.mFontColor; + mColor = cr; mAltText = label2; mCurrent = 0; } From fc3682006a8700fc7097a43eb023de6847923be1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 30 Jun 2016 11:30:32 +0200 Subject: [PATCH 2/3] - fixed PointOnSide functions to consider 'on the line' as 'in front of'. The bad code was taken from the 2005 floating point rewrite that, by comparing the value with '> -EQUAL_EPSILON', returned 1 for any value close to 0 (as 'on the line') so it was mistakenly reported as 'behind the line'. --- src/p_maputl.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/p_maputl.h b/src/p_maputl.h index e5a8a5f4f..0e87e501a 100644 --- a/src/p_maputl.h +++ b/src/p_maputl.h @@ -38,17 +38,22 @@ struct intercept_t inline int P_PointOnLineSidePrecise(double x, double y, const line_t *line) { - return (y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - x) * line->Delta().Y > -EQUAL_EPSILON; + return (y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - x) * line->Delta().Y > EQUAL_EPSILON; } inline int P_PointOnLineSidePrecise(const DVector2 &pt, const line_t *line) { - return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > -EQUAL_EPSILON; + return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > EQUAL_EPSILON; } +extern line_t *lines; inline int P_PointOnLineSide (double x, double y, const line_t *line) { extern int P_VanillaPointOnLineSide(double x, double y, const line_t* line); + if (line - lines == 6180) + { + int a = 0; + } return i_compatflags2 & COMPATF2_POINTONLINE ? P_VanillaPointOnLineSide(x, y, line) : P_PointOnLineSidePrecise(x, y, line); @@ -73,12 +78,12 @@ inline int P_PointOnLineSide(const DVector2 & p, const line_t *line) inline int P_PointOnDivlineSide(double x, double y, const divline_t *line) { - return (y - line->y) * line->dx + (line->x - x) * line->dy > -EQUAL_EPSILON; + return (y - line->y) * line->dx + (line->x - x) * line->dy > EQUAL_EPSILON; } inline int P_PointOnDivlineSide(const DVector2 &pos, const divline_t *line) { - return (pos.Y - line->y) * line->dx + (line->x - pos.X) * line->dy > -EQUAL_EPSILON; + return (pos.Y - line->y) * line->dx + (line->x - pos.X) * line->dy > EQUAL_EPSILON; } //========================================================================== From 7bdb98cc0b3735c4c95cd45c11183e1147bfff26 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 30 Jun 2016 11:31:00 +0200 Subject: [PATCH 3/3] - removed debug stuff. --- src/p_maputl.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/p_maputl.h b/src/p_maputl.h index 0e87e501a..81d3c9d13 100644 --- a/src/p_maputl.h +++ b/src/p_maputl.h @@ -46,15 +46,9 @@ inline int P_PointOnLineSidePrecise(const DVector2 &pt, const line_t *line) return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > EQUAL_EPSILON; } -extern line_t *lines; inline int P_PointOnLineSide (double x, double y, const line_t *line) { extern int P_VanillaPointOnLineSide(double x, double y, const line_t* line); - if (line - lines == 6180) - { - int a = 0; - } - return i_compatflags2 & COMPATF2_POINTONLINE ? P_VanillaPointOnLineSide(x, y, line) : P_PointOnLineSidePrecise(x, y, line); }