Skip to content

Commit a8cb09f

Browse files
committed
added goto and search panels and format switch for all input panels
1 parent 3dcd1ad commit a8cb09f

8 files changed

Lines changed: 261 additions & 122 deletions

File tree

Binmap/Controls/BinList.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ public Point ItemSpace
4141
}
4242
}
4343

44-
public int NumItems
45-
{
46-
get
47-
{
48-
return items.Count;
49-
}
50-
}
51-
5244
#region IScrollbarTarget and IInput implementations
5345
Rectangle IScrollbarTarget.ScrollRectangle { get { return Transform; } }
5446
public int ScrollStepSize { get { return 100; } }
@@ -373,6 +365,11 @@ public override void Resize(int w, int h)
373365
if (!layoutLocked) Layout();
374366
}
375367

368+
public void ScrollTo(int targetPosition)
369+
{
370+
scrollbar.ScrollTo(targetPosition);
371+
}
372+
376373
public void OnScroll(int scrollPosition)
377374
{
378375
startIndex = scrollPosition;

Binmap/Controls/BinListItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public override void Draw(SpriteBatch spriteBatch)
107107
commentInput.Transform.X = parentRect.Width - CommentColumnWidth - Transform.X + 2;
108108
commentInput.Transform.Y = 0;
109109
commentInput.Visible = true;
110+
commentInput.Font = Main.DefaultFont;
110111
}
111112
else commentInput.Visible = false;
112113

Binmap/Controls/Button.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
using Microsoft.Xna.Framework;
33
using System;
44
using Microsoft.Xna.Framework.Graphics;
5+
using Microsoft.Xna.Framework.Input;
56

