CrabUI
Loading...
Searching...
No Matches
CUIMagnifyingGlass.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5
6using Barotrauma;
7using Microsoft.Xna.Framework;
8using Microsoft.Xna.Framework.Input;
9using Microsoft.Xna.Framework.Graphics;
10
11namespace CrabUI
12{
13 /// <summary>
14 /// It's a debug tool, you can use it with cuimg command, it's very fps comsuming
15 /// </summary>
16 [NoDefault]
18 {
19 public static CUIFrame GlassFrame;
20
21 public static void AddToggleButton()
22 {
23 CUI.TopMain["ToggleMagnifyingGlass"] = new CUIButton("MG")
24 {
25 Absolute = new CUINullRect(0, 0, 20, 20),
26 Anchor = CUIAnchor.CenterLeft,
27 AddOnMouseDown = (e) => ToggleEquip(),
28 };
29 }
30
31 public static void ToggleEquip()
32 {
33 if (GlassFrame != null)
34 {
35 GlassFrame.RemoveSelf();
36 GlassFrame = null;
37 }
38 else
39 {
40 GlassFrame = new CUIFrame()
41 {
42 ZIndex = 100000,
43
44 BackgroundColor = Color.Transparent,
45 OutlineColor = Color.Cyan,
46 OutlineThickness = 5,
47 Anchor = CUIAnchor.Center,
48 Absolute = new CUINullRect(w: 200, h: 200),
49 };
50 GlassFrame["glass"] = new CUIMagnifyingGlass();
51 CUI.TopMain["MagnifyingGlass"] = GlassFrame;
52 }
53 }
54
55 public override void CleanUp()
56 {
57 texture.Dispose();
58 base.CleanUp();
59 }
60 Texture2D texture;
61 Color[] backBuffer;
62
63
64 double lastDrawn;
65 public override void Draw(SpriteBatch spriteBatch)
66 {
67 if (Timing.TotalTime - lastDrawn > 0.05)
68 {
69 lastDrawn = Timing.TotalTime;
70
71 GameMain.Instance.GraphicsDevice.GetBackBufferData<Color>(backBuffer);
72 texture.SetData(backBuffer);
73
74 texture.GetData<Color>(
75 0, new Rectangle((int)Real.Left, (int)Real.Top, 40, 40), Data, 0, Data.Length
76 );
77 SetData();
78 }
79
80 base.Draw(spriteBatch);
81 }
82
83 public CUIMagnifyingGlass() : base()
84 {
85 Size = new Point(40, 40);
86 SamplerState = CUI.NoSmoothing;
87 Relative = new CUINullRect(0, 0, 1, 1);
88
89 int w = GameMain.Instance.GraphicsDevice.PresentationParameters.BackBufferWidth;
90 int h = GameMain.Instance.GraphicsDevice.PresentationParameters.BackBufferHeight;
91
92 backBuffer = new Color[w * h];
93
94 texture = new Texture2D(GameMain.Instance.GraphicsDevice, w, h, false, GameMain.Instance.GraphicsDevice.PresentationParameters.BackBufferFormat);
95 }
96 }
97
98}
CUIAnchor is just a Vector2 This is a static class containing some helper methods.
Definition CUIAnchor.cs:18
A button It's derived from CUITextBlock and has all its props.
Definition CUIButton.cs:19
Allows you to manipulate pixel data of its texture.
Definition CUICanvas.cs:17
void SetData()
Call this method to transfer values from Data array into texture.
Definition CUICanvas.cs:66
virtual Point Size
Size of the internal texture Will automatically resize the texture and data array of set.
Definition CUICanvas.cs:28
SamplerState SamplerState
don't
CUINullRect Relative
Relative to parent size and position, [0..1].
Color BackgroundColor
Color of BackgroundSprite, default is black If you're using custom sprite and don't see it make sur...
Vector2 Anchor
this point of this component
CUIRect Real
Calculated prop, position on real screen in pixels Should be fully calculated after CUIMainComponent....
int? ZIndex
Components are drawn in order of their ZIndex Normally it's derived from component position in the ...
Color OutlineColor
Outline is like a border, but on the outside of the component.
CUINullRect Absolute
Absolute size and position in pixels.
Draggable and resizable container for other components.
Definition CUIFrame.cs:16
In fact a static class managing static things.
Definition CUIErrors.cs:16
static CUIMainComponent TopMain
Orchestrates Drawing and updates, there could be only one CUI.TopMain is located above vanilla GUI.
Definition CUI.cs:89
It's a debug tool, you can use it with cuimg command, it's very fps comsuming.
override void Draw(SpriteBatch spriteBatch)
Here component should be drawn.
Rectangle with float?
Definition CUIRect.cs:104