Permalink
Browse files

added goto and search panels and format switch for all input panels

  • Loading branch information...
movAX13h committed May 16, 2017
1 parent 3dcd1ad commit a8cb09fca8bda8b9a72048766e2ab0f2d987e671
View
@@ -41,14 +41,6 @@ public Point ItemSpace
}
}
public int NumItems
{
get
{
return items.Count;
}
}
#region IScrollbarTarget and IInput implementations
Rectangle IScrollbarTarget.ScrollRectangle { get { return Transform; } }
public int ScrollStepSize { get { return 100; } }
@@ -373,6 +365,11 @@ public override void Resize(int w, int h)
if (!layoutLocked) Layout();
}
public void ScrollTo(int targetPosition)
{
scrollbar.ScrollTo(targetPosition);
}
public void OnScroll(int scrollPosition)
{
startIndex = scrollPosition;
@@ -107,6 +107,7 @@ public override void Draw(SpriteBatch spriteBatch)
commentInput.Transform.X = parentRect.Width - CommentColumnWidth - Transform.X + 2;
commentInput.Transform.Y = 0;
commentInput.Visible = true;
commentInput.Font = Main.DefaultFont;
}
else commentInput.Visible = false;
View
@@ -2,10 +2,11 @@
using Microsoft.Xna.Framework;
using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Binmap.Controls
{
class Button : Control
class Button : Control, IInput
{
public object Tag = null;
private Action<Button> clickCallback;
@@ -18,6 +19,9 @@ class Button : Control
public SpriteFont Font = Main.FontL;
public bool Focused { set { } }
public Action<IInput> OnChangeCallback { set { } }
public Button(int w, int h, string text, Color textColor, Action<Button> callback = null, object tag = null) : base(0, 0, w, h, Main.BorderColor)
{
MouseEnabled = true;
@@ -29,6 +33,7 @@ public Button(int w, int h, string text, Color textColor, Action<Button> callbac
protected override void OnMouseDown()
{
Main.SetFocus(this);
clickCallback?.Invoke(this);
}
@@ -46,7 +51,18 @@ public override void Draw(SpriteBatch spriteBatch)
rect.X += (int)Math.Floor((Transform.Width - size.X) / 2) + 1;
rect.Y += (int)Math.Floor((Transform.Height - size.Y) / 2);
if (Font == Main.FontS)
{
rect.X -= 1;
rect.Y += 3;
}
spriteBatch.DrawString(Font, Text, new Vector2(rect.X, rect.Y), TextColor);
}
public bool ProcessKey(Keys key)
{
throw new NotImplementedException();
}
}
}
@@ -85,7 +85,7 @@ private void thumbClicked(Button btn)
public void Layout()
{
int availableHeight = Transform.Height - 2 * buttonA.Transform.Height;
thumb.Resize(Transform.Width - 4, Math.Max(thumb.Transform.Width, Math.Min(availableHeight, availableHeight * target.NumVisible / target.MaxScrollValue)));
thumb.Resize(Transform.Width - 4, Math.Max(thumb.Transform.Width, Math.Min(availableHeight, availableHeight * target.NumVisible / Math.Max(1, target.MaxScrollValue))));
availableHeight -= thumb.Transform.Height;
float s = (float)ScrollPosition / (Math.Max(1, target.MaxScrollValue - target.NumVisible));
thumb.Transform.Y = buttonA.Transform.Height + (int)Math.Round(availableHeight * s);
@@ -10,30 +10,18 @@ class TextInput : Container, IInput
{
public string Text = "";
private bool focused = false;
public bool Focused
{
set
{
focused = value;
}
}
public bool Focused { set { focused = value; } }
public Color FocusFrameColor = Main.TrackColor;
public Color TextColor = Color.Yellow;
private Action<IInput> onChangeCallback = null;
public Action<IInput> OnChangeCallback
{
set
{
onChangeCallback = value;
}
}
public SpriteFont Font = Main.DefaultFont;
public Action<IInput> OnChangeCallback { private get; set; }
public Action<IInput> OnSubmitCallback { private get; set; }
private int caretPosition = 0;
private float caretTime = 0;
public Color TextColor = Color.Yellow;
public TextInput(int x, int y, int w, int h) : base(x, y, w, h, Main.BackgroundColor)
{
MouseEnabled = true;
@@ -47,6 +35,8 @@ protected override void OnMouseDown()
public override void Update(float time, float dTime)
{
if (!Visible) return;
base.Update(time, dTime);
caretTime += dTime;
}
@@ -65,8 +55,8 @@ public override void Draw(SpriteBatch spriteBatch)
// text
int x = worldRect.X + 2;
int y = worldRect.Y - 1;
if (Main.DefaultFont == Main.FontS) y += 4;
spriteBatch.DrawString(Main.DefaultFont, Text, new Vector2(x, y), TextColor);
if (Font == Main.FontS) y += 4;
spriteBatch.DrawString(Font, Text, new Vector2(x, y), TextColor);
// caret
if (caretPosition > Text.Length) caretPosition = Text.Length;
@@ -76,7 +66,7 @@ public override void Draw(SpriteBatch spriteBatch)
Vector2 textSize = Main.DefaultFont.MeasureString(left);
x += (int)Math.Round(textSize.X);
if (Main.DefaultFont == Main.FontL) y += 3;
if (Font == Main.FontL) y += 3;
else y -= 1;
spriteBatch.Draw(Main.WhiteTexture, new Rectangle(x, y, 1, Transform.Height - 4), Color.White);
@@ -130,52 +120,52 @@ public bool ProcessKey(Keys key)
if (!Main.KeyboardState.IsKeyDown(Keys.LeftShift) && !Main.KeyboardState.IsKeyDown(Keys.RightShift)) s = s.ToLower();
Text = left + s + right;
onChangeCallback?.Invoke(this);
OnChangeCallback?.Invoke(this);
caretPosition += 1;
break;
case Keys.Space:
Text = left + " " + right;
onChangeCallback?.Invoke(this);
OnChangeCallback?.Invoke(this);
caretPosition += 1;
break;
case Keys.Add:
case Keys.OemPlus:
Text = left + "+" + right;
onChangeCallback?.Invoke(this);
OnChangeCallback?.Invoke(this);
caretPosition += 1;
break;
case Keys.Subtract:
case Keys.OemMinus:
Text = left + "-" + right;
onChangeCallback?.Invoke(this);
OnChangeCallback?.Invoke(this);
caretPosition += 1;
break;
case Keys.Decimal:
case Keys.OemComma:
Text = left + "," + right;
onChangeCallback?.Invoke(this);
OnChangeCallback?.Invoke(this);
caretPosition += 1;
break;
case Keys.OemPeriod:
Text = left + "." + right;
onChangeCallback?.Invoke(this);
OnChangeCallback?.Invoke(this);
caretPosition += 1;
break;
case Keys.Multiply:
Text = left + "*" + right;
onChangeCallback?.Invoke(this);
OnChangeCallback?.Invoke(this);
caretPosition += 1;
break;
case Keys.Divide:
Text = left + "/" + right;
onChangeCallback?.Invoke(this);
OnChangeCallback?.Invoke(this);
caretPosition += 1;
break;
@@ -220,28 +210,29 @@ public bool ProcessKey(Keys key)
}
Text = left + s + right;
onChangeCallback?.Invoke(this);
OnChangeCallback?.Invoke(this);
caretPosition += 1;
break;
case Keys.Delete:
if (right.Length > 0)
{
Text = left + right.Substring(1);
onChangeCallback?.Invoke(this);
OnChangeCallback?.Invoke(this);
}
break;
case Keys.Back:
if (left.Length > 0)
{
Text = left.Substring(0, left.Length - 1) + right;
onChangeCallback?.Invoke(this);
OnChangeCallback?.Invoke(this);
caretPosition -= 1;
}
break;
case Keys.Enter:
OnSubmitCallback?.Invoke(this);
Main.SetFocus(null);
break;
View
@@ -45,7 +45,7 @@ public static void SetFocus(IInput control)
if (focusedControl != null) focusedControl.Focused = true;
}
public static string Version = "1.3";
public static string Version = "1.4";
Keys[] prevPressed;
GraphicsDeviceManager graphics;
@@ -138,7 +138,7 @@ private void loadFile(string filename)
else b = " (" + b + ")";
}
Window.Title = "Binmap " + Version + " - " + a + b;
Window.Title = "Binmap " + Version + " - " + a + b + ", " + layouter.NumBytes + " bytes";
}
else Forms.MessageBox.Show(layouter.LastError, "Sorry!", Forms.MessageBoxButtons.OK, Forms.MessageBoxIcon.Error);
}
Oops, something went wrong.

0 comments on commit a8cb09f

Please sign in to comment.