[chronojump/FS-TFT-Menu] Cairo encoder bars title managing loss color done!
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/FS-TFT-Menu] Cairo encoder bars title managing loss color done!
- Date: Wed, 20 Apr 2022 11:59:21 +0000 (UTC)
commit 9a80d4126f28f7005b0bd57783564e437bae86ee
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Mar 28 17:30:27 2022 +0200
Cairo encoder bars title managing loss color done!
src/gui/cairo/bars.cs | 110 +++++++++++++++++++++++++++++++++++++++++++-----
src/gui/eventExecute.cs | 45 ++++++++++----------
2 files changed, 122 insertions(+), 33 deletions(-)
---
diff --git a/src/gui/cairo/bars.cs b/src/gui/cairo/bars.cs
index 3e2c183db..5a8151096 100644
--- a/src/gui/cairo/bars.cs
+++ b/src/gui/cairo/bars.cs
@@ -32,11 +32,17 @@ public abstract class CairoBars : CairoGeneric
protected int fontHeightAboveBar; //will be reduced if does not fit. On encoder is bigger than other
places, pass -1 if don't want to define
protected int fontHeightForBottomNames;
protected int marginForBottomNames;
- protected string title;
protected bool clickable;
protected bool paintAxis;
protected bool paintGrid; //if paint grid, then paint a rectangle below resultOnBar (on encoder:
false)
+ protected string titleStr;
+ //3 encoder title variales
+ protected string lossStr; //loss in grey
+ protected string workStr;
+ protected string impulseStr;
+ protected bool encoderTitle; //boolean meaning previous variables are used, SetEncoderTitle() has
been called
+
//protected string jumpType;
//protected string runType;
protected string date;
@@ -92,6 +98,7 @@ public abstract class CairoBars : CairoGeneric
initGraph(font, 1); //.8 if writeTextAtRight
barsXCenter_l = new List<double>();
resultOnBars_l = new List<Point3F>();
+ encoderTitle = false;
}
public void PassGuidesData (CairoBarsGuideManage cairoBarsGuideManage)
@@ -278,7 +285,7 @@ public abstract class CairoBars : CairoGeneric
public virtual void PassData1Serie (List<PointF> pointMain_l,
List<Cairo.Color> colorMain_l, List<string> names_l,
int fontHeightAboveBar, int fontHeightForBottomNames, int marginForBottomNames,
- string title)
+ string titleStr)
{
//defined in CairoBars1Series
}
@@ -287,7 +294,7 @@ public abstract class CairoBars : CairoGeneric
List<Cairo.Color> colorMain_l, List<Cairo.Color> colorSecondary_l, List<string>
names_l,
string labelBarMain, string labelBarSecondary, bool labelRotateInFirstBar,
int fontHeightAboveBar, int fontHeightForBottomNames, int marginForBottomNames,
- string title)
+ string titleStr)
{
//defined in CairoBarsNHSeries
}
@@ -748,8 +755,73 @@ public abstract class CairoBars : CairoGeneric
protected void writeTitleAtTop()
{
+ if(encoderTitle)
+ {
+ writeTitleAtTopEncoder ();
+ return;
+ }
+
printText(graphWidth/2 + leftMargin, textHeight/2, 0, textHeight+2,
- title, g, alignTypes.CENTER);
+ titleStr, g, alignTypes.CENTER);
+ }
+
+ protected void writeTitleAtTopEncoder()
+ {
+ g.Save();
+
+ //have title and titleFull to be able to position all perfectly but having two pens (colors)
+ string titleFull = titleStr + lossStr + workStr + impulseStr;
+
+ // 1) get the titleTextHeight for titleFull
+ int titleTextHeight = textHeight +2;
+ g.SetFontSize(titleTextHeight);
+ Cairo.TextExtents te = g.TextExtents(titleFull);
+
+ if (te.Width > graphWidth) //margins?
+ {
+ do {
+ titleTextHeight --;
+ if(titleTextHeight <= 1)
+ {
+ titleTextHeight = 1;
+ g.SetFontSize(titleTextHeight);
+ te = g.TextExtents(titleFull);
+ break;
+ }
+ g.SetFontSize(titleTextHeight);
+ te = g.TextExtents(titleFull);
+ } while (te.Width > graphWidth); //margins?
+ }
+ double titleFullWidth = te.Width;
+ //g.SetFontSize(titleTextHeight);
+
+ // 2) get the width to paint each string at its position
+ //double titleWidth = (g.TextExtents(titleStr)).Width;
+ double titleWidth = (g.TextExtents(titleStr)).XAdvance; //used this becuase the ending
whitespace is not used on Width calculation
+ double lossWidth = (g.TextExtents(lossStr)).Width;
+ double workWidth = (g.TextExtents(workStr)).Width;
+ //double impulseWidth = (g.TextExtents(impulseStr)).Width;
+
+ // 3) paint title, loss, work, impulse
+ g.SetSourceColor(black);
+ printText(graphWidth/2 -titleFullWidth/2, textHeight/2, 0, titleTextHeight,
+ titleStr, g, alignTypes.LEFT);
+
+ if(lossStr != "")
+ {
+ g.SetSourceColor(gray99); //darker than the arrow line
+ printText(graphWidth/2 -titleFullWidth/2 + titleWidth, textHeight/2, 0,
titleTextHeight,
+ lossStr, g, alignTypes.LEFT);
+ g.SetSourceColor(black);
+ }
+
+ printText(graphWidth/2 -titleFullWidth/2 + titleWidth +lossWidth, textHeight/2, 0,
titleTextHeight,
+ workStr, g, alignTypes.LEFT);
+
+ printText(graphWidth/2 -titleFullWidth/2 + titleWidth +lossWidth +workWidth, textHeight/2, 0,
titleTextHeight,
+ impulseStr, g, alignTypes.LEFT);
+
+ g.Restore();
}
protected void writeMessageAtCenter(string message)
@@ -782,12 +854,12 @@ public abstract class CairoBars : CairoGeneric
{
int ypos = -6;
- //writeTextAtRight(ypos++, title, true);
+ //writeTextAtRight(ypos++, titleStr, true);
//writeTextAtRight(ypos++, jumpTypeStr + " " + jumpType, false);
//writeTextAtRight(ypos++, date, false);
printText(graphWidth, Convert.ToInt32(graphHeight/2 + textHeight*2), 0, textHeight,
- title, g, alignTypes.LEFT);
+ titleStr, g, alignTypes.LEFT);
}
*/
@@ -815,6 +887,20 @@ public abstract class CairoBars : CairoGeneric
return mouseLimits.FindBarInPixel(pixel);
}
+ /*
+ encoder title has different strings, one of them in grey, more or less on the center
+ we need to pass the strings here to create the title
+ */
+ public void SetEncoderTitle (string titleStr, string lossStr, string workStr, string impulseStr)
+ {
+ this.titleStr = titleStr;
+ this.lossStr = lossStr;
+ this.workStr = workStr;
+ this.impulseStr = impulseStr;
+
+ encoderTitle = true;
+ }
+
public string YVariable {
set { yVariable = value; }
}
@@ -926,7 +1012,7 @@ public class CairoBars1Series : CairoBars
public override void PassData1Serie (List<PointF> pointMain_l,
List<Cairo.Color> colorMain_l, List<string> names_l,
int fontHeightAboveBar, int fontHeightForBottomNames, int marginForBottomNames,
- string title)
+ string titleStr)
{
this.pointMain_l = pointMain_l;
this.colorMain_l = colorMain_l;
@@ -934,7 +1020,9 @@ public class CairoBars1Series : CairoBars
this.fontHeightAboveBar = fontHeightAboveBar;
this.fontHeightForBottomNames = fontHeightForBottomNames;
this.marginForBottomNames = marginForBottomNames;
- this.title = title;
+
+ if(! encoderTitle)
+ this.titleStr = titleStr;
}
public override void GraphDo ()
@@ -1304,7 +1392,7 @@ public class CairoBarsNHSeries : CairoBars
List<Cairo.Color> colorMain_l, List<Cairo.Color> colorSecondary_l, List<string>
names_l,
string labelBarMain, string labelBarSecondary, bool labelRotateInFirstBar,
int fontHeightAboveBar, int fontHeightForBottomNames, int marginForBottomNames,
- string title)
+ string titleStr)
{
this.pointSecondary_ll = pointSecondary_ll;
this.pointMain_l = pointMain_l;
@@ -1317,7 +1405,9 @@ public class CairoBarsNHSeries : CairoBars
this.fontHeightAboveBar = fontHeightAboveBar;
this.fontHeightForBottomNames = fontHeightForBottomNames;
this.marginForBottomNames = marginForBottomNames;
- this.title = title;
+
+ if(! encoderTitle)
+ this.titleStr = titleStr;
}
public override void GraphDo ()
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index b2b2bb71d..87652b669 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -3405,6 +3405,11 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
private List<Cairo.Color> colorSecondary_l;
private List<string> names_l;
+ private string titleStr;
+ private string lossStr;
+ private string workStr;
+ private string impulseStr;
+
//just blank the screen
public CairoPaintBarplotPreEncoder (DrawingArea darea, string fontStr)
{
@@ -3837,28 +3842,28 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
//LogB.Information(string.Format("sumSaved: {0}, countSaved: {1}, div: {2}", sumSaved,
countSaved, sumSaved / countSaved));
//add avg and avg of saved values
- string title = pegbe.mainVariable + " [X: " +
+ titleStr = pegbe.mainVariable + " [X: " +
Util.TrimDecimals( (sumValid / countValid), decimals) +
" " + units + "; ";
if(countSaved > 0)
- title += "X" + Catalog.GetString("saved") + ": " +
+ titleStr += "X" + Catalog.GetString("saved") + ": " +
Util.TrimDecimals( (sumSaved / countSaved), decimals) +
" " + units;
- string lossString = "";
+ lossStr = "";
- //do not show lossString on Preferences.EncoderPhasesEnum.ECC
+ //do not show lossStr on Preferences.EncoderPhasesEnum.ECC
if( pegbe.showLoss && (pegbe.eccon == "c" || preferences.encoderCaptureFeedbackEccon !=
Preferences.EncoderPhasesEnum.ECC) )
{
- title += "; ";
- lossString = "Loss: ";
+ titleStr += "; ";
+ lossStr = "Loss: ";
if(pegbe.eccon != "c")
- lossString = "Loss (con): "; //on ecc/con use only con for loss calculation
+ lossStr = "Loss (con): "; //on ecc/con use only con for loss calculation
if(maxThisSetValidAndCon > 0)
{
- lossString += Util.TrimDecimals(
+ lossStr += Util.TrimDecimals(
100.0 * (maxThisSetValidAndCon - minThisSetValidAndCon) /
maxThisSetValidAndCon, decimals) + "%";
//LogB.Information(string.Format("Loss at plot: {0}", 100.0 *
(maxThisSetValidAndCon - minThisSetValidAndCon) / maxThisSetValidAndCon));
}
@@ -3866,23 +3871,14 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
//work and impulse are in separate string variables because maybe we will select to show one
or the other
//work
- string workString = "] " + Catalog.GetString("Work") + ": " + Util.TrimDecimals(workTotal,
decimals);
+ workStr = "] " + Catalog.GetString("Work") + ": " + Util.TrimDecimals(workTotal, decimals);
if(preferences.encoderWorkKcal)
- workString += " Kcal";
+ workStr += " Kcal";
else
- workString += " J";
+ workStr += " J";
//impulse
- string impulseString = " " + Catalog.GetString("Impulse") + ": " +
Util.TrimDecimals(impulseTotal, decimals) + " N*s";
-
- //have title and titleFull to be able to position all perfectly but having two pens (colors)
- string titleFull = title + lossString + workString + impulseString;
-
-
- /*
- // 1) get the width of titleFull, title, lossString
- ... do it on barplot
- */
+ impulseStr = " " + Catalog.GetString("Impulse") + ": " + Util.TrimDecimals(impulseTotal,
decimals) + " N*s";
}
private void prepareLossArrow ()
@@ -3928,10 +3924,13 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
if(dataSecondary_l.Count > 0)
cb.PassDataSecondary (dataSecondary_l);
+ //this should be passed before PassData1Serie && PassData2Series
+ cb.SetEncoderTitle (titleStr, lossStr, workStr, impulseStr);
+
if(pegbe.eccon == "c")
cb.PassData1Serie (dataA_l,
colorMain_l, names_l,
- 20, 14, 8, "my title");
+ 20, 14, 8, "");
else {
List<List<PointF>> pointSecondary_ll = new List<List<PointF>>();
pointSecondary_ll.Add(dataA_l);
@@ -3939,7 +3938,7 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
cb.PassData2Series (dataB_l, pointSecondary_ll, false,
colorMain_l, colorSecondary_l, names_l,
"Ecc", "Con", true,
- 20, 14, 8, "my title");
+ 20, 14, 8, "");
}
cb.GraphDo();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]