[chronojump] cairo printText can be aligned at right
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] cairo printText can be aligned at right
- Date: Mon, 17 Aug 2020 10:50:42 +0000 (UTC)
commit 9c1485c7f2509064e97c6751f5ab2b3d878fafe2
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Aug 17 12:46:48 2020 +0200
cairo printText can be aligned at right
src/gui/cairo/jumpsDjOptimalFall.cs | 2 +-
src/gui/cairo/jumpsEvolution.cs | 2 +-
src/gui/cairo/jumpsWeightFVProfile.cs | 2 +-
src/gui/cairo/xy.cs | 22 ++++++++++++++--------
4 files changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/src/gui/cairo/jumpsDjOptimalFall.cs b/src/gui/cairo/jumpsDjOptimalFall.cs
index 5055bcc7..9475e674 100644
--- a/src/gui/cairo/jumpsDjOptimalFall.cs
+++ b/src/gui/cairo/jumpsDjOptimalFall.cs
@@ -37,7 +37,7 @@ public class JumpsDjOptimalFallGraph : CairoXY
g.SetFontSize(16);
printText(area.Allocation.Width /2, area.Allocation.Height /2, 24, textHeight,
- needToExecuteJumpsStr + " " + jumpType + ".", g, true);
+ needToExecuteJumpsStr + " " + jumpType + ".", g, alignTypes.CENTER);
endGraph();
}
diff --git a/src/gui/cairo/jumpsEvolution.cs b/src/gui/cairo/jumpsEvolution.cs
index 74b2fa7a..b4c2108a 100644
--- a/src/gui/cairo/jumpsEvolution.cs
+++ b/src/gui/cairo/jumpsEvolution.cs
@@ -36,7 +36,7 @@ public class JumpsEvolutionGraph : CairoXY
g.SetFontSize(16);
printText(area.Allocation.Width /2, area.Allocation.Height /2, 24, textHeight,
- needToExecuteJumpsStr + " " + jumpType + ".", g, true);
+ needToExecuteJumpsStr + " " + jumpType + ".", g, alignTypes.CENTER);
endGraph();
}
diff --git a/src/gui/cairo/jumpsWeightFVProfile.cs b/src/gui/cairo/jumpsWeightFVProfile.cs
index c3dc40dc..c34cc3a4 100644
--- a/src/gui/cairo/jumpsWeightFVProfile.cs
+++ b/src/gui/cairo/jumpsWeightFVProfile.cs
@@ -119,7 +119,7 @@ public class JumpsWeightFVProfileGraph : CairoXY
message = Catalog.GetString("V0 is not > 0.");
g.SetFontSize(16);
- printText(area.Allocation.Width /2, area.Allocation.Height /2, 24, textHeight, message, g,
true);
+ printText(area.Allocation.Width /2, area.Allocation.Height /2, 24, textHeight, message, g,
alignTypes.CENTER);
}
public override void Do()
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index 49230831..9039ea60 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -293,8 +293,8 @@ public abstract class CairoXY
g.LineTo(outerMargins, graphHeight - outerMargins);
g.LineTo(graphWidth - outerMargins, graphHeight - outerMargins);
g.Stroke ();
- printText(2, Convert.ToInt32(outerMargins/2), 0, textHeight, getYAxisLabel(), g, false);
- printText(graphWidth - Convert.ToInt32(outerMargins/2), graphHeight - outerMargins, 0,
textHeight, getXAxisLabel(), g, false);
+ printText(2, Convert.ToInt32(outerMargins/2), 0, textHeight, getYAxisLabel(), g,
alignTypes.LEFT);
+ printText(graphWidth - Convert.ToInt32(outerMargins/2), graphHeight - outerMargins, 0,
textHeight, getXAxisLabel(), g, alignTypes.LEFT);
g.Stroke ();
g.LineWidth = 2;
@@ -471,7 +471,7 @@ public abstract class CairoXY
if(bold)
g.SelectFontFace("Helvetica", Cairo.FontSlant.Normal, Cairo.FontWeight.Bold);
- printText(graphWidth, Convert.ToInt32(graphHeight/2 + textHeight*2*line), 0, textHeight,
text, g, false);
+ printText(graphWidth, Convert.ToInt32(graphHeight/2 + textHeight*2*line), 0, textHeight,
text, g, alignTypes.LEFT);
if(bold)
g.SelectFontFace("Helvetica", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
@@ -628,13 +628,13 @@ public abstract class CairoXY
{
g.MoveTo(outerMargins, ytemp);
g.LineTo(graphWidth - outerMargins, ytemp);
- printText(Convert.ToInt32(outerMargins/2), ytemp, 0, textHeight, text, g, true);
+ printText(Convert.ToInt32(outerMargins/2), ytemp, 0, textHeight, text, g, alignTypes.CENTER);
}
protected void paintVerticalGridLine(int xtemp, string text)
{
g.MoveTo(xtemp, graphHeight - outerMargins);
g.LineTo(xtemp, outerMargins);
- printText(xtemp, graphHeight - Convert.ToInt32(outerMargins/2), 0, textHeight, text, g, true);
+ printText(xtemp, graphHeight - Convert.ToInt32(outerMargins/2), 0, textHeight, text, g,
alignTypes.CENTER);
}
@@ -762,15 +762,21 @@ public abstract class CairoXY
return new Cairo.Color(red/256.0, green/256.0, blue/256.0);
}
- protected void printText (int x, int y, int height, int textHeight, string text, Cairo.Context g,
bool centered)
+ protected enum alignTypes { LEFT, CENTER, RIGHT }
+ protected void printText (int x, int y, int height, int textHeight, string text, Cairo.Context g,
alignTypes align)
{
int moveToLeft = 0;
- if(centered)
+ if(align == alignTypes.CENTER || align == alignTypes.RIGHT)
{
Cairo.TextExtents te;
te = g.TextExtents(text);
- moveToLeft = Convert.ToInt32(te.Width/2);
+
+ if(align == alignTypes.CENTER)
+ moveToLeft = Convert.ToInt32(te.Width/2);
+ else
+ moveToLeft = Convert.ToInt32(te.Width);
}
+
g.MoveTo( x - moveToLeft, ((y+y+height)/2) + textHeight/2 );
g.ShowText(text);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]