Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

tgui canvas test 1.2

a guest Nov 7th, 2017 55 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. using SFML.System;
  2. using SFML.Window;
  3. using SFML.Graphics;
  4. using TGUI;
  5.  
  6. namespace TGUITest {
  7.     class Program {
  8.         static void Main (string[] args) {
  9.             // basic window junk
  10.             RenderWindow window = new RenderWindow(new VideoMode(100, 60), "TGUI.Net Canvas Test");
  11.  
  12.             window.Closed += (s, e) => window.Close();
  13.  
  14.             Gui gui = new Gui(window);
  15.  
  16.  
  17.             // create test content to be rendered to texture
  18.             RectangleShape rect = new RectangleShape(new Vector2f(200, 200));
  19.  
  20.             TestRenderable testRenderable = new TestRenderable();
  21.            
  22.             Drawable[] drawableEntities = { rect, testRenderable };
  23.  
  24.  
  25.             // standard rendertexture setup
  26.             RenderTexture intermediate = new RenderTexture(200, 200);
  27.  
  28.             Sprite intermediateContext = new Sprite(intermediate.Texture) {
  29.                 Scale = new Vector2f(0.1f, 0.1f)
  30.             };
  31.  
  32.  
  33.             // create tgui drawing area
  34.             Canvas intermediate2_tgui = new Canvas(20, 20) {
  35.                 Position = new Vector2f(20, 20)
  36.             };
  37.  
  38.             gui.Add(intermediate2_tgui);
  39.  
  40.  
  41.             // create sfml drawing area for comparison
  42.             RenderTexture intermediate2_sfml = new RenderTexture(20, 20);
  43.  
  44.             Sprite intermediate2_ctx = new Sprite(intermediate2_sfml.Texture) {
  45.                 Position = new Vector2f(80, 20)
  46.             };
  47.            
  48.  
  49.             while (window.IsOpen) {
  50.                 // basic window junk
  51.                 window.DispatchEvents();
  52.  
  53.                 window.Clear();
  54.                
  55.  
  56.                 // draw to the internal sfml rt
  57.                 intermediate.Clear();
  58.  
  59.                 foreach (Drawable ent in drawableEntities) {
  60.                     intermediate.Draw(ent);
  61.                 }
  62.  
  63.                 intermediate.Display();
  64.  
  65.  
  66.                 // draw to the tgui widget
  67.                 intermediate2_tgui.Clear();
  68.  
  69.                 intermediate2_tgui.Draw(intermediateContext);
  70.  
  71.                 intermediate2_tgui.Display();
  72.  
  73.  
  74.                 // draw to the comparison rendertexture
  75.                 intermediate2_sfml.Clear();
  76.  
  77.                 intermediate2_sfml.Draw(intermediateContext);
  78.  
  79.                 intermediate2_sfml.Display();
  80.  
  81.  
  82.                 // output comparison
  83.                 window.Draw(intermediate2_ctx);
  84.  
  85.                 gui.Draw();
  86.  
  87.                 window.Display();
  88.             }
  89.         }
  90.     }
  91.  
  92.    
  93.  
  94.     class TestRenderable : Transformable, Drawable {
  95.         private Vertex[] _Vertices;
  96.  
  97.         public TestRenderable () {
  98.             _Vertices = new Vertex[] {
  99.                 new Vertex(new Vector2f(0, 0), Color.White),
  100.                 new Vertex(new Vector2f(100, 0), Color.Magenta),
  101.                 new Vertex(new Vector2f(100, 100), Color.Cyan),
  102.                 new Vertex(new Vector2f(0, 100), Color.Yellow)
  103.             };
  104.         }
  105.  
  106.         public void Draw (RenderTarget target, RenderStates states) {
  107.             states.Transform *= Transform;
  108.             target.Draw(_Vertices, PrimitiveType.Quads, states);
  109.         }
  110.     }
  111. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top