Advertisement
Guill

Class Text 1.2

Jun 26th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module GI_Colors
  2.     COLORS = {
  3.     #------------------------------
  4.     # Insira novas cores aqui
  5.     #------------------------------
  6.     # "nome da cor" => Color.new(Valor RGB),
  7.     #
  8.     # Não esqueça da virgula.
  9.     #------------------------------
  10.         "clWhite" => Color.new(255,255,255),
  11.     "clBlack" => Color.new(0,0,0)              
  12.    
  13.     #...
  14.     #------------------------------
  15.     }  
  16.  
  17. end
  18.  
  19. #=========================================================
  20. # Classe Text
  21. #---------------------------------------------------------
  22. # Mostra um texto definido em tempo de execução
  23. #---------------------------------------------------------
  24. # * Adicione um comando de evento Chamar Script com os
  25. # parâmetros a seguir:
  26. #
  27. # text = <seu texto aqui>
  28. # $systxt = Text.new(x,y,w,h,text)
  29. #
  30. # * Substitua X,Y,W e H por suas respectivas cordenadas de
  31. # tela.
  32. #
  33. #=========================================================
  34. class Text < Sprite
  35.     attr_accessor :font_color
  36.         attr_accessor :font_name
  37.     attr_accessor :text
  38.        
  39.         #====================================
  40.         # Initialize
  41.         #------------------------------------
  42.         # * Inicializa a sprite
  43.         # * Cria uma bitmap
  44.         # * Seta o texto e a posição na bitmap
  45.         #====================================
  46.         def initialize(x,y,w,h,text)
  47.                 super(nil)
  48.         @text = text
  49.                 self.bitmap = Bitmap.new(w,h)
  50.                 self.bitmap.draw_text(0,0,w,h,text)
  51.                 self.x = x
  52.                 self.y = y    
  53.         @font_name = self.bitmap.font.name
  54.         @font_color = 'clWhite'
  55.         end
  56.                
  57.     #====================================
  58.         # Update
  59.         #------------------------------------
  60.         # * Atualiza a Sprite
  61.         #====================================
  62.         def update
  63.         self.text = @text
  64.         self.font_color = @font_color
  65.         self.font_name = @font_name
  66.                 super  
  67.         end
  68.        
  69.         #====================================
  70.         # Dispose
  71.         #------------------------------------
  72.         # * Dispõe a sprite
  73.         #====================================
  74.         def dispose
  75.                 super
  76.         end
  77.        
  78.         #====================================
  79.         # Change Text
  80.         #------------------------------------
  81.         # * Muda o texto da bitmap
  82.         # * Muda a posição da bitmap
  83.         #====================================
  84.         def change_text(x,y,w,h,text)
  85.                 self.bitmap.clear
  86.                 self.bitmap = Bitmap.new(w,h)
  87.         @text = text
  88.                 self.bitmap.draw_text(0,0,w,h,text)
  89.                 self.x = x
  90.                 self.y = y            
  91.         end
  92.        
  93.         #====================================
  94.         # Change Font
  95.         #------------------------------------
  96.         # * Muda a fonte do texto da bitmap
  97.         #====================================
  98.         def change_font(name,color)
  99.                 self.bitmap.font.name = name
  100.         self.bitmap.font.color = GI_Colors::COLORS[color]
  101.                 @font_name = name
  102.         @font_color = GI_Colors::COLORS.index(self.bitmap.font.color)
  103.         end
  104.        
  105. end
  106. #=========================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement