Advertisement
Guest User

manicdigger_hiba

a guest
Jun 25th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. //ezt hivja meg a DrawButton(), abban nincs hiba, ha torlom azt a sor amiben meghivja, nem jon elo a hiba
  2. internal void DrawText(string text, FontCi font, float x, float y, TextAlign align, TextBaseline baseline)
  3.     {
  4.         TextTexture t = GetTextTexture(text, font);
  5.         int dx = 0;
  6.         int dy = 0;
  7.         if (align == TextAlign.Center)
  8.         {
  9.             dx -= t.textwidth / 2;
  10.         }
  11.         if (align == TextAlign.Right)
  12.         {
  13.             dx -= t.textwidth;
  14.         }
  15.         if (baseline == TextBaseline.Middle)
  16.         {
  17.             dy -= t.textheight / 2;
  18.         }
  19.         if (baseline == TextBaseline.Bottom)
  20.         {
  21.             dy -= t.textheight;
  22.         }
  23.         Draw2dQuad(t.texture, x + dx, y + dy, t.texturewidth, t.textureheight); //ha ezt a sort torlom ki, akkor sincs a hiba
  24.     }
  25.  
  26. // ... ami e sor alatt van, azt mar nem igazan ertem
  27. TextTexture GetTextTexture(string text, FontCi font)
  28.     {
  29.         for (int i = 0; i < textTexturesCount; i++)
  30.         {
  31.             TextTexture t = textTextures[i];
  32.             if (t == null)
  33.             {
  34.                 continue;
  35.             }
  36.             if (t.text == text
  37.                 && t.font.size == font.size
  38.                 && t.font.family == font.family
  39.                 && t.font.style == font.style)
  40.             {
  41.                 return t;
  42.             }
  43.         }
  44.         TextTexture textTexture = new TextTexture();
  45.  
  46.         Text_ text_ = new Text_();
  47.         text_.text = text;
  48.         text_.font = font;
  49.         text_.color = Game.ColorFromArgb(255, 255, 255, 255);
  50.         BitmapCi textBitmap = textColorRenderer.CreateTextTexture(text_);
  51.  
  52.         int texture = p.LoadTextureFromBitmap(textBitmap);
  53.        
  54.         IntRef textWidth = new IntRef();
  55.         IntRef textHeight = new IntRef();
  56.         p.TextSize(text, font, textWidth, textHeight);
  57.  
  58.         textTexture.texture = texture;
  59.         textTexture.texturewidth = p.FloatToInt(p.BitmapGetWidth(textBitmap));
  60.         textTexture.textureheight = p.FloatToInt(p.BitmapGetHeight(textBitmap));
  61.         textTexture.text = text;
  62.         textTexture.font = font;
  63.         textTexture.textwidth = textWidth.value;
  64.         textTexture.textheight = textHeight.value;
  65.  
  66.         p.BitmapDelete(textBitmap);
  67.        
  68.         textTextures[textTexturesCount++] = textTexture;
  69.         return textTexture;
  70.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement