~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/core/Mono.Texteditor/Mono.TextEditor/HelperMethods.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
Import upstream version 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// HelperMethods.cs
 
2
// 
 
3
// Cut & paste from PangoCairoHelper.
2
4
//
3
5
// Author:
 
6
//   Aaron Bockover <abockover@novell.com>
4
7
//   Mike Krüger <mkrueger@novell.com>
5
8
//
6
9
// Copyright (c) 2008 Novell, Inc (http://www.novell.com)
26
29
 
27
30
using System;
28
31
using System.Linq;
 
32
using System.Runtime.InteropServices;
29
33
 
30
34
namespace Mono.TextEditor
31
35
{
32
 
        internal static class HelperMethods
 
36
        public static class HelperMethods
33
37
        {
34
38
                public static T Kill<T>(this T gc) where T : IDisposable
35
39
                {
47
51
                        
48
52
                        return default(T);
49
53
                }
 
54
                
 
55
                
 
56
                [DllImport("libpangocairo-1.0-0.dll", CallingConvention=CallingConvention.Cdecl)]
 
57
                static extern void pango_cairo_show_layout (IntPtr cr, IntPtr layout);
 
58
 
 
59
                public static void ShowLayout (this Cairo.Context cr, Pango.Layout layout)
 
60
                {
 
61
                        pango_cairo_show_layout (cr == null ? IntPtr.Zero : cr.Handle, layout == null ? IntPtr.Zero : layout.Handle);
 
62
                }
 
63
 
 
64
                [DllImport("libpangocairo-1.0-0.dll", CallingConvention=CallingConvention.Cdecl)]
 
65
                static extern IntPtr pango_cairo_create_layout (IntPtr cr);
 
66
 
 
67
                public static Pango.Layout CreateLayout (this Cairo.Context cr)
 
68
                {
 
69
                        IntPtr raw_ret = pango_cairo_create_layout (cr == null ? IntPtr.Zero : cr.Handle);
 
70
                        return GLib.Object.GetObject (raw_ret) as Pango.Layout;
 
71
                }
 
72
 
 
73
                [DllImport("libpangocairo-1.0-0.dll", CallingConvention=CallingConvention.Cdecl)]
 
74
                static extern void pango_cairo_layout_path (IntPtr cr, IntPtr layout);
 
75
 
 
76
                public static void LayoutPath (this Cairo.Context cr, Pango.Layout layout)
 
77
                {
 
78
                        pango_cairo_layout_path (cr == null ? IntPtr.Zero : cr.Handle, layout == null ? IntPtr.Zero : layout.Handle);
 
79
                }
 
80
 
 
81
                [DllImport("libpangocairo-1.0-0.dll", CallingConvention=CallingConvention.Cdecl)]
 
82
                static extern void pango_cairo_context_set_resolution (IntPtr pango_context, double dpi);
 
83
 
 
84
                public static void ContextSetResolution (this Pango.Context context, double dpi)
 
85
                {
 
86
                        pango_cairo_context_set_resolution (context == null ? IntPtr.Zero : context.Handle, dpi);
 
87
                }
 
88
 
 
89
                [DllImport("libpangocairo-1.0-0.dll", CallingConvention=CallingConvention.Cdecl)]
 
90
                static extern IntPtr pango_layout_get_context (IntPtr layout);
 
91
 
 
92
                public static string GetColorString (Gdk.Color color)
 
93
                {
 
94
                        return string.Format ("#{0:X02}{1:X02}{2:X02}", color.Red / 256, color.Green / 256, color.Blue / 256);
 
95
                }
 
96
 
 
97
                public static Pango.Context LayoutGetContext (this Pango.Layout layout)
 
98
                {
 
99
                        IntPtr handle = pango_layout_get_context (layout.Handle);
 
100
                        return handle.Equals (IntPtr.Zero) ? null : GLib.Object.GetObject (handle) as Pango.Context;
 
101
                }
 
102
                
 
103
                public static void DrawLine (this Cairo.Context cr, Cairo.Color color, double x1, double y1, double x2, double y2)
 
104
                {
 
105
                        cr.Color = color;
 
106
                        cr.MoveTo (x1, y1);
 
107
                        cr.LineTo (x2, y2);
 
108
                        cr.Stroke ();
 
109
                }
 
110
                
 
111
                public static void Line (this Cairo.Context cr, double x1, double y1, double x2, double y2)
 
112
                {
 
113
                        cr.MoveTo (x1, y1);
 
114
                        cr.LineTo (x2, y2);
 
115
                }
 
116
                
 
117
                public static void SharpLineX (this Cairo.Context cr, double x1, double y1, double x2, double y2)
 
118
                {
 
119
                        cr.MoveTo (x1 + 0.5, y1);
 
120
                        cr.LineTo (x2 + 0.5, y2);
 
121
                }
 
122
                
 
123
                public static void SharpLineY (this Cairo.Context cr, double x1, double y1, double x2, double y2)
 
124
                {
 
125
                        cr.MoveTo (x1, y1 + 0.5);
 
126
                        cr.LineTo (x2, y2 + 0.5);
 
127
                }
50
128
        }
51
129
}