no more submodule

This commit is contained in:
2024-09-15 22:40:48 +02:00
parent df3b8a3135
commit 0234b33671
5804 changed files with 943618 additions and 1 deletions

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.18"/>
<template class="CompositeWidget" parent="GtkBin">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButton" id="btn1">
<property name="label" translatable="yes">Instance handler</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="margin-start">3</property>
<property name="margin-end">3</property>
<property name="margin-top">3</property>
<property name="margin-bottom">3</property>
<signal name="clicked" handler="on_btn1_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn2">
<property name="label" translatable="yes">Static handler</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="margin-start">3</property>
<property name="margin-end">3</property>
<property name="margin-top">3</property>
<property name="margin-bottom">3</property>
<signal name="clicked" handler="on_btn2_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="label">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">3</property>
<property name="margin-end">3</property>
<property name="margin-top">3</property>
<property name="margin-bottom">3</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</template>
</interface>

View File

@@ -0,0 +1,77 @@
// CustomCellRenderer.cs : C# implementation of an example custom cellrenderer
// from http://scentric.net/tutorial/sec-custom-cell-renderers.html
//
// Author: Todd Berman <tberman@sevenl.net>
//
// (c) 2004 Todd Berman
// adopted from: https://github.com/mono/gtk-sharp/commits/2.99.3/sample/CustomCellRenderer.cs
using System;
using Gtk;
using Gdk;
using GLib;
namespace Samples
{
public class CustomCellRenderer : CellRenderer
{
private float percent;
[GLib.Property ("percent")]
public float Percentage {
get { return percent; }
set { percent = value; }
}
protected override void OnGetSize (Widget widget, ref Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height)
{
base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height);
int calc_width = (int) this.Xpad * 2 + 100;
int calc_height = (int) this.Ypad * 2 + 10;
width = calc_width;
height = calc_height;
x_offset = 0;
y_offset = 0;
if (!cell_area.Equals (Rectangle.Zero)) {
x_offset = (int) (this.Xalign * (cell_area.Width - calc_width));
x_offset = Math.Max (x_offset, 0);
y_offset = (int) (this.Yalign * (cell_area.Height - calc_height));
y_offset = Math.Max (y_offset, 0);
}
}
protected override void OnRender (Cairo.Context cr, Widget widget, Rectangle background_area, Rectangle cell_area, CellRendererState flags)
{
int x = (int) (cell_area.X + this.Xpad);
int y = (int) (cell_area.Y + this.Ypad);
int width = (int) (cell_area.Width - this.Xpad * 2);
int height = (int) (cell_area.Height - this.Ypad * 2);
widget.StyleContext.Save ();
widget.StyleContext.AddClass ("trough");
widget.StyleContext.RenderBackground (cr, x, y, width, height);
widget.StyleContext.RenderFrame (cr, x, y, width, height);
Border padding = widget.StyleContext.GetPadding (StateFlags.Normal);
x += padding.Left;
y += padding.Top;
width -= padding.Left + padding.Right;
height -= padding.Top + padding.Bottom;
widget.StyleContext.Restore ();
widget.StyleContext.Save ();
widget.StyleContext.AddClass ("progressbar");
widget.StyleContext.RenderActivity (cr, x, y, (int) (width * Percentage), height);
widget.StyleContext.Restore ();
}
}
}

View File

@@ -0,0 +1,110 @@
// adopted from: https://github.com/mono/xwt/blob/master/Xwt.XamMac/Xwt.Mac/ImageHandler.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Gtk;
using Gdk;
using System.Runtime.InteropServices;
using Cairo;
using Rectangle = Gdk.Rectangle;
namespace Samples
{
// This is a completely pointless widget, but its for testing subclassing Widget.OnDrawn
public class GtkDrawingArea : Gtk.DrawingArea { }
public class ImageBox : GtkDrawingArea
{
Pixbuf image;
float yalign = 0.5f, xalign = 0.5f;
public ImageBox(Pixbuf img) : this()
{
Image = img;
}
public ImageBox()
{
this.HasWindow = false;
this.AppPaintable = true;
}
public Pixbuf Image {
get { return image; }
set {
image = value;
SetSizeRequest((int) image.Width, (int) image.Height);
//QueueDraw();
}
}
private Size SizeRequestet { get; set; }
public float Yalign {
get { return yalign; }
set {
yalign = value;
QueueDraw();
}
}
public float Xalign {
get { return xalign; }
set {
xalign = value;
QueueDraw();
}
}
void DrawPixbuf(Cairo.Context ctx, Gdk.Pixbuf img, double x, double y, Size idesc)
{
ctx.Save();
ctx.Translate(x, y);
ctx.Scale(idesc.Width / (double) img.Width, idesc.Height / (double) img.Height);
Gdk.CairoHelper.SetSourcePixbuf(ctx, img, 0, 0);
#pragma warning disable 618
using (var p = ctx.Source) {
if (p is SurfacePattern pattern) {
if (idesc.Width > img.Width || idesc.Height > img.Height) {
// Fixes blur issue when rendering on an image surface
pattern.Filter = Cairo.Filter.Fast;
} else
pattern.Filter = Cairo.Filter.Good;
}
}
#pragma warning restore 618
ctx.Paint();
ctx.Restore();
}
protected override bool OnDrawn(Cairo.Context cr)
{
if (image == default)
return true;
var a = Allocation;
var size = Allocation.Size;
Pixbuf pixbuff = image;
// HACK: Gtk sends sometimes an expose/draw event while the widget reallocates.
// In that case we would draw in the wrong area, which may lead to artifacts
// if no other widget updates it. Alternative: we could clip the
// allocation bounds, but this may have other issues.
if (a.Width == 1 && a.Height == 1 && a.X == -1 && a.Y == -1) // the allocation coordinates on reallocation
return base.OnDrawn(cr);
var x = (int) ((a.Width - (float) pixbuff.Width) * xalign);
var y = (int) ((a.Height - (float) pixbuff.Height) * yalign);
if (x < 0) x = 0;
if (y < 0) y = 0;
DrawPixbuf(cr, pixbuff, x, y, size);
return base.OnDrawn(cr);
}
}
}

