Button refactor
This commit is contained in:
parent
4839e48e49
commit
5fe7b87215
1 changed files with 50 additions and 36 deletions
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using Ryujinx.Profiler.UI.SharpFontHelpers;
|
||||
|
@ -10,84 +7,101 @@ namespace Ryujinx.Profiler.UI
|
|||
{
|
||||
public class ProfileButton
|
||||
{
|
||||
private int Padding;
|
||||
private FontService FontService;
|
||||
private int X, Y, Right, Top, Height;
|
||||
private int TextX, TextY;
|
||||
private string Label;
|
||||
private Action Clicked;
|
||||
private bool Visible;
|
||||
// Store font service
|
||||
private FontService _fontService;
|
||||
|
||||
// Layout information
|
||||
private int _left, _right;
|
||||
private int _bottom, _top;
|
||||
private int _height;
|
||||
private int _padding;
|
||||
|
||||
// Label information
|
||||
private int _labelX, _labelY;
|
||||
private string _label;
|
||||
|
||||
// Misc
|
||||
private Action _clicked;
|
||||
private bool _visible;
|
||||
|
||||
|
||||
public ProfileButton(FontService fontService, Action clicked)
|
||||
: this(fontService, clicked, 0, 0, 0, 0, 0)
|
||||
{
|
||||
Visible = false;
|
||||
_visible = false;
|
||||
}
|
||||
|
||||
public ProfileButton(FontService fontService, Action clicked, int x, int y, int padding, int height, int width)
|
||||
: this(fontService, "", clicked, x, y, padding, height, width)
|
||||
{
|
||||
Visible = false;
|
||||
_visible = false;
|
||||
}
|
||||
|
||||
public ProfileButton(FontService fontService, string label, Action clicked, int x, int y, int padding, int height, int width = -1)
|
||||
{
|
||||
FontService = fontService;
|
||||
Clicked = clicked;
|
||||
_fontService = fontService;
|
||||
_clicked = clicked;
|
||||
|
||||
UpdateSize(label, x, y, padding, height, width);
|
||||
}
|
||||
|
||||
public int UpdateSize(string label, int x, int y, int padding, int height, int width = -1)
|
||||
{
|
||||
Visible = true;
|
||||
Label = label;
|
||||
_visible = true;
|
||||
_label = label;
|
||||
|
||||
if (width == -1)
|
||||
{
|
||||
// Dummy draw to measure size
|
||||
width = (int)FontService.DrawText(label, 0, 0, height, false);
|
||||
width = (int)_fontService.DrawText(label, 0, 0, height, false);
|
||||
}
|
||||
|
||||
UpdateSize(x, y, padding, width, height);
|
||||
return Right - X;
|
||||
|
||||
return _right - _left;
|
||||
}
|
||||
|
||||
public void UpdateSize(int x, int y, int padding, int width, int height)
|
||||
{
|
||||
Height = height;
|
||||
X = x;
|
||||
Y = y;
|
||||
TextX = x + padding / 2;
|
||||
TextY = y + padding / 2;
|
||||
Top = y + height + padding;
|
||||
Right = x + width + padding;
|
||||
_height = height;
|
||||
_left = x;
|
||||
_bottom = y;
|
||||
_labelX = x + padding / 2;
|
||||
_labelY = y + padding / 2;
|
||||
_top = y + height + padding;
|
||||
_right = x + width + padding;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if (!Visible)
|
||||
if (!_visible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Draw backing rectangle
|
||||
GL.Begin(PrimitiveType.Triangles);
|
||||
GL.Color3(Color.Black);
|
||||
GL.Vertex2(X, Y);
|
||||
GL.Vertex2(X, Top);
|
||||
GL.Vertex2(Right, Top);
|
||||
GL.Vertex2(_left, _bottom);
|
||||
GL.Vertex2(_left, _top);
|
||||
GL.Vertex2(_right, _top);
|
||||
|
||||
GL.Vertex2(Right, Top);
|
||||
GL.Vertex2(Right, Y);
|
||||
GL.Vertex2(X, Y);
|
||||
GL.Vertex2(_right, _top);
|
||||
GL.Vertex2(_right, _bottom);
|
||||
GL.Vertex2(_left, _bottom);
|
||||
GL.End();
|
||||
|
||||
FontService.DrawText(Label, TextX, TextY, Height);
|
||||
// Use font service to draw label
|
||||
_fontService.DrawText(_label, _labelX, _labelY, _height);
|
||||
}
|
||||
|
||||
public bool ProcessClick(int x, int y)
|
||||
{
|
||||
if (x > X && x < Right &&
|
||||
y > Y && y < Top)
|
||||
// If button contains x, y
|
||||
if (x > _left && x < _right &&
|
||||
y > _bottom && y < _top)
|
||||
{
|
||||
Clicked();
|
||||
_clicked();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue