View difference between Paste ID: dudiRc5E and CUgDwfrs
SHOW: | | - or go back to the newest paste.
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 :bold
38
        attr_accessor :italic
39
	attr_accessor :text
40
		
41
        #====================================
42
        # Initialize
43
        #------------------------------------
44
        # * Inicializa a sprite
45
        # * Cria uma bitmap
46
        # * Seta o texto e a posição na bitmap
47
        #====================================
48
        def initialize(x,y,w,h,text)
49
                super(nil)
50
		@text = text
51
                self.bitmap = Bitmap.new(w,h)
52
                self.bitmap.draw_text(0,0,w,h,text)
53
                self.x = x
54
                self.y = y    
55
		@font_name = self.bitmap.font.name
56
		@font_color = 'clWhite'
57
        end
58
        		
59
	#====================================
60
        # Update
61
        #------------------------------------
62
        # * Atualiza a Sprite
63
        #====================================
64
        def update
65
		self.text = @text
66
		self.font_color = @font_color
67
		self.font_name = @font_name
68
		apply_style
69
                super  
70
        end
71
       
72
        #====================================
73
        # Dispose
74
        #------------------------------------
75
        # * Dispõe a sprite
76
        #====================================
77
        def dispose
78
                super
79
        end
80
       
81
        #====================================
82
        # Apply style
83
        #------------------------------------
84
        # * Muda o estilo do negrito
85
        # * Muda o estilo do itálico
86
        #====================================
87
        def apply_style
88
                self.bitmap.font.bold = self.bold  
89
                self.bitmap.font.italic = self.italic             
90
        end
91
92
        #====================================
93
        # Change Text
94
        #------------------------------------
95
        # * Muda o texto da bitmap
96
        # * Muda a posição da bitmap
97
        #====================================
98
        def change_text(x,y,w,h,text)
99
                self.bitmap.clear
100
                self.bitmap = Bitmap.new(w,h)
101
		@text = text
102
                self.bitmap.draw_text(0,0,w,h,text)
103
                self.x = x
104
                self.y = y             
105
        end
106
		
107
        #====================================
108
        # Change Font
109
        #------------------------------------
110
        # * Muda a fonte do texto da bitmap
111
        #====================================
112
        def change_font(name,color)
113
                self.bitmap.font.name = name
114
		self.bitmap.font.color = GI_Colors::COLORS[color]
115
                @font_name = name
116
		@font_color = GI_Colors::COLORS.index(self.bitmap.font.color)
117
        end
118
       
119
end
120
#=========================================================