protected override bool OnExposeEvent(Gdk.EventExpose ev) { int width = Allocation.Width; int height = Allocation.Height; var bgColor = Style.Backgrounds[(int)State]; int imgWidth = (int)(pixbuf.Width / DpiScaling.Dialog); int imgHeight = (int)(pixbuf.Height / DpiScaling.Dialog); int x = (width - imgWidth) / 2; int y = (height - imgHeight) / 2; // Have to use Cairo here since i am unable to draw unpixelated bitmaps with Gdk. var ctx = CairoHelper.Create(ev.Window); CairoHelper.SetSourceColor(ctx, bgColor); ctx.Paint(); ctx.Translate(x, y); ctx.Scale(1.0f / DpiScaling.Dialog, 1.0f / DpiScaling.Dialog); CairoHelper.SetSourcePixbuf(ctx, pixbuf, 0, 0); ctx.Paint(); ctx.Target.Dispose(); ctx.Dispose(); return(true); }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { var bgColor = Style.Backgrounds[(int)State]; var fgColor = Style.Foregrounds[(int)State]; int width = Allocation.Width; int height = Allocation.Height; int imgWidth = (int)(pixbuf.Width / GLTheme.DialogScaling); int imgHeight = (int)(pixbuf.Height / GLTheme.DialogScaling); int x = buttonText == null ? (width - imgWidth) / 2 : 5; int y = (height - imgHeight) / 2; int yp = State == Gtk.StateType.Active ? 1 : 0; // Have to use Cairo here since i am unable to draw unpixelated bitmaps with Gdk. var ctx = CairoHelper.Create(ev.Window); CairoHelper.SetSourceColor(ctx, bgColor); ctx.Paint(); ctx.Translate(x, y + yp); ctx.Scale(1.0f / GLTheme.DialogScaling, 1.0f / GLTheme.DialogScaling); CairoHelper.SetSourcePixbuf(ctx, pixbuf, 0, 0); ctx.Paint(); if (buttonText != null) { CairoHelper.SetSourceColor(ctx, fgColor); ctx.Scale(1.0f, 1.0f); ctx.SelectFontFace("Quicksand", FontSlant.Normal, bold ? FontWeight.Bold : FontWeight.Normal); ctx.SetFontSize(14 * GLTheme.DialogScaling); ctx.MoveTo(20 * GLTheme.DialogScaling, 13 * GLTheme.DialogScaling); ctx.ShowText(buttonText); } ctx.Target.Dispose(); ctx.Dispose(); return(true); }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { int width = Allocation.Width; int height = Allocation.Height; #if FAMISTUDIO_MACOS var bgColor = Style.Backgrounds[(int)State]; var fgColor = Style.Foregrounds[(int)State]; int imgWidth = (int)(pixbuf.Width / GLTheme.DialogScaling); int imgHeight = (int)(pixbuf.Height / GLTheme.DialogScaling); int x = buttonText == null ? (width - imgWidth) / 2 : 5; int y = (height - imgHeight) / 2; int yp = State == Gtk.StateType.Active ? 1 : 0; // Have to use Cairo here since i am unable to draw unpixelated bitmaps with Gdk. var ctx = CairoHelper.Create(ev.Window); CairoHelper.SetSourceColor(ctx, bgColor); ctx.Paint(); ctx.Translate(x, y + yp); ctx.Scale(1.0f / GLTheme.DialogScaling, 1.0f / GLTheme.DialogScaling); CairoHelper.SetSourcePixbuf(ctx, pixbuf, 0, 0); ctx.Paint(); if (buttonText != null) { CairoHelper.SetSourceColor(ctx, fgColor); ctx.Scale(1.0f, 1.0f); ctx.SelectFontFace("Quicksand", FontSlant.Normal, bold ? FontWeight.Bold : FontWeight.Normal); ctx.SetFontSize(14 * GLTheme.DialogScaling); ctx.MoveTo(20 * GLTheme.DialogScaling, 13 * GLTheme.DialogScaling); ctx.ShowText(buttonText); } ctx.Target.Dispose(); ctx.Dispose(); #else using (Gdk.GC gc = new Gdk.GC((Drawable)base.GdkWindow)) { int x = layoutNormal == null ? (width - pixbuf.Width) / 2 : 5; int y = (height - pixbuf.Height) / 2; int yp = State == Gtk.StateType.Active ? 1 : 0; GdkWindow.DrawRectangle(Style.BackgroundGC(State), true, 0, 0, width, height); if (layoutNormal != null) { var layout = bold ? layoutBold : layoutNormal; layout.Width = -1; layout.GetSize(out _, out int layoutHeight); layoutHeight = Pango.Units.ToPixels(layoutHeight); GdkWindow.DrawPixbuf(gc, pixbuf, 0, 0, x, y + yp, pixbuf.Width, pixbuf.Height, RgbDither.None, 0, 0); GdkWindow.DrawLayout(Style.ForegroundGC(State), 10 + pixbuf.Width, (height - layoutHeight) / 2 + yp, layout); } else { GdkWindow.DrawPixbuf(gc, pixbuf, 0, 0, x, y + yp, pixbuf.Width, pixbuf.Height, RgbDither.None, 0, 0); } } #endif return(true); }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { Gdk.Rectangle alloc = this.Allocation; // XXX: Not sure why we need to transpose this. Probably // setting up our GdkWindow incorrectly. /*if (this.Toplevel as Gtk.Container != null) { * Container parent = this.Toplevel as Container; * alloc.X -= (int) parent.BorderWidth; * alloc.Y -= (int) parent.BorderWidth; * }*/ alloc.X = 0; alloc.Y = 0; using (Context cr = CairoHelper.Create(this.GdkWindow)) { //CrumbHelper.RoundedRectangle (cr, alloc, m_Radius); CairoFigures.AngleFrame(cr, alloc, -10, 0, 10, 0); // Fill in our default background cr.Pattern = m_NormalBg; cr.FillPreserve(); // Draw our outer line CairoHelper.SetSourceColor( cr, Style.Dark(StateType.Active)); cr.LineWidth = 1; cr.Stroke(); // Adjust our allocation to draw our inner line alloc.X += 1; alloc.Y += 1; alloc.Width -= 2; alloc.Height -= 2; // Draw and stroke our inner line //CrumbHelper.RoundedRectangle (cr, alloc, m_Radius); CairoFigures.AngleFrame(cr, alloc, -10, 0, 10, 0); CairoHelper.SetSourceColor( cr, Style.Light(StateType.Normal)); cr.LineWidth = 1; cr.Stroke(); int i = 0; foreach (Crumb crumb in this.m_Crumbs) { Gdk.Rectangle area = m_Coords[crumb]; // Pad the widget area area.X -= 5; area.Y -= 4; area.Width += 20; area.Height += 8; // Determine what corners we should draw // Corners corners; // if (i == 0) // corners = Corners.TopLeft | Corners.BottomLeft; // else if (i + 1 == m_Crumbs.Count) // corners = Corners.TopRight | Corners.BottomRight; // else // corners = Corners.None; bool isHover = crumb == Hover; bool isActive = crumb == Active; if (isHover || isActive) { // Select our area for background drawing // CrumbHelper.RoundedRectangle (cr, area, m_Radius, corners); CairoFigures.AngleFrame(cr, area, -10, 0, 10, 0); // Clear the background //cr.SetSourceRGB (1, 1, 1); //cr.FillPreserve (); // Style our background cr.Pattern = isActive ? m_SelectedBg : m_PrelightBg; cr.FillPreserve(); StateType state = isActive ? StateType.Selected : StateType.Active; // Draw outer line around it CairoHelper.SetSourceColor(cr, Style.Mid(state)); cr.LineWidth = 1; cr.Stroke(); area.X += 1; area.Y += 1; area.Width -= 2; area.Height -= 2; // Draw our inner highlight line //CrumbHelper.RoundedRectangle (cr, area, m_Radius, corners); CairoFigures.AngleFrame(cr, area, -10, 0, 10, 0); CairoHelper.SetSourceColor(cr, Style.Light(state)); cr.LineWidth = 1; cr.Stroke(); } // Draw our separator lines if needed // if (i + 1 != m_Crumbs.Count) { // cr.MoveTo (area.X + area.Width + 1, area.Y); // cr.LineTo (area.X + area.Width + 1, // area.Y + area.Height); // CairoHelper.SetSourceColor ( // cr, Style.Dark (StateType.Normal)); // cr.LineWidth = 1; // cr.Stroke (); // // cr.MoveTo (area.X + area.Width + 1.5, area.Y); // cr.LineTo (area.X + area.Width + 1.5, // area.Y + area.Height); // CairoHelper.SetSourceColor ( // cr, Style.Light (StateType.Normal)); // cr.LineWidth = 1; // cr.Stroke (); // } this.PropagateExpose(crumb.Widget, evnt); i++; } } return(true); }