本文整理汇总了C#中SFML.Graphics.Text.GetGlobalBounds方法的典型用法代码示例。如果您正苦于以下问题:C# Text.GetGlobalBounds方法的具体用法?C# Text.GetGlobalBounds怎么用?C# Text.GetGlobalBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SFML.Graphics.Text
的用法示例。
在下文中一共展示了Text.GetGlobalBounds方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TextButton
public TextButton(WindowManager _WM,string StartString, int _X, int _Y, int _SizeX, int _SizeY, EventHandler callback)
: base(_WM, _X,_Y,_SizeX,_SizeY)
{
ButtonText = new Text(StartString, WM.font,15);
ButtonPressed += callback;
localx = _X;
localy = _Y;
BackPlate = new RectangleShape();
//BackPlate.Size = new Vector2f(ButtonText
BackPlate.FillColor = Color.Magenta;
SetSize((int)ButtonText.GetGlobalBounds().Width, (int)ButtonText.GetGlobalBounds().Height*2);
LeftSide = new Sprite(new Texture("UI.png", new IntRect(8, 32, 8, 24)));
Center = new Sprite(new Texture("UI.png", new IntRect(17, 32, 1, 24)));
Center.Scale = new Vector2f(sizeX-8-8, 1);
RightSide = new Sprite(new Texture("UI.png", new IntRect(96, 32, 8, 24)));
}
示例2: TimeCounter
public TimeCounter()
: base(4)
{
Elapsed = TimeSpan.Zero;
Text = new Text();
Text.DisplayedString = "00:00:00";
Text.Font = Game.Assets.Fonts["Blocky"];
Text.CharacterSize = 20;
Text.Color = Color.White;
Text.Position = new Vector2f((float)Game.Bounds.Center.X, 15);
Text.Origin = new Vector2f(Text.GetGlobalBounds().Width * 0.5f, 0);
}
示例3: ButtonElement
public ButtonElement(Screen _screen, Vector2f _position, string starttext, EventHandler callback)
: base(_position,"DefaultButton",true)
{
Parent = _screen;
text = new Text(starttext,Parent.ScreenManager.DefaultFont);
text.Position = _position;
this.Position = new Vector2f(text.GetGlobalBounds().Left, text.GetGlobalBounds().Top);
Parent = _screen;
Size = new Vector2f(text.GetGlobalBounds().Width,text.GetGlobalBounds().Height);
debugshape = new RectangleShape(Size);//(new Vector2f(BoundingBox.Width,BoundingBox.Height));
debugshape.Position = new Vector2f(text.GetGlobalBounds().Left, text.GetGlobalBounds().Top);
Random rnd = new Random();
debugshape.FillColor = new Color(0,0,0,255);
debugshape.OutlineColor = Color.Green;
debugshape.OutlineThickness = -1.0f;
buttonPressed += callback;
}
示例4: DrawScore
private void DrawScore()
{
Text score = new Text (_score.ToString (), _font);
Text wave = new Text ("Wave " + _wave.ToString(), _font);
score.Color = Color.White;
wave.Color = Color.White;
score.CharacterSize = 40;
wave.CharacterSize = 25;
score.Position = new Vector2f (_window.Size.X - score.GetGlobalBounds ().Width - 10, 0);
wave.Position = new Vector2f (10, 0);
_window.Draw (score);
_window.Draw (wave);
}
示例5: DrawEquationSolver
private void DrawEquationSolver()
{
// load font
String eqText = _eqToSolve.GetEquation.val1 + " " + Equation.GetString(_eqToSolve.GetEquation.type) + " " + _eqToSolve.GetEquation.val2 + "\n= " + _eqCurrentInput;
Text eq = new Text (eqText, _font);
// align backgroud with text
RectangleShape background = new RectangleShape (new Vector2f (eq.GetGlobalBounds().Width + 90, eq.GetGlobalBounds().Height + 45));
background.FillColor = Color.Red;
Vector2f pos = new Vector2f (_window.Size.X/2 - (background.Size.X/2), _window.Size.Y/2 - (background.Size.Y/2));
background.Position = pos;
eq.Position = new Vector2f (pos.X + 40, pos.Y + 20);
_window.Draw (background);
_window.Draw (eq);
}
示例6: Start
public void Start()
{
System.Drawing.Rectangle r = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
RenderWindow window = new RenderWindow(new VideoMode(1024, 786), "One Bullet", Styles.Titlebar | Styles.Close, settings);
window.LostFocus += (s, e) => { focus = false; };
window.GainedFocus += (s, e) => { focus = true; };
Width = (int)window.Size.X;
Height = (int)window.Size.Y;
window.Closed += window_Closed;
window.KeyPressed += window_KeyPressed;
window.KeyReleased += window_KeyReleased;
Finish();
player.OnShoot += Shoot;
window.SetFramerateLimit(60);
Font font = new Font("Content/consolas.ttf");
Text healthText = new Text("", font, 72);
healthText.Color = Color.Red;
Text dialog = new Text("", font, 48);
dialog.Color = new Color(128, 128, 128);
Texture bulletUI = new Texture("Content/bulletUI.png");
RectangleShape bulletRect = new RectangleShape();
bulletRect.Size = new Vector2f(72, 108);
bulletRect.Origin = new Vector2f(72, 108);
bulletRect.Texture = bulletUI;
light = new RenderTexture(window.Size.X, window.Size.Y);
lightCircle = new CircleShape(0, 20);
RectangleShape lightDisplay = new RectangleShape();
lightDisplay.Size = new Vector2f(window.Size.X, window.Size.Y);
lightDisplay.Position = new Vector2f();
blur = new Shader("Content/blur.vs", "Content/blur.fs");
blur.SetParameter("rad", 0.004f);
RenderStates blurStates = new RenderStates(RenderStates.Default);
blurStates.Shader = blur;
RectangleShape imageFrame = new RectangleShape();
imageFrame.Position = new Vector2f(Width / 2 - 400, 16);
imageFrame.Size = new Vector2f(800, 600);
Texture white = new Texture(1, 1);
Texture blood = new Texture("Content/bloodOverlay.png");
Text startBtn = new Text("START GAME", font, 100);
startBtn.Position = new Vector2f(Width / 2 - startBtn.GetGlobalBounds().Width / 2, Height / 5);
bloodSystem = new ParticleSystem(new Texture("Content/bloodParticle.png"));
Texture aimImage = new Texture("Content/finalScene.png");
Text copyright = new Text("Game by WebFreak001. Made for Ludum Dare 28", font, 48);
copyright.Position = new Vector2f(Width / 2 - copyright.GetLocalBounds().Width / 2, 32);
bool mouseOld = false;
#region Achivements
if (!File.Exists("ach.txt"))
{
File.WriteAllText("ach.txt", "0:0\n1:0\n2:0");
}
achivements = new Dictionary<int, Achivement>();
string[] achs = File.ReadAllLines("ach.txt");
bool done1 = false;
bool done2 = false;
bool done3 = false;
if (achs.Length > 2)
{
if (achs[0].StartsWith("0"))
{
char c = achs[0].Last();
if (c == '1') done1 = true;
}
if (achs[1].StartsWith("1"))
{
char c = achs[1].Last();
if (c == '1') done2 = true;
}
if (achs[2].StartsWith("1"))
{
char c = achs[2].Last();
if (c == '1') done3 = true;
}
}
achivements.Add(0, new Achivement() { Done = done1, Text = "Start the game" });
achivements.Add(1, new Achivement() { Done = done2, Text = "You Missed" });
achivements.Add(2, new Achivement() { Done = done3, Text = "Finish the Game" });
//.........这里部分代码省略.........
示例7: DisplayTitle
/// <summary>
/// Funkcja wyświetla ekran tytułowy
/// </summary>
private static void DisplayTitle() {
Text grad = new Text("Praca inżynierska", font, 60) {
Color = Color.White,
Style = Text.Styles.Bold
};
grad.Origin = new Vector2f(grad.GetGlobalBounds().Width / 2, grad.GetGlobalBounds().Height / 2);
grad.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 335);
Text author = new Text("Autor:", font, 20) {
Color = Color.White
};
author.Origin = new Vector2f(author.GetGlobalBounds().Width / 2, author.GetGlobalBounds().Height / 2);
author.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 275);
Text who = new Text("Mateusz Winiarski", font, 20) {
Color = Color.White,
Style = Text.Styles.Italic | Text.Styles.Bold
};
who.Origin = new Vector2f(who.GetGlobalBounds().Width / 2, who.GetGlobalBounds().Height / 2);
who.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 250);
Text AGH1 = new Text("Akademia Górniczo-Hutnicza", font, 25) {
Color = Color.White
};
AGH1.Origin = new Vector2f(AGH1.GetGlobalBounds().Width / 2, AGH1.GetGlobalBounds().Height / 2);
AGH1.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 200);
Text AGH2 = new Text("im. Stanisława Staszica w Krakowie", font, 25) {
Color = Color.White
};
AGH2.Origin = new Vector2f(AGH2.GetGlobalBounds().Width / 2, AGH2.GetGlobalBounds().Height / 2);
AGH2.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 175);
Text WFiIS = new Text("Wydział Fizyki i Informatyki Stosowanej", font, 25) {
Color = Color.White
};
WFiIS.Origin = new Vector2f(WFiIS.GetGlobalBounds().Width / 2, WFiIS.GetGlobalBounds().Height / 2);
WFiIS.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 125);
Text IS = new Text("Informatyka Stosowana", font, 25) {
Color = Color.White
};
IS.Origin = new Vector2f(IS.GetGlobalBounds().Width / 2, IS.GetGlobalBounds().Height / 2);
IS.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 100);
Text topic1 = new Text("Sztuczna inteligencja w grach komputerowych", font, 35) {
Color = Color.White
};
topic1.Origin = new Vector2f(topic1.GetGlobalBounds().Width / 2, topic1.GetGlobalBounds().Height / 2);
topic1.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 45);
Text topic2 = new Text("na przykładzie logiki rozmytej, algorytmu stada", font, 35) {
Color = Color.White
};
topic2.Origin = new Vector2f(topic2.GetGlobalBounds().Width / 2, topic2.GetGlobalBounds().Height / 2);
topic2.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 - 10);
Text topic3 = new Text("i problemu najkrótszej ścieżki w grze 2D.", font, 35) {
Color = Color.White
};
topic3.Origin = new Vector2f(topic3.GetGlobalBounds().Width / 2, topic3.GetGlobalBounds().Height / 2);
topic3.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 + 25);
Text prom = new Text("Promotor:", font, 20) {
Color = Color.White
};
prom.Origin = new Vector2f(prom.GetGlobalBounds().Width / 2, prom.GetGlobalBounds().Height / 2);
prom.Position = new Vector2f(window.Size.X / 2 - 250, window.Size.Y / 2 + 120);
Text promName = new Text("dr inż. Janusz Malinowski", font, 20) {
Color = Color.White,
Style = Text.Styles.Italic
};
promName.Origin = new Vector2f(promName.GetGlobalBounds().Width / 2, promName.GetGlobalBounds().Height / 2);
promName.Position = new Vector2f(window.Size.X / 2 - 250, window.Size.Y / 2 + 145);
Text rec = new Text("Recenzent:", font, 20) {
Color = Color.White
};
rec.Origin = new Vector2f(rec.GetGlobalBounds().Width / 2, rec.GetGlobalBounds().Height / 2);
rec.Position = new Vector2f(window.Size.X / 2 + 250, window.Size.Y / 2 + 120);
Text recName = new Text("Unknown", font, 20) {
Color = Color.White,
Style = Text.Styles.Italic
};
recName.Origin = new Vector2f(recName.GetGlobalBounds().Width / 2, recName.GetGlobalBounds().Height / 2);
recName.Position = new Vector2f(window.Size.X / 2 + 250, window.Size.Y / 2 + 145);
Text wait = new Text("Proszę czekać. Trwa generowanie mapy.", font, 30) {
Color = Color.Red,
Style = Text.Styles.Bold
};
wait.Origin = new Vector2f(wait.GetGlobalBounds().Width / 2, wait.GetGlobalBounds().Height / 2);
wait.Position = new Vector2f(window.Size.X / 2, window.Size.Y / 2 + 220);
Text time = new Text("Może to mi troszkę zająć. Cierpliwości :)", font, 20) {
//.........这里部分代码省略.........
示例8: Render
public override void Render(RenderTarget target)
{
//Setting view to camera position
View view = target.GetView();
view.Center = new Vector2f((int) CameraPosition.X, (int) CameraPosition.Y);
target.SetView(view);
var screenBounds = new FloatRect
{
Left = view.Center.X - (view.Size.X / 2),
Top = view.Center.Y - (view.Size.Y / 2),
Width = view.Size.X,
Height = view.Size.Y
};
//Drawing map/tiles
map.Render(target, screenBounds, Fog);
RenderRallypoints(target);
//Draw selected unit circles
const float selectCircleRadius = 20;
var selectedCircle = new CircleShape(selectCircleRadius);
selectedCircle.OutlineColor = new Color(100, 255, 100, 200);
selectedCircle.OutlineThickness = 5;
selectedCircle.FillColor = new Color(0, 0, 0, 0);
selectedCircle.Origin = new Vector2f(selectCircleRadius, selectCircleRadius);
if (selectedUnits != null)
{
foreach (EntityBase entityBase in selectedUnits)
{
selectedCircle.Position = entityBase.Position;
target.Draw(selectedCircle);
}
}
var debugHPText = new Text();
debugHPText.Scale = new Vector2f(.6f, .6f);
debugHPText.Color = new Color(255, 255, 255, 100);
var readOnly = new Dictionary<ushort, EntityBase>(entities);
foreach (EntityBase entityBase in readOnly.Values)
{
if (entityBase.GetBounds().Intersects(screenBounds))
{
if (Fog != null)
{
var coords = map.ConvertCoords(entityBase.Position);
entityBase.Render(target, Fog.Grid[(int) coords.X, (int) coords.Y].CurrentState);
if (Fog.Grid[(int)coords.X, (int)coords.Y].CurrentState == FOWTile.TileStates.CurrentlyViewed)
{
entityBase.HasBeenViewed = true;
}
debugHPText.Color = new Color(255, 255, 255, 200);
debugHPText.DisplayedString = "HP: " + entityBase.Health.ToString();
debugHPText.Origin = new Vector2f(debugHPText.GetGlobalBounds().Width/2,
debugHPText.GetGlobalBounds().Height);
debugHPText.Position = entityBase.Position;
target.Draw(debugHPText);
if (entityBase is BuildingBase)
{
var buildingCast = (BuildingBase) entityBase;
if (buildingCast.IsProductingUnit)
{
debugHPText.Color = new Color(255, 255, 0, 100);
debugHPText.DisplayedString = buildingCast.UnitBuildCompletePercent.ToString();
debugHPText.Position += new Vector2f(0, 50);
target.Draw(debugHPText);
}
}
}
}
}
var readOnlyEffect = new List<EffectBase>(Effects);
foreach (EffectBase effectBase in readOnlyEffect)
{
effectBase.Render(target);
}
if (releaseSelect)
{
var rect = new FloatRect(controlBoxP1.X, controlBoxP1.Y, controlBoxP2.X - controlBoxP1.X,
controlBoxP2.Y - controlBoxP1.Y);
var rectangle = new RectangleShape(new Vector2f(rect.Width, rect.Height));
rectangle.Position = new Vector2f(rect.Left, rect.Top);
rectangle.FillColor = new Color(100, 200, 100, 100);
target.Draw(rectangle);
}
//Draw Alerts
const int ALERTXOFFSET = 10;
const int ALERTYMULTIPLE = 60;
const int ALERTYOFFSET = 20;
for (int i = 0; i < alerts.Count; i++)
{
HUDAlert alert = alerts[i];
//.........这里部分代码省略.........
示例9: Render
public override void Render(RenderTarget target)
{
var renderName = new Text(PlayerName);
renderName.Position = target.ConvertCoords(new Vector2i(10, 10));
renderName.Scale = new Vector2f(.6f, .6f);
target.Draw(renderName);
var gameName = new Text("MY LITTLE GLUE FACTORY");
gameName.Scale = new Vector2f(1, 1);
gameName.Origin = new Vector2f(gameName.GetGlobalBounds().Width/2, gameName.GetGlobalBounds().Height/2);
gameName.Position = target.ConvertCoords(new Vector2i((int) target.Size.X/2, 10));
target.Draw(gameName);
for(var i = 0; i < options.Count; i++)
{
if(selectedOption == i)
{
target.Draw(options[i][1]);
}
else
{
target.Draw(options[i][0]);
}
}
}
示例10: Draw
//.........这里部分代码省略.........
scissorRight = scissorLeft;
else if (scissorBottom < scissorTop)
scissorTop = scissorBottom;
// Create a text widget to draw the items
Text text = new Text("", m_TextFont, m_TextSize);
// Check if there is a scrollbar and whether it isn't hidden
if ((m_Scroll != null) && (m_Scroll.LowValue < m_Scroll.Maximum))
{
// Store the transformation
Transform storedTransform = states.Transform;
// Find out which items should be drawn
uint firstItem = (uint)(m_Scroll.Value / m_ItemHeight);
uint lastItem = (uint)((m_Scroll.Value + m_Scroll.LowValue) / m_ItemHeight);
// Show another item when the scrollbar is standing between two items
if ((m_Scroll.Value + m_Scroll.LowValue) % m_ItemHeight != 0)
++lastItem;
// Set the clipping area
Gl.glScissor(scissorLeft, (int)(target.Size.Y - scissorBottom), scissorRight - scissorLeft, scissorBottom - scissorTop);
for (uint i = firstItem; i < lastItem; ++i)
{
// Restore the transformations
states.Transform = storedTransform;
// Set the next item
text.DisplayedString = m_Items[(int)i];
// Get the global bounds
FloatRect bounds = text.GetGlobalBounds();
// Check if we are drawing the selected item
if (m_SelectedItem == (int)(i))
{
// Draw a background for the selected item
{
// Set a new transformation
states.Transform.Translate(0, ((float)(i * m_ItemHeight) - m_Scroll.Value));
// Create and draw the background
RectangleShape back = new RectangleShape(new Vector2f((float)m_Size.X, (float)m_ItemHeight));
back.FillColor = m_SelectedBackgroundColor;
target.Draw(back, states);
// Restore the transformation
states.Transform = storedTransform;
}
// Change the text color
text.Color = m_SelectedTextColor;
}
else // Set the normal text color
text.Color = m_TextColor;
// Set the translation for the text
states.Transform.Translate(2, (float)System.Math.Floor((float)(i * m_ItemHeight) - m_Scroll.Value + ((m_ItemHeight - bounds.Height) / 2.0f) - bounds.Top));
// Draw the text
target.Draw(text, states);
}
}
else // There is no scrollbar or it is invisible
示例11: Draw
public override void Draw(RenderTarget rt)
{
if (!Visible)
return;
RectangleShape button = new RectangleShape(new Vector2f(Width, Height))
{
Position = Position,
FillColor = Color.Black
};
rt.Draw(button);
// Hover
if (mouseIn)
{
RectangleShape buttonHover = new RectangleShape(new Vector2f(Width - 8, Height - 8))
{
Position = Position + new Vector2f(4.0f, 4.0f),
FillColor = Color.Black,
OutlineColor = Color.White,
OutlineThickness = 2.0f
};
rt.Draw(buttonHover);
}
Text text = new Text(value, Assets.LoadFont(Program.DefaultFont))
{
Position = Position + Size / 2.0f,
CharacterSize = 24,
Style = Text.Styles.Bold
};
FloatRect bounds = text.GetGlobalBounds();
text.Position -= new Vector2f(bounds.Width / 2.0f, bounds.Height / 2.0f + 4.0f);
text.Round();
rt.Draw(text);
base.Draw(rt);
}
示例12: GetWidth
//from the internets:
internal static int GetWidth(Text Text){
//Make sure its not empty, because this would crash it later otherwise.
if( Text.ToString().Length == 0 )
return 0;
//Temp variables that use the same font and size as the original text.
//This is to get the width of one '#'
Text Temp1 = new Text( "#", Text.Font, Text.CharacterSize );
Text Temp2 = new Text( "# #", Text.Font, Text.CharacterSize );
//Now we can get the width of the whitespace by subtracting the width of 2 '#' from "# #".
int Width = (int)(Temp2.GetGlobalBounds().Width - Temp1.GetGlobalBounds().Width*2);
//The width of the string without taking into consideration for spaces left at the beggining or end.
int TotalWidth = (int)Text.GetGlobalBounds().Width;
//Get the text from the sf::Text as an std::string.
string str = Text.ToString();
//Bool to see if we encounter a string consisting of only spaces.
bool OnlySpaces = false;
//Go through all characters in the string from the start.
for( int i = 0; i < str.Length; i++ )
{
if( str[i] == ' ' )
//Add each space's width to the sum of it all.
TotalWidth += Width;
else
break;
//Check if we have gone through the whole string.
if( i == str.Length -1 )
OnlySpaces = true;
}
//Go through all characters in the string from the end, as long as it wasn't only spaces.
if( !OnlySpaces )
{
for (int i = str.Length - 1; i > 0; i--)
{
if (str[i] == ' ')
//Add each space's width to the sum of it all.
TotalWidth += Width;
else
break;
}
}
return TotalWidth;
}
示例13: Draw
public override void Draw(RenderTarget rt)
{
RectangleShape barArea = new RectangleShape(Size)
{
Position = Position,
FillColor = Color.Black
};
rt.Draw(barArea);
Text labelText = new Text(label, Assets.LoadFont(Program.DefaultFont))
{
Position = Position + new Vector2f(16.0f, -24.0f),
CharacterSize = 18,
Color = Color.Black
};
labelText.Round();
rt.Draw(labelText);
Text messageText = new Text(Value, Assets.LoadFont(Program.DefaultFont))
{
Position = Position + new Vector2f(8.0f, 8.0f),
CharacterSize = 28,
Color = Color.White
};
messageText.Round();
rt.Draw(messageText);
if (Selected && cursorVisible)
{
RectangleShape cursor = new RectangleShape(new Vector2f(2.0f, Size.Y - 16.0f))
{
Position = Position + new Vector2f(messageText.GetGlobalBounds().Width + 8.0f + 4.0f, 8.0f),
FillColor = Color.White
};
cursor.Round();
rt.Draw(cursor);
}
base.Draw(rt);
}
示例14: Draw
public override void Draw(RenderTarget rt)
{
RectangleShape numberbox = new RectangleShape(Size)
{
Position = Position,
FillColor = Color.Black,
};
rt.Draw(numberbox);
if (mouseIn)
{
RectangleShape checkboxHover = new RectangleShape(new Vector2f(64.0f - 8.0f, 48.0f - 8.0f))
{
Position = Position + new Vector2f(4f, 4f),
FillColor = Color.Black,
OutlineColor = Color.White,
OutlineThickness = 2f
};
rt.Draw(checkboxHover);
}
Text valueText = new Text(stringValue, Assets.LoadFont(Program.DefaultFont))
{
Position = Position + new Vector2f(8.0f, 8.0f),
CharacterSize = 28,
Color = Color.White
};
valueText.Round();
rt.Draw(valueText);
if (Selected && cursorVisible)
{
RectangleShape cursor = new RectangleShape(new Vector2f(2.0f, Size.Y - 16.0f))
{
Position = Position + new Vector2f(valueText.GetGlobalBounds().Width + 8.0f + 4.0f, 8.0f),
FillColor = Color.White
};
cursor.Round();
rt.Draw(cursor);
}
Text labelText = new Text(label, Assets.LoadFont(Program.DefaultFont))
{
Position = Position + new Vector2f(64.0f + 16.0f, 24.0f + 2.0f),
CharacterSize = 32,
Color = Color.Black
};
labelText.Center(false);
labelText.Round();
rt.Draw(labelText);
}