2
// WelcomePageListButton.cs
5
// lluis <${AuthorEmail}>
7
// Copyright (c) 2012 lluis
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
using MonoDevelop.Core;
28
using MonoDevelop.Components;
31
namespace MonoDevelop.Ide.WelcomePage
33
public class WelcomePageListButton: EventBox
35
private static Gdk.Cursor hand_cursor = new Gdk.Cursor(Gdk.CursorType.Hand1);
36
string title, subtitle, actionUrl;
40
Gdk.Rectangle starRect;
43
static Gdk.Pixbuf starNormal;
44
static Gdk.Pixbuf starNormalHover;
45
static Gdk.Pixbuf starPinned;
46
static Gdk.Pixbuf starPinnedHover;
48
public event EventHandler PinClicked;
50
public bool DrawLeftBorder { get; set; }
51
public bool DrawRightBorder { get; set; }
53
public int BorderPadding { get; set; }
55
public int LeftTextPadding { get; set; }
56
public int InternalPadding { get; set; }
58
static WelcomePageListButton ()
60
starNormal = Gdk.Pixbuf.LoadFromResource ("star-normal.png");
61
starNormalHover = Gdk.Pixbuf.LoadFromResource ("star-normal-hover.png");
62
starPinned = Gdk.Pixbuf.LoadFromResource ("star-pinned.png");
63
starPinnedHover = Gdk.Pixbuf.LoadFromResource ("star-pinned-hover.png");
66
public WelcomePageListButton (string title, string subtitle, Gdk.Pixbuf icon, string actionUrl)
68
VisibleWindow = false;
70
this.subtitle = subtitle;
72
this.actionUrl = actionUrl;
73
WidthRequest = Styles.WelcomeScreen.Pad.Solutions.SolutionTile.Width;
74
HeightRequest = Styles.WelcomeScreen.Pad.Solutions.SolutionTile.Height + 2;
75
Events |= (Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask);
77
LeftTextPadding = Styles.WelcomeScreen.Pad.Solutions.SolutionTile.TextLeftPadding;
78
InternalPadding = Styles.WelcomeScreen.Pad.Padding;
81
public bool AllowPinning { get; set; }
84
get { return pinned; }
91
protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
93
GdkWindow.Cursor = hand_cursor;
96
return base.OnEnterNotifyEvent (evnt);
99
protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
101
GdkWindow.Cursor = null;
104
return base.OnLeaveNotifyEvent (evnt);
107
protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
109
if (evnt.Button == 1) {
110
if (mouseOverStar && AllowPinning) {
113
if (PinClicked != null)
114
PinClicked (this, EventArgs.Empty);
116
} else if (mouseOver) {
117
WelcomePageSection.DispatchLink (actionUrl);
121
return base.OnButtonReleaseEvent (evnt);
124
protected override bool OnMotionNotifyEvent (Gdk.EventMotion evnt)
126
var so = starRect.Contains (Allocation.X + (int)evnt.X, Allocation.Y + (int)evnt.Y);
127
if (so != mouseOverStar) {
131
return base.OnMotionNotifyEvent (evnt);
134
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
136
using (var ctx = Gdk.CairoHelper.Create (evnt.Window)) {
138
if (BorderPadding <= 0) {
139
ctx.Rectangle (Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
140
ctx.Color = CairoExtensions.ParseColor (Styles.WelcomeScreen.Pad.Solutions.SolutionTile.HoverBackgroundColor);
142
ctx.MoveTo (Allocation.X, Allocation.Y + 0.5);
143
ctx.RelLineTo (Allocation.Width, 0);
144
ctx.MoveTo (Allocation.X, Allocation.Y + Allocation.Height - 0.5);
145
ctx.RelLineTo (Allocation.Width, 0);
147
if (DrawRightBorder) {
148
ctx.MoveTo (Allocation.Right + 0.5, Allocation.Y + 0.5);
149
ctx.LineTo (Allocation.Right + 0.5, Allocation.Bottom - 0.5);
151
if (DrawLeftBorder) {
152
ctx.MoveTo (Allocation.Left + 0.5, Allocation.Y + 0.5);
153
ctx.LineTo (Allocation.Left + 0.5, Allocation.Bottom - 0.5);
157
ctx.Color = CairoExtensions.ParseColor (Styles.WelcomeScreen.Pad.Solutions.SolutionTile.HoverBorderColor);
160
Gdk.Rectangle region = Allocation;
161
region.Inflate (-BorderPadding, -BorderPadding);
163
ctx.RoundedRectangle (region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 3);
164
ctx.Color = CairoExtensions.ParseColor (Styles.WelcomeScreen.Pad.Solutions.SolutionTile.HoverBackgroundColor);
168
ctx.Color = CairoExtensions.ParseColor (Styles.WelcomeScreen.Pad.Solutions.SolutionTile.HoverBorderColor);
175
int x = Allocation.X + InternalPadding;
176
int y = Allocation.Y + (Allocation.Height - icon.Height) / 2;
177
Gdk.CairoHelper.SetSourcePixbuf (ctx, icon, x, y);
180
if (AllowPinning && (mouseOver || pinned)) {
184
star = starPinnedHover;
189
star = starNormalHover;
193
x = x + icon.Width - star.Width + 3;
194
y = y + icon.Height - star.Height + 3;
195
Gdk.CairoHelper.SetSourcePixbuf (ctx, star, x, y);
197
starRect = new Gdk.Rectangle (x, y, star.Width, star.Height);
202
int textWidth = Allocation.Width - LeftTextPadding - InternalPadding * 2;
204
var face = Platform.IsMac ? Styles.WelcomeScreen.Pad.TitleFontFamilyMac : Styles.WelcomeScreen.Pad.TitleFontFamilyWindows;
205
Pango.Layout titleLayout = new Pango.Layout (PangoContext);
206
titleLayout.Width = Pango.Units.FromPixels (textWidth);
207
titleLayout.Ellipsize = Pango.EllipsizeMode.End;
208
titleLayout.SetMarkup (WelcomePageSection.FormatText (face, Styles.WelcomeScreen.Pad.Solutions.SolutionTile.TitleFontSize, false, Styles.WelcomeScreen.Pad.MediumTitleColor, title));
210
Pango.Layout subtitleLayout = null;
212
if (!string.IsNullOrEmpty (subtitle)) {
213
subtitleLayout = new Pango.Layout (PangoContext);
214
subtitleLayout.Width = Pango.Units.FromPixels (textWidth);
215
subtitleLayout.Ellipsize = Pango.EllipsizeMode.Start;
216
subtitleLayout.SetMarkup (WelcomePageSection.FormatText (face, Styles.WelcomeScreen.Pad.Solutions.SolutionTile.PathFontSize, false, Styles.WelcomeScreen.Pad.SmallTitleColor, subtitle));
221
titleLayout.GetPixelSize (out w, out h1);
224
if (subtitleLayout != null) {
225
height += Styles.WelcomeScreen.Pad.Solutions.SolutionTile.TitleBottomMargin;
226
subtitleLayout.GetPixelSize (out w, out h2);
230
int tx = Allocation.X + InternalPadding + LeftTextPadding;
231
int ty = Allocation.Y + (Allocation.Height - height) / 2;
233
Pango.CairoHelper.ShowLayout (ctx, titleLayout);
235
if (subtitleLayout != null) {
236
ty += h1 + Styles.WelcomeScreen.Pad.Solutions.SolutionTile.TitleBottomMargin;
238
Pango.CairoHelper.ShowLayout (ctx, subtitleLayout);