67
namespace Binmap.Controls
78
{
8-
class Button : Control
9+
class Button : Control, IInput
910
{
1011
public object Tag = null;
1112
private Action<Button> clickCallback;
@@ -18,6 +19,9 @@ class Button : Control
1819

1920
public SpriteFont Font = Main.FontL;
2021

22+
public bool Focused { set { } }
23+
public Action<IInput> OnChangeCallback { set { } }
24+
2125
public Button(int w, int h, string text, Color textColor, Action<Button> callback = null, object tag = null) : base(0, 0, w, h, Main.BorderColor)
2226
{
2327
MouseEnabled = true;
@@ -29,6 +33,7 @@ public Button(int w, int h, string text, Color textColor, Action<Button> callbac
2933

3034
protected override void OnMouseDown()
3135
{
36+
Main.SetFocus(this);
3237
clickCallback?.Invoke(this);
3338
}
3439

@@ -46,7 +51,18 @@ public override void Draw(SpriteBatch spriteBatch)
4651
rect.X += (int)Math.Floor((Transform.Width - size.X) / 2) + 1;
4752
rect.Y += (int)Math.Floor((Transform.Height - size.Y) / 2);
4853

54+
if (Font == Main.FontS)
55+
{
56+
rect.X -= 1;
57+
rect.Y += 3;
58+
}
59+
4960
spriteBatch.DrawString(Font, Text, new Vector2(rect.X, rect.Y), TextColor);
5061
}
62+
63+
public bool ProcessKey(Keys key)
64+
{
65+
throw new NotImplementedException();
66+
}
5167
}
5268
}

Binmap/Controls/Scrollbar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private void thumbClicked(Button btn)
8585
public void Layout()
8686
{
8787
int availableHeight = Transform.Height - 2 * buttonA.Transform.Height;
88-
thumb.Resize(Transform.Width - 4, Math.Max(thumb.Transform.Width, Math.Min(availableHeight, availableHeight * target.NumVisible / target.MaxScrollValue)));
88+
thumb.Resize(Transform.Width - 4, Math.Max(thumb.Transform.Width, Math.Min(availableHeight, availableHeight * target.NumVisible / Math.Max(1, target.MaxScrollValue))));
8989
availableHeight -= thumb.Transform.Height;
9090
float s = (float)ScrollPosition / (Math.Max(1, target.MaxScrollValue - target.NumVisible));
9191
thumb.Transform.Y = buttonA.Transform.Height + (int)Math.Round(availableHeight * s);

Binmap/Controls/TextInput.cs

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,18 @@ class TextInput : Container, IInput
1010
{
1111
public string Text = "";
1212
private bool focused = false;
13-
public bool Focused
14-
{
15-
set
16-
{
17-
focused = value;
18-
}
19-
}
20-
13+
public bool Focused { set { focused = value; } }
2114
public Color FocusFrameColor = Main.TrackColor;
15+
public Color TextColor = Color.Yellow;
2216

23-
private Action<IInput> onChangeCallback = null;
24-
public Action<IInput> OnChangeCallback
25-
{
26-
set
27-
{
28-
onChangeCallback = value;
29-
}
30-
}
17+
public SpriteFont Font = Main.DefaultFont;
18+
19+
public Action<IInput> OnChangeCallback { private get; set; }
20+
public Action<IInput> OnSubmitCallback { private get; set; }
3121

3222
private int caretPosition = 0;
3323
private float caretTime = 0;
3424

35-
public Color TextColor = Color.Yellow;
36-
3725
public TextInput(int x, int y, int w, int h) : base(x, y, w, h, Main.BackgroundColor)
3826
{
3927
MouseEnabled = true;
@@ -47,6 +35,8 @@ protected override void OnMouseDown()
4735

4836
public override void Update(float time, float dTime)
4937
{
38+
if (!Visible) return;
39+
5040
base.Update(time, dTime);
5141
caretTime += dTime;
5242
}
@@ -65,8 +55,8 @@ public override void Draw(SpriteBatch spriteBatch)
6555
// text
6656
int x = worldRect.X + 2;
6757
int y = worldRect.Y - 1;
68-
if (Main.DefaultFont == Main.FontS) y += 4;
69-
spriteBatch.DrawString(Main.DefaultFont, Text, new Vector2(x, y), TextColor);
58+
if (Font == Main.FontS) y += 4;
59+
spriteBatch.DrawString(Font, Text, new Vector2(x, y), TextColor);
7060

7161
// caret
7262
if (caretPosition > Text.Length) caretPosition = Text.Length;
@@ -76,7 +66,7 @@ public override void Draw(SpriteBatch spriteBatch)
7666

7767
Vector2 textSize = Main.DefaultFont.MeasureString(left);
7868
x += (int)Math.Round(textSize.X);
79-
if (Main.DefaultFont == Main.FontL) y += 3;
69+
if (Font == Main.FontL) y += 3;
8070
else y -= 1;
8171

8272
spriteBatch.Draw(Main.WhiteTexture, new Rectangle(x, y, 1, Transform.Height - 4), Color.White);
@@ -130,52 +120,52 @@ public bool ProcessKey(Keys key)
130120
if (!Main.KeyboardState.IsKeyDown(Keys.LeftShift) && !Main.KeyboardState.IsKeyDown(Keys.RightShift)) s = s.ToLower();
131121

132122
Text = left + s + right;
133-
onChangeCallback?.Invoke(this);
123+
OnChangeCallback?.Invoke(this);
134124
caretPosition += 1;
135125
break;
136126

137127
case Keys.Space:
138128
Text = left + " " + right;
139-
onChangeCallback?.Invoke(this);
129+
OnChangeCallback?.Invoke(this);
140130
caretPosition += 1;
141131
break;
142132

143133
case Keys.Add:
144134
case Keys.OemPlus:
145135
Text = left + "+" + right;
146-
onChangeCallback?.Invoke(this);
136+
OnChangeCallback?.Invoke(this);
147137
caretPosition += 1;
148138
break;
149139

150140
case Keys.Subtract:
151141
case Keys.OemMinus:
152142
Text = left + "-" + right;
153-
onChangeCallback?.Invoke(this);
143+
OnChangeCallback?.Invoke(this);
154144
caretPosition += 1;
155145
break;
156146

157147
case Keys.Decimal:
158148
case Keys.OemComma:
159149
Text = left + "," + right;
160-
onChangeCallback?.Invoke(this);
150+
OnChangeCallback?.Invoke(this);
161151
caretPosition += 1;
162152
break;
163153

164154
case Keys.OemPeriod:
165155
Text = left + "." + right;
166-
onChangeCallback?.Invoke(this);
156+
OnChangeCallback?.Invoke(this);
167157
caretPosition += 1;
168158
break;
169159

170160
case Keys.Multiply:
171161
Text = left + "*" + right;
172-
onChangeCallback?.Invoke(this);
162+
OnChangeCallback?.Invoke(this);
173163
caretPosition += 1;
174164
break;
175165

176166
case Keys.Divide:
177167
Text = left + "/" + right;
178-
onChangeCallback?.Invoke(this);
168+
OnChangeCallback?.Invoke(this);
179169
caretPosition += 1;
180170
break;
181171

@@ -220,28 +210,29 @@ public bool ProcessKey(Keys key)
220210
}
221211

222212
Text = left + s + right;
223-
onChangeCallback?.Invoke(this);
213+
OnChangeCallback?.Invoke(this);
224214
caretPosition += 1;
225215
break;
226216

227217
case Keys.Delete:
228218
if (right.Length > 0)
229219
{
230220
Text = left + right.Substring(1);
231-
onChangeCallback?.Invoke(this);
221+
OnChangeCallback?.Invoke(this);
232222
}
233223
break;
234224

235225
case Keys.Back:
236226
if (left.Length > 0)
237227
{
238228
Text = left.Substring(0, left.Length - 1) + right;
239-
onChangeCallback?.Invoke(this);
229+
OnChangeCallback?.Invoke(this);
240230
caretPosition -= 1;
241231
}
242232
break;
243233

244234
case Keys.Enter:
235+
OnSubmitCallback?.Invoke(this);
245236
Main.SetFocus(null);
246237
break;
247238

Binmap/Main.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void SetFocus(IInput control)
4545
if (focusedControl != null) focusedControl.Focused = true;
4646
}
4747

48-
public static string Version = "1.3";
48+
public static string Version = "1.4";
4949

5050
Keys[] prevPressed;
5151
GraphicsDeviceManager graphics;
@@ -138,7 +138,7 @@ private void loadFile(string filename)
138138
else b = " (" + b + ")";
139139
}
140140

141-
Window.Title = "Binmap " + Version + " - " + a + b;
141+
Window.Title = "Binmap " + Version + " - " + a + b + ", " + layouter.NumBytes + " bytes";
142142
}
143143
else Forms.MessageBox.Show(layouter.LastError, "Sorry!", Forms.MessageBoxButtons.OK, Forms.MessageBoxIcon.Error);
144144
}

0 commit comments

Comments
 (0)