MuInput class
This commit is contained in:
parent
7ae7e46a36
commit
d56f214a44
@ -419,45 +419,6 @@ namespace MicroUI
|
|||||||
public char[] inputText = new char[32];
|
public char[] inputText = new char[32];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MuPool
|
|
||||||
{
|
|
||||||
public static int Get(MuContext ctx, MuPoolItem[] items, uint id)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < items.Length; i++)
|
|
||||||
{
|
|
||||||
if (items[i].Id == id)
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int Init(MuContext ctx, MuPoolItem[] items, uint id)
|
|
||||||
{
|
|
||||||
int n = -1;
|
|
||||||
int f = ctx.Frame;
|
|
||||||
// Find the item with the oldest last_update
|
|
||||||
for (int i = 0; i < items.Length; i++)
|
|
||||||
{
|
|
||||||
if (items[i].LastUpdate < f)
|
|
||||||
{
|
|
||||||
f = items[i].LastUpdate;
|
|
||||||
n = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MuAssert.Expect(n > -1);
|
|
||||||
items[n].Id = id;
|
|
||||||
Update(ctx, items, n);
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Update(MuContext ctx, MuPoolItem[] items, int idx)
|
|
||||||
{
|
|
||||||
items[idx].LastUpdate = ctx.Frame;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class MuAssert
|
public static class MuAssert
|
||||||
{
|
{
|
||||||
public static bool TestMode { get; set; } = false;
|
public static bool TestMode { get; set; } = false;
|
||||||
@ -825,4 +786,93 @@ namespace MicroUI
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class MuPool
|
||||||
|
{
|
||||||
|
public static int Get(MuContext ctx, MuPoolItem[] items, uint id)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < items.Length; i++)
|
||||||
|
{
|
||||||
|
if (items[i].Id == id)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int Init(MuContext ctx, MuPoolItem[] items, uint id)
|
||||||
|
{
|
||||||
|
int n = -1;
|
||||||
|
int f = ctx.Frame;
|
||||||
|
// Find the item with the oldest last_update
|
||||||
|
for (int i = 0; i < items.Length; i++)
|
||||||
|
{
|
||||||
|
if (items[i].LastUpdate < f)
|
||||||
|
{
|
||||||
|
f = items[i].LastUpdate;
|
||||||
|
n = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MuAssert.Expect(n > -1);
|
||||||
|
items[n].Id = id;
|
||||||
|
Update(ctx, items, n);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Update(MuContext ctx, MuPoolItem[] items, int idx)
|
||||||
|
{
|
||||||
|
items[idx].LastUpdate = ctx.Frame;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MuInput
|
||||||
|
{
|
||||||
|
public static void MouseMove(MuContext ctx, int x, int y)
|
||||||
|
{
|
||||||
|
ctx.MousePos = new MuVec2(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MouseDown(MuContext ctx, int x, int y, int btn)
|
||||||
|
{
|
||||||
|
MouseMove(ctx, x, y);
|
||||||
|
ctx.MouseDown |= btn;
|
||||||
|
ctx.MousePressed |= btn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MouseUp(MuContext ctx, int x, int y, int btn)
|
||||||
|
{
|
||||||
|
MouseMove(ctx, x, y);
|
||||||
|
ctx.MouseDown &= ~btn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Scroll(MuContext ctx, int x, int y)
|
||||||
|
{
|
||||||
|
ctx.ScrollDelta = new MuVec2(ctx.ScrollDelta.X + x, ctx.ScrollDelta.Y + y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void KeyDown(MuContext ctx, int key)
|
||||||
|
{
|
||||||
|
ctx.KeyPressed |= key;
|
||||||
|
ctx.KeyDown |= key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void KeyUp(MuContext ctx, int key)
|
||||||
|
{
|
||||||
|
ctx.KeyDown &= ~key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void InputText(MuContext ctx, string text)
|
||||||
|
{
|
||||||
|
int len = ctx.inputText.Length;
|
||||||
|
int size = text.Length;
|
||||||
|
if (len + size > ctx.inputText.Length)
|
||||||
|
throw new Exception("Input text buffer overflow");
|
||||||
|
// Copy text into the buffer (simple version)
|
||||||
|
for (int i = 0; i < size && i < ctx.inputText.Length; i++)
|
||||||
|
{
|
||||||
|
ctx.inputText[i] = text[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user