Editor/textfield.rb
# Some constants that define our appearance.
Some constants that define our appearance.
Some constants that define our appearance .
def draw
    if @window.text_input == self then
      background_color = ACTIVE_COLOR
    else
      background_color = INACTIVE_COLOR
    end
    @window.draw_quad(x,    	y, 		background_color,
				x + width, 	y ,          	background_color,
				x,         	y + height, background_color,
				x + width, 	y + height, background_color, 0)
    pos_x = x + @font.text_width(self.text[0...self.caret_pos])
    sel_x = x + @font.text_width(self.text[0...self.selection_start])
    @window.draw_quad(sel_x, 	y,         	 	SELECTION_COLOR,
				pos_x, 	y,          		SELECTION_COLOR,
				sel_x, 	y + height, 	SELECTION_COLOR,
				pos_x, 	y + height, 	SELECTION_COLOR, 0)
    if @window.text_input == self then
      @window.draw_line(pos_x, 	y,          	CARET_COLOR,
				pos_x, 	y + height, CARET_COLOR, 0)
end
	@font.draw(@label, x, y-15, 0)
	@font.draw(self.text, x + 2, y, 0)
  end
def draw if @window . text_input == self then background_color = ACTIVE_COLOR else background_color = INACTIVE_COLOR end @window . draw_quad ( x , y , background_color , x + width , y , background_color , x , y + height , background_color , x + width , y + height , background_color , 0 ) pos_x = x + @font . text_width ( self . text [ 0 ... self . caret_pos ] ) sel_x = x + @font . text_width ( self . text [ 0 ... self . selection_start ] ) @window . draw_quad ( sel_x , y , SELECTION_COLOR , pos_x , y , SELECTION_COLOR , sel_x , y + height , SELECTION_COLOR , pos_x , y + height , SELECTION_COLOR , 0 ) if @window . text_input == self then @window . draw_line ( pos_x , y , CARET_COLOR , pos_x , y + height , CARET_COLOR , 0 ) end @font . draw ( @label , x , y - 15 , 0 ) @font . draw ( self . text , x + 2 , y , 0 ) end
Some constants that define our appearance.
Some constants that define our appearance .
# Depending on whether this is the currently selected input or not, change the # background's color. # Calculate the position of the caret and the selection start. # Draw the selection background, if any; if not, sel_x and pos_x will be # the same value, making this quad empty. # Draw the caret; again, only if this is the currently selected field. # label # Finally, draw the text itself!