[longomatch: 4/7] Make use of the new cairo helpers
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch: 4/7] Make use of the new cairo helpers
- Date: Sun, 6 Feb 2011 13:33:40 +0000 (UTC)
commit b17f1f9c84244360b1593dada00e8cfac995a803
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Sun Feb 6 01:03:26 2011 +0100
Make use of the new cairo helpers
LongoMatch/Gui/Component/TimeReferenceWidget.cs | 72 +++++++++--------------
LongoMatch/Gui/Component/TimeScale.cs | 71 +++++------------------
2 files changed, 43 insertions(+), 100 deletions(-)
---
diff --git a/LongoMatch/Gui/Component/TimeReferenceWidget.cs b/LongoMatch/Gui/Component/TimeReferenceWidget.cs
index 5030135..0b5d270 100644
--- a/LongoMatch/Gui/Component/TimeReferenceWidget.cs
+++ b/LongoMatch/Gui/Component/TimeReferenceWidget.cs
@@ -22,6 +22,7 @@ using System;
using Gtk;
using Gdk;
using Cairo;
+using LongoMatch.Common;
using LongoMatch.TimeNodes;
using Pango;
@@ -99,79 +100,62 @@ namespace LongoMatch.Gui.Component
this.CairoDraw(evnt,height,width);
else
this.GdkDraw(evnt,height,width);
-
-
-
-
return base.OnExposeEvent(evnt);
}
+
private void CairoDraw(EventExpose evnt,int height,int width) {
Time time = new Time();
using(Cairo.Context g = Gdk.CairoHelper.Create(evnt.Window)) {
- // Drawing main line
- g.Color = new Cairo.Color(0,0,0);
- g.MoveTo(currentFrame/pixelRatio,height);
- g.LineTo(currentFrame/pixelRatio+5,height-15);
- g.LineTo(currentFrame/pixelRatio-5,height-15);
- g.ClosePath();
- g.Fill();
- g.Stroke();
- g.MoveTo(new PointD(0,height));
- g.LineTo(new PointD(width,height));
- g.LineWidth = 2;
- g.Stroke();
- g.MoveTo(new PointD(0,height-20));
+ Cairo.Color color = new Cairo.Color(0, 0, 0);
+ /* Drawing position triangle */
+ CairoUtils.DrawTriangle(g,CurrentFrame/pixelRatio-Scroll, height, 10, 15, color);
+ /* Draw '0' */
+ CairoUtils.DrawLine(g, 0-Scroll, height, width, height, 2, color);
+ g.MoveTo(new PointD(0-Scroll,height-20));
g.ShowText("0");
- for (int i=10*frameRate; i<=frames/pixelRatio;) {
- g.MoveTo(new PointD(i,height));
- g.LineTo(new PointD(i,height-10));
- g.LineWidth = 2;
- g.Stroke();
-
-
- g.MoveTo(new PointD(i-13,height-20));
- time.MSeconds = (int)(i/frameRate*pixelRatio);
+ for (int i=10*FrameRate; i<=frames/pixelRatio;) {
+ CairoUtils.DrawLine(g, i-Scroll, height,i-Scroll,
+ height-10, 2, color);
+ g.MoveTo(new PointD(i-Scroll-13,height-20));
+ time.MSeconds = (int)(i/FrameRate*pixelRatio);
g.ShowText(time.ToSecondsString());
- i=i+10*frameRate;
+ i=i+10*FrameRate;
}
for (int i=0; i<=frames/pixelRatio;) {
- g.MoveTo(new PointD(i,height));
- g.LineTo(new PointD(i,height-5));
- g.LineWidth = 1;
- g.Stroke();
- i=i+frameRate;
+ CairoUtils.DrawLine(g, i-Scroll, height,i-Scroll,
+ height-5, 1, color);
+ i=i+FrameRate;
}
}
}
+
private void GdkDraw(EventExpose evnt,int height,int width) {
Time time = new Time();
layout.SetMarkup("0");
this.GdkWindow.DrawLayout(this.Style.TextGC(StateType.Normal),0,height-23,layout);
- Gdk.Point topL= new Gdk.Point((int)(currentFrame/pixelRatio-5),height-15);
- Gdk.Point topR= new Gdk.Point((int)(currentFrame/pixelRatio+5),height-15);
- Gdk.Point bottom= new Gdk.Point((int)(currentFrame/pixelRatio),height);
+ Gdk.Point topL= new Gdk.Point((int)(CurrentFrame/pixelRatio-Scroll-5),height-15);
+ Gdk.Point topR= new Gdk.Point((int)(CurrentFrame/pixelRatio-Scroll+5),height-15);
+ Gdk.Point bottom= new Gdk.Point((int)(CurrentFrame/pixelRatio-Scroll),height);
this.GdkWindow.DrawPolygon(this.Style.TextGC(StateType.Normal),true,new Gdk.Point[] {topL,topR,bottom});
- for (int i=10*frameRate; i<=frames/pixelRatio;) {
+ for (int i=10*FrameRate; i<=frames/pixelRatio;) {
// Drawing separator line
- evnt.Window.DrawLine(Style.DarkGC(StateType.Normal),i,height,i,height-10);
- time.MSeconds = (int)(i/frameRate*pixelRatio);
+ evnt.Window.DrawLine(Style.DarkGC(StateType.Normal),i-(int)Scroll,height,i-(int)Scroll,height-10);
+ time.MSeconds = (int)(i/FrameRate*pixelRatio);
layout.SetMarkup(time.ToSecondsString());
- this.GdkWindow.DrawLayout(this.Style.TextGC(StateType.Normal),i-13,height-23,layout);
+ this.GdkWindow.DrawLayout(this.Style.TextGC(StateType.Normal),i-(int)Scroll-13,height-23,layout);
//g.ShowText(time.ToSecondsString());
- i=i+10*frameRate;
+ i=i+10*FrameRate;
}
for (int i=0; i<=frames/pixelRatio;) {
- evnt.Window.DrawLine(Style.DarkGC(StateType.Normal),i,height,i,height-5);
- i=i+frameRate;
+ evnt.Window.DrawLine(Style.DarkGC(StateType.Normal),i-(int)Scroll,height,i-(int)Scroll,height-5);
+ i=i+FrameRate;
}
// Drawing main line
evnt.Window.DrawLine(Style.DarkGC(StateType.Normal),0,height,width,height);
}
-
-
}
}
diff --git a/LongoMatch/Gui/Component/TimeScale.cs b/LongoMatch/Gui/Component/TimeScale.cs
index 7d72acc..8af7146 100644
--- a/LongoMatch/Gui/Component/TimeScale.cs
+++ b/LongoMatch/Gui/Component/TimeScale.cs
@@ -25,6 +25,7 @@ using Gdk;
using Gtk;
using Pango;
using Mono.Unix;
+using LongoMatch.Common;
using LongoMatch.Handlers;
using LongoMatch.TimeNodes;
@@ -77,7 +78,7 @@ namespace LongoMatch.Gui.Component
this.list = list;
HeightRequest= SECTION_HEIGHT;
Size((int)(frames/pixelRatio),SECTION_HEIGHT);
- this.color = RGBToCairoColor(color);
+ this.color = CairoUtils.RGBToCairoColor(color);
this.color.A = ALPHA;
Events = EventMask.PointerMotionMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask ;
@@ -127,31 +128,6 @@ namespace LongoMatch.Gui.Component
GdkWindow.ProcessUpdates(true);
}
- private void DrawRoundedRectangle(Cairo.Context gr, double x, double y, double width, double height, double radius)
- {
- gr.Save();
-
- if ((radius > height / 2) || (radius > width / 2))
- radius = Math.Min(height / 2, width / 2);
-
- gr.MoveTo(x, y + radius);
- gr.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2);
- gr.LineTo(x + width - radius, y);
- gr.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0);
- gr.LineTo(x + width, y + height - radius);
- gr.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2);
- gr.LineTo(x + radius, y + height);
- gr.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI);
- gr.ClosePath();
- gr.Restore();
- }
-
-
- private Cairo.Color RGBToCairoColor(Gdk.Color gdkColor) {
- return new Cairo.Color((double)(gdkColor.Red)/ushort.MaxValue,
- (double)(gdkColor.Green)/ushort.MaxValue,
- (double)(gdkColor.Blue)/ushort.MaxValue);
- }
private void SetMenu() {
MenuItem newMediaTimeNode;
@@ -183,13 +159,10 @@ namespace LongoMatch.Gui.Component
foreach (MediaTimeNode tn in list) {
if (tn != selected) {
- DrawRoundedRectangle(g,tn.StartFrame/pixelRatio,3,tn.TotalFrames/pixelRatio,height-6,SECTION_HEIGHT/7);
- g.LineWidth = 2;
- g.Color = new Cairo.Color(color.R+0.1, color.G+0.1,color.B+0.1, 1);
- g.LineJoin = LineJoin.Round;
- g.StrokePreserve();
- g.Color = color;
- g.Fill();
+ Cairo.Color borderColor = new Cairo.Color(color.R+0.1, color.G+0.1,color.B+0.1, 1);
+ CairoUtils.DrawRoundedRectangle(g,tn.StartFrame/pixelRatio,3,
+ tn.TotalFrames/pixelRatio,height-6,
+ SECTION_HEIGHT/7, color, borderColor);
}
else {
hasSelectedTimeNode = true;
@@ -197,20 +170,15 @@ namespace LongoMatch.Gui.Component
}
//Then we draw the selected TimeNode over the others
if (hasSelectedTimeNode) {
- DrawRoundedRectangle(g,selected.StartFrame/pixelRatio,3,selected.TotalFrames/pixelRatio,height-6,SECTION_HEIGHT/7);
+ Cairo.Color borderColor = new Cairo.Color(color.R+0.1, color.G+0.1,color.B+0.1, 1);
+ CairoUtils.DrawRoundedRectangle(g,selected.StartFrame/pixelRatio,3,
+ selected.TotalFrames/pixelRatio,height-6,
+ SECTION_HEIGHT/7, color, borderColor);
if (selected.HasKeyFrame) {
g.MoveTo(selected.KeyFrame/pixelRatio,3);
g.LineTo(selected.KeyFrame/pixelRatio,SECTION_HEIGHT-3);
g.StrokePreserve();
}
- g.Color = new Cairo.Color(0, 0, 0, 1);
- g.LineWidth = 3;
- g.LineJoin = LineJoin.Round;
- g.Operator = Operator.Source;
- g.StrokePreserve();
- g.Operator = Operator.Over;
- g.Color = color;
- g.Fill();
}
DrawLines(win,g,height,width);
}
@@ -219,20 +187,11 @@ namespace LongoMatch.Gui.Component
private void DrawLines(Gdk.Window win, Cairo.Context g, int height, int width) {
if (Environment.OSVersion.Platform == PlatformID.Unix) {
- g.Operator = Operator.Over;
- g.Color = new Cairo.Color(0,0,0);
- g.LineWidth = 1;
- g.MoveTo(currentFrame/pixelRatio,0);
- g.LineTo(currentFrame/pixelRatio,height);
- g.Stroke();
- g.Color = new Cairo.Color(0,0,0);
- g.LineWidth = 2;
- g.MoveTo(0,0);
- g.LineTo(width,0);
- g.Stroke();
- g.MoveTo(0,height);
- g.LineTo(width,height);
- g.Stroke();
+ Cairo.Color color = new Cairo.Color(0,0,0);
+ CairoUtils.DrawLine(g, currentFrame/pixelRatio,0,currentFrame/pixelRatio,height,
+ 1, color);
+ CairoUtils.DrawLine(g,0 ,0, width, 0, 1, color);
+ CairoUtils.DrawLine(g,0 ,height, width, height, 1, color);
}
else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]