Advertisement
julioCCs

GTA iV - Graphics event example

Jul 7th, 2013
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. //my first C# example :P
  2.  
  3. //http://gtaxscripting.blogspot.com/
  4. //http://www.facebook.com/GtaIVScripting
  5. //https://www.youtube.com/user/GTAScripting
  6.  
  7. // insert a small png file called anPNG.png into Scripts folder to see the sprite draw method working
  8.  
  9. using System;
  10. using GTA;
  11. using System.IO;
  12. using System.Drawing;
  13.  
  14. namespace GraphicsExample
  15. {
  16.  
  17.     public class GraphicsExample : Script
  18.     {
  19.         private Boolean bDrawTexture = false;
  20.  
  21.         private Texture myTexture; //an texture can be a png, bmp or jpg file
  22.        
  23.         public GraphicsExample()
  24.         {
  25.             try
  26.             {
  27.                 //try to load the texture from the file
  28.                 myTexture = new GTA.Texture(File.ReadAllBytes(".\\scripts\\anPNG.png"));
  29.                 //if load is ok set the control variable to true, with this we avoid issues in the draw event
  30.                 bDrawTexture = true;
  31.             }
  32.             catch { }
  33.  
  34.             this.PerFrameDrawing += new GraphicsEventHandler(this.GraphicsEvent);
  35.         }
  36.  
  37.         private void drawTextWithEffect(GraphicsEventArgs e, string s, Int16 x, Int16 y)
  38.         {
  39.             //draw an rectangle to be the background, the calc to define the X and Wdith its not close to be correct :(, just a example
  40.             e.Graphics.DrawRectangle((Int16)(x + s.Length * 5.7), y + 12, (Int16)s.Length * 12, 25, Color.FromArgb(100, 0, 100, 255));
  41.             //draw the text over the rectangle
  42.             e.Graphics.DrawText(s, x, y, Color.White);
  43.         }
  44.  
  45.         private void GraphicsEvent(object sender, GraphicsEventArgs e)
  46.         {
  47.             //line
  48.             e.Graphics.DrawLine(10, 10, 100, 10, 3, Color.White);
  49.             //rectangle
  50.             e.Graphics.DrawRectangle(50, 40, 100, 40, Color.DarkBlue);
  51.             //text
  52.             e.Graphics.DrawText("simple text", 10, 60, Color.White);
  53.  
  54.             //sprite
  55.             if (bDrawTexture) {
  56.                 e.Graphics.DrawSprite(myTexture, 100, 300, 100,100,0);
  57.             }
  58.  
  59.             //text with effect using auxiliar method
  60.             drawTextWithEffect(e, "This was an example", 300, 30);
  61.             drawTextWithEffect(e, "1", 300, 70);
  62.             drawTextWithEffect(e, "This was an example 2 48746541654 456465 asfsa iuyiy", 300, 110);
  63.         }
  64.  
  65.  
  66.     }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement