Class: GGLib::DebugConsole

Inherits:
Widget show all
Defined in:
lib/ext/widgets.rb

Instance Attribute Summary

Attributes inherited from Widget

#buttonId, #defimage, #id, #name, #sleeping, #theme, #window, #zfocus

Attributes inherited from Containable

#align, #container, #maxSize, #minSize, #offset, #padding, #valign

Attributes inherited from Tile

#id, #inclusive, #x1, #x2, #y1, #y2

Instance Method Summary collapse

Methods inherited from Widget

#blur, #button, #clicked?, #del, #downevent, #event, #focus, #hasFocus?, #hasStickyFocus?, #intDraw, #onClick, #onDelete, #onDrag, #onInitialize, #onKeyDown, #onMouseDown, #onMouseOut, #onMouseOver, #onRightClick, #onRightDrag, #onRightMouseDown, #over?, #sleeping?, #stickFocus, #unstickFocus

Methods inherited from Tile

#centerOn, #del, deleteAllInstances, deleteById, #each, #eachBorder, getAllInstances, getById, #height, #iTile, intersect?, #intersect?, #isInTile?, #move, #resize, setAllInstances, #setCoordinates, #setTile, #width, #xTile

Constructor Details

#initialize(name = :unnamed, theme = Themes::blank) ⇒ DebugConsole

Returns a new instance of DebugConsole.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ext/widgets.rb', line 4

def initialize(name=:unnamed, theme=Themes::blank)
  super(name, 0, 0, 640, 480, theme)
  @vline=0
  @oldtext=[]
  @textm=false
  clear
  stickFocus
  begin
    @theme.font.default = Gosu::Font.new($window, "Courier New", @theme.font.default.height)
  rescue
  end
end

Instance Method Details

#acceptStickyFocus?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ext/widgets.rb', line 19

def acceptStickyFocus?
  return true
end

#acceptText?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/ext/widgets.rb', line 16

def acceptText?
  return true
end

#clearObject



98
99
100
101
102
103
104
105
# File 'lib/ext/widgets.rb', line 98

def clear
  @text=[]
  @text[0]="-~*CONSOLE*~-"
  @text[1]="<Press ` (backquote) or enter '/exit' to exit>"
  @text[2]=">> "
  @line=2    
  @vline=@oldtext.size-1
end

#drawObject



165
166
167
168
169
170
171
# File 'lib/ext/widgets.rb', line 165

def draw
  i=0
  @text.each {|line|
    @theme.font.default.draw(line, 10, 10+i*@theme.font.default.height, ZOrder::Text, 1.0, 1.0, 0xffffffff)
    i+=1
  }
end

#feedText(char) ⇒ Object



66
67
68
# File 'lib/ext/widgets.rb', line 66

def feedText(char)
  @text[@line]+=char.to_s unless (char=="`" || char=="\n" || char=="\r")
end

#justify(ln) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/ext/widgets.rb', line 69

def justify(ln)
  fin=""
  size=ln.size
  while ln.size>70
    fin+=ln.slice(0,70)+"\fNL"
    ln=ln.slice(70,ln.size)
  end
  fin+=ln.to_s
  return fin
end

#onKeyUp(key) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ext/widgets.rb', line 22

def onKeyUp(key)
  if key==Gosu::Button::KbDelete or key==Gosu::Button::KbBackspace
    thisline=@text[@line]
    if @textm and thisline.length>0
      @text[@line]=thisline.slice(0,thisline.length-1)
    elsif thisline.length>3
      @text[@line]=thisline.slice(0,thisline.length-1)
    end
  elsif key==Gosu::Button::KbEscape or $window.button_id_to_char(key) == '`'
    sleep
  elsif key==Gosu::Button::KbReturn or key==Gosu::Button::KbEnter
    if @textm
      if @text[@line]=="/endtext"
        @textm=false
        @line+=1
        @text[@line]=">> "
      else
        @line+=1
        @text[@line]=""
      end
      return
    end
    @oldtext.push @text[@line]
    cmd=@text[@line].slice(3,@text[@line].length-3)
    if cmd.slice(cmd.size-3,3)=="/nl"
      @text[@line]=@text[@line].slice(0,@text[@line].length-3)
      @text[@line+1]="|> "
      @line+=1
    else
      runcmd(cmd)
    end
    @vline=@oldtext.size
  elsif key==Gosu::Button::KbUp
    if @vline-1 >= 0 and 
      @vline-=1
      @text[@line]=@oldtext[@vline]
    end
  elsif key==Gosu::Button::KbDown
    if @vline+1 < @oldtext.size and 
      @vline+=1
      @text[@line]=@oldtext[@vline]
    end
  end
end

#onStickyBlurObject



162
163
164
# File 'lib/ext/widgets.rb', line 162

def onStickyBlur
  $window.setTextInput(nil)
end

#onStickyFocusObject



159
160
161
# File 'lib/ext/widgets.rb', line 159

def onStickyFocus
  $window.setTextInput(@textinput)
end

#respond(text) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ext/widgets.rb', line 79

def respond(text)
  text=text.to_s
  @line+=1
  if text==""
    text="<no output>"
  end
  text=justify(text) if text.index("\fNL")==nil
  text=text.split("\fNL")
  mult=false
  text.each { |ln|
    if ln.slice(0,4)=="\fERR"
      @text[@line]="!> "+ln.strip
    else
      @text[@line]="^> "+ln
    end
    @line+=1
    @text[@line]=">> "
  }
end

#sleepObject



145
146
147
148
149
150
# File 'lib/ext/widgets.rb', line 145

def sleep
  @text=[]
  @line=0
  @vline=0
  super
end

#wakeUpObject



151
152
153
154
155
156
157
158
# File 'lib/ext/widgets.rb', line 151

def wakeUp
  @oldtext=[]
  @vline=0
  @text=false
  clear
  stickFocus
  super
end