-// Copyright (c) 2013-2020 Bruyère Jean-Philippe <jp_bruyere@hotmail.com>
+// Copyright (c) 2013-2021 Bruyère Jean-Philippe <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
}
public Interface (int width = 800, int height = 600, bool startUIThread = true, bool createSurface = true)
{
- loadCursors ();
-
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
- CurrentInterface = this;
+ //CurrentInterface = this;
clientRectangle = new Rectangle (0, 0, width, height);
if (createSurface)
public static float WheelIncrement = 1;
/// <summary>Tabulation size in Text controls</summary>
public static int TAB_SIZE = 4;
- public static string LineBreak = "\n";
+ [Obsolete]public static string LineBreak = "\n";
/// <summary> Allow rendering of interface in development environment </summary>
public static bool DesignerMode = false;
/// <summary> Disable caching for a widget if this threshold is reached </summary>
/// Each control need a ref to the root interface containing it, if not set in GraphicObject.currentInterface,
/// the ref of this one will be stored in GraphicObject.currentInterface
/// </summary>
- protected static Interface CurrentInterface;
+ //protected static Interface CurrentInterface;
#endregion
#region Events
}
blinkingCursor.Restart ();
forceTextCursor = false;
- } else if (textCursor != null && blinkingCursor.ElapsedMilliseconds > blinkFrequency) {
+ } else if (textCursor != null && blinkingCursor.ElapsedMilliseconds > TEXT_CURSOR_BLINK_FREQUENCY) {
RegisterClip (textCursor.Value);
textCursor = null;
blinkingCursor.Restart ();
} else if (FocusedWidget is Label lab && lab.SelectionIsEmpty) {
- if (blinkingCursor.ElapsedMilliseconds > blinkFrequency) {
+ if (blinkingCursor.ElapsedMilliseconds > TEXT_CURSOR_BLINK_FREQUENCY) {
textCursor = lab.DrawCursor (ctx);
surf.Flush ();
blinkingCursor.Restart ();
DbgLogger.EndEvent (DbgEvtType.Drawing, true);
}
#endregion
- const long blinkFrequency = 300;
+
+ #region Blinking text cursor
+ public static long TEXT_CURSOR_BLINK_FREQUENCY = 300;
internal Rectangle? textCursor = null;
internal bool forceTextCursor = true;
Stopwatch blinkingCursor = Stopwatch.StartNew ();
+ #endregion
+
#region GraphicTree handling
/// <summary>Add widget to the Graphic tree of this interface and register it for layouting</summary>
public Widget AddWidget(Widget g)
Cursor createCursor (MouseCursor mc)
{
+ const int minimumSize = 24;
+ if (!XCursor.Cursors.ContainsKey (mc)) {
+ XCursor.Cursors[mc] = XCursorFile.Load (this, $"#Crow.Cursors.{mc}").Cursors.First (cu => cu.Width >= minimumSize);
+ }
XCursor c = XCursor.Cursors [mc];
return new CustomCursor (c.Width, c.Height, c.data, c.Xhot, c.Yhot);
}
cursor = value;
currentCursor?.Dispose ();
- currentCursor = createCursor (cursor);
+ switch (cursor) {
+ case MouseCursor.arrow:
+ case MouseCursor.top_left_arrow:
+ currentCursor = new Cursor (CursorShape.Arrow);
+ break;
+ case MouseCursor.crosshair:
+ currentCursor = new Cursor (CursorShape.Crosshair);
+ break;
+ case MouseCursor.hand:
+ currentCursor = new Cursor (CursorShape.Hand);
+ break;
+ case MouseCursor.ibeam:
+ currentCursor = new Cursor (CursorShape.IBeam);
+ break;
+ default:
+ currentCursor = XCursor.Create (this, cursor);
+ break;
+ }
+
currentCursor.Set (hWin);
//MouseCursorChanged.Raise (this,new MouseCursorChangedEventArgs(cursor));
}
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
+using System.Linq;
namespace Crow
{
{
const uint XC_TYPE_IMG = 0xfffd0002;
- class toc
+ struct toc
{
public uint type;
public uint subtype;
static XCursorFile loadFromStream(Stream s)
{
- List<toc> tocList = new List<toc> ();
+ List<toc> tocList = new List<toc> (5);
XCursorFile tmp = new XCursorFile ();
using (BinaryReader sr = new BinaryReader (s)) {
- byte[] data;
- //magic: CARD32 ’Xcur’ (0x58, 0x63, 0x75, 0x72)
- if (new string (sr.ReadChars (4)) != "Xcur") {
+ //magic: CARD32 ’Xcur’ (0x58, 0x63, 0x75, 0x72)
+ if (!sr.ReadChars (4).AsSpan ().SequenceEqual("Xcur".AsSpan())) {
Debug.WriteLine ("XCursor Load error: Wrong magic");
return null;
}
foreach (toc t in tocList) {
if (t.type != XC_TYPE_IMG)
continue;
-
sr.BaseStream.Seek (t.pos, SeekOrigin.Begin);
tmp.Cursors.Add(imageLoad (sr));
}
// delay: CARD32 Delay between animation frames in milliseconds
tmp.Delay = sr.ReadUInt32 ();
// pixels: LISTofCARD32 Packed ARGB format pixels
- tmp.data = new byte [tmp.Width * tmp.Height * 4];
- for (int i = 0; i < tmp.Width * tmp.Height; i++) {
- //unchecked { tmp.data [i * 4 + 3] = (byte)(2 * (int)sr.ReadByte ()); }
- tmp.data [i * 4 + 0] = sr.ReadByte ();
- tmp.data [i * 4 + 1] = sr.ReadByte ();
- tmp.data [i * 4 + 2] = sr.ReadByte ();
- tmp.data [i * 4 + 3] = sr.ReadByte ();
-
- //System.Diagnostics.Debug.WriteLine ($"{tmp.data [i * 4 + 3],2:X} {tmp.data [i * 4 + 0],2:X} {tmp.data [i * 4 + 1],2:X} {tmp.data [i * 4 + 2],2:X}");
- }
- //tmp.data = sr.ReadBytes((int)(tmp.Width * tmp.Height * 4));
- /*using(Stream fs = new FileStream($"/tmp/test.bin_{tmp.Width}", FileMode.Create))
- using (BinaryWriter sr2 = new BinaryWriter(fs)) {
- sr2.Write (tmp.data, 0, tmp.data.Length);
- }*/
+ tmp.data = sr.ReadBytes ((int)(4 * tmp.Width * tmp.Height));
return tmp;
}
}
public uint Delay;
public byte[] data;
- public XCursor ()
- {
+ public XCursor () { }
+ public static Glfw.CustomCursor Create (Interface iface, MouseCursor mc) {
+ const int minimumSize = 24;
+ if (!Cursors.ContainsKey (mc))
+ XCursor.Cursors[mc] = XCursorFile.Load (iface, $"#Crow.Cursors.{mc}").Cursors.First (cu => cu.Width >= minimumSize);
+ XCursor c = XCursor.Cursors[mc];
+ return new Glfw.CustomCursor (c.Width, c.Height, c.data, c.Xhot, c.Yhot);
}
-// public static implicit operator MouseCursor(XCursor xc)
-// {
-// return new MouseCursor((int)xc.Xhot, (int)xc.Yhot, (int)xc.Width, (int)xc.Height,xc.data);
-// }
+ // public static implicit operator MouseCursor(XCursor xc)
+ // {
+ // return new MouseCursor((int)xc.Xhot, (int)xc.Yhot, (int)xc.Width, (int)xc.Height,xc.data);
+ // }
}
}