View File

@@ -0,0 +1,196 @@
// adopted from: https://github.com/mono/gtk-sharp/commits/2.99.3/sample/PolarFixed.cs
// This is a completely pointless widget, but it shows how to subclass container...
using System;
using System.Collections.Generic;
using Gtk;
using Gdk;
namespace Samples
{
class PolarFixed : Container
{
IList<PolarFixedChild> children;
public PolarFixed()
{
children = new List<PolarFixedChild>();
HasWindow = false;
}
// The child properties object
public class PolarFixedChild : Container.ContainerChild
{
double theta;
uint r;
public PolarFixedChild(PolarFixed parent, Widget child, double theta, uint r) : base(parent, child)
{
this.theta = theta;
this.r = r;
}
// We call parent.QueueResize() from the property setters here so that you
// can move the widget around just by changing its child properties (just
// like with a native container class).
public double Theta {
get { return theta; }
set {
theta = value;
parent.QueueResize();
}
}
public uint R {
get { return r; }
set {
r = value;
parent.QueueResize();
}
}
}
// Override the child properties accessor to return the right object from
// "children".
public override ContainerChild this[Widget w] {
get {
foreach (PolarFixedChild pfc in children) {
if (pfc.Child == w)
return pfc;
}
return null;
}
}
// Indicate the kind of children the container will accept. Most containers
// will accept any kind of child, so they should return Gtk.Widget.GType.
// The default is "GLib.GType.None", which technically means that no (new)
// children can be added to the container, though Container.Add does not
// enforce this.
protected override GLib.GType OnChildType()
{
return Gtk.Widget.GType;
}
// Implement gtk_container_forall(), which is also used by
// Gtk.Container.Children and Gtk.Container.AllChildren.
protected override void ForAll(bool include_internals, Callback callback)
{
base.ForAll(include_internals, callback);
foreach (PolarFixedChild pfc in children)
callback(pfc.Child);
}
// Invoked by Container.Add (w). It's good practice to have this do *something*,
// even if it's not something terribly useful.
protected override void OnAdded(Widget w)
{
Put(w, 0.0, 0);
}
// our own adder method
public void Put(Widget w, double theta, uint r)
{
children.Add(new PolarFixedChild(this, w, theta, r));
w.Parent = this;
QueueResize();
}
public void Move(Widget w, double theta, uint r)
{
PolarFixedChild pfc = (PolarFixedChild) this[w];
if (pfc != null) {
pfc.Theta = theta;
pfc.R = r;
}
}
// invoked by Container.Remove (w)
protected override void OnRemoved(Widget w)
{
PolarFixedChild pfc = (PolarFixedChild) this[w];
if (pfc != null) {
pfc.Child.Unparent();
children.Remove(pfc);
QueueResize();
}
}
// Handle size request
protected override void OnGetPreferredHeight(out int minimal_height, out int natural_height)
{
Requisition req = new Requisition();
OnSizeRequested(ref req);
minimal_height = natural_height = req.Height;
}
protected override void OnGetPreferredWidth(out int minimal_width, out int natural_width)
{
Requisition req = new Requisition();
OnSizeRequested(ref req);
minimal_width = natural_width = req.Width;
}
void OnSizeRequested(ref Requisition req)
{
int child_width, child_minwidth, child_height, child_minheight;
int x, y;
req.Width = req.Height = 0;
foreach (PolarFixedChild pfc in children) {
// Recursively request the size of each child
pfc.Child.GetPreferredWidth(out child_minwidth, out child_width);
pfc.Child.GetPreferredHeight(out child_minheight, out child_height);
// Figure out where we're going to put it
x = (int) (Math.Cos(pfc.Theta) * pfc.R) + child_width / 2;
y = (int) (Math.Sin(pfc.Theta) * pfc.R) + child_height / 2;
// Update our own size request to fit it
if (req.Width < 2 * x)
req.Width = 2 * x;
if (req.Height < 2 * y)
req.Height = 2 * y;
}
// Take Container.BorderWidth into account
req.Width += (int) (2 * BorderWidth);
req.Height += (int) (2 * BorderWidth);
}
// Size allocation. Note that the allocation received may be smaller than what we
// requested. Some containers will take that into account by giving some or all
// of their children a smaller allocation than they requested. Other containers
// (like this one) just let their children get placed partly out-of-bounds if they
// aren't allocated enough room.
protected override void OnSizeAllocated(Rectangle allocation)
{
Requisition childReq, childMinReq;
int cx, cy, x, y;
// This sets the "Allocation" property. For widgets that
// have a GdkWindow, it also calls GdkWindow.MoveResize()
base.OnSizeAllocated(allocation);
// Figure out where the center of the grid will be
cx = allocation.X + (allocation.Width / 2);
cy = allocation.Y + (allocation.Height / 2);
foreach (PolarFixedChild pfc in children) {
pfc.Child.GetPreferredSize(out childMinReq, out childReq);
x = (int) (Math.Cos(pfc.Theta) * pfc.R) - childReq.Width / 2;
y = (int) (Math.Sin(pfc.Theta) * pfc.R) + childReq.Height / 2;
allocation.X = cx + x;
allocation.Width = childReq.Width;
allocation.Y = cy - y;
allocation.Height = childReq.Height;
pfc.Child.SizeAllocate(allocation);
}
}
}
}