Last active
March 21, 2022 08:47
-
-
Save cwensley/2e25c8496bedc99bff3e to your computer and use it in GitHub Desktop.
Custom drawable template for Eto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Eto.Forms; | |
using Eto.Drawing; | |
namespace CustomDrawable | |
{ | |
public class MyDrawable : Drawable | |
{ | |
bool mouseDragging; | |
public MyDrawable() | |
{ | |
Size = new Size(100, 20); // set preferred size of ruler | |
} | |
protected override void OnPaint(PaintEventArgs e) | |
{ | |
base.OnPaint(e); | |
// do your painting of the ruler using e.Graphics | |
} | |
protected override void OnMouseDown(MouseEventArgs e) | |
{ | |
base.OnMouseDown(e); | |
if (e.Buttons == MouseButtons.Primary) | |
{ | |
// check the position of the mouse (e.Location) to detect if it is over a margin indicator | |
mouseDragging = true; | |
} | |
} | |
protected override void OnMouseMove(MouseEventArgs e) | |
{ | |
base.OnMouseMove(e); | |
if (mouseDragging) | |
{ | |
// move the margin | |
} | |
} | |
protected override void OnMouseUp(MouseEventArgs e) | |
{ | |
base.OnMouseUp(e); | |
if (e.Buttons == MouseButtons.Primary && mouseDragging) | |
{ | |
// finished dragging operation | |
mouseDragging = false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment