Class: Othello::BoardView::Square

Inherits:
Object
  • Object
show all
Defined in:
sample/tcltklib/sample2.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view, row, col) ⇒ Square

Returns a new instance of Square.



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'sample/tcltklib/sample2.rb', line 197

def initialize(view, row, col)
   @view = view
   @id = @view.e("create rectangle",
                 *(view.tk_rect(view.left + col,
                                view.top + row,
                                view.left + col + 1,
                                view.top + row + 1) \
                   << "-fill #{BACK_GROUND_COLOR}") )
   @row = row
   @col = col
   @view.e("itemconfigure", @id,
     "-width 0.5m -outline #{BORDER_COLOR}")
   @view.e("bind", @id, "<Any-Enter>", TclTkCallback.new($ip, proc{
      if @oval == nil
         view.e("itemconfigure", @id, "-fill #{HILIT_BG_COLOR}")
      end
   }))
   @view.e("bind", @id, "<Any-Leave>", TclTkCallback.new($ip, proc{
      view.e("itemconfigure", @id, "-fill #{BACK_GROUND_COLOR}")
   }))
   @view.e("bind", @id, "<ButtonRelease-1>", TclTkCallback.new($ip,
      proc{
      view.click_square(self)
   }))
end

Instance Attribute Details

#colObject (readonly)

Returns the value of attribute col



195
196
197
# File 'sample/tcltklib/sample2.rb', line 195

def col
  @col
end

#ovalObject (readonly)

Returns the value of attribute oval



193
194
195
# File 'sample/tcltklib/sample2.rb', line 193

def oval
  @oval
end

#rowObject (readonly)

Returns the value of attribute row



194
195
196
# File 'sample/tcltklib/sample2.rb', line 194

def row
  @row
end

Instance Method Details



223
224
225
226
227
228
# File 'sample/tcltklib/sample2.rb', line 223

def blink(color)
   @view.e("itemconfigure", @id, "-fill #{color}")
   $update.e()
   sleep(0.1)
   @view.e("itemconfigure", @id, "-fill #{BACK_GROUND_COLOR}")
end