Module: GamesParadise::GUI::Gtk::Mastermind::CircleModule

Includes:
Gtk::BaseModule
Included in:
Circle
Defined in:
lib/games_paradise/mastermind/shared_code/circle_module.rb

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
TITLE =
#

TITLE

#
'Mastermind Circle Module'
WIDTH =
#

WIDTH

#
1200
HEIGHT =
#

HEIGHT

#
1000

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(i = ARGV) ⇒ Object

#

GamesParadise::GUI::Gtk::Mastermind::CircleModule.run

#


238
239
240
241
242
243
244
245
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 238

def self.run(i = ARGV)
  require 'gtk_paradise/run'
  _ = ::GamesParadise::GUI::Gtk::Mastermind::CircleRange.new(i)
  r = ::Gtk.run
  r << _
  r.set_size_request(_.width?, _.height?)
  r.top_left_then_run
end

Instance Method Details

#attach_image(this_colour = 'rand') ⇒ Object Also known as: change_image

#

attach_image

Also removes the image before we continue.

#


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 177

def attach_image(
    this_colour = 'rand'
  )
  remove_image
  this_colour = ARRAY_COLOURS.sample if this_colour == 'rand'
  @colour = this_colour
  case this_colour
  when 'red'      then _ = ::GamesParadise::GUI::Gtk::Mastermind::CIRCLE_RED
  when 'blue'     then _ = ::GamesParadise::GUI::Gtk::Mastermind::CIRCLE_BLUE
  when 'green'    then _ = ::GamesParadise::GUI::Gtk::Mastermind::CIRCLE_GREEN
  when 'yellow'   then _ = ::GamesParadise::GUI::Gtk::Mastermind::CIRCLE_YELLOW
  when 'orange'   then _ = ::GamesParadise::GUI::Gtk::Mastermind::CIRCLE_ORANGE
  when 'violet'   then _ = ::GamesParadise::GUI::Gtk::Mastermind::CIRCLE_VIOLET
  when 'blank','' then _ = ::GamesParadise::GUI::Gtk::Mastermind::CIRCLE_BLANK
  else           
    puts 'BUG... this_colour seems to not exist:'
    puts this_colour
  end
  @pic = gtk_image(DIRECTORY_TO_THE_IMAGES+_)
  set_image(@pic) if @pic
end

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


127
128
129
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 127

def border_size?
  2
end

#colour?Boolean Also known as: colour

#

colour?

#

Returns:

  • (Boolean)


231
232
233
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 231

def colour?
  @colour
end

#initialize(colour = '', parent_widget = nil, sensitive_mode = false) ⇒ Object

#

initialize

#


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 54

def initialize(
    colour         = '',
    parent_widget  = nil,
    sensitive_mode = false
  )
  super()
  reset
  set_parent_widget(parent_widget)
  @colour = colour
  set_sensitive(sensitive_mode)
  attach_image(@colour)
  set_size_request(26,26)

  on_button_press_event { |widget, event|
    if ::Gtk.use_gtk2?
      use_this_event = Gdk::Event::BUTTON_PRESS
    else
      use_this_event = :button_press
    end
    if event.event_type == use_this_event
      if event.button    == 1 # linke maustaste
        change_image(next?(@colour))
      elsif event.button == 3 # rechte maustaste
        change_image(previous?(@colour))
      end
    end
  }
  no_relief
end

#next?(colour) ⇒ Boolean

#

next?

#

Returns:

  • (Boolean)


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 151

def next?(colour)
  case colour
  when 'blank','rand','',nil
    @colour = ARRAY_COLOURS[0]
  when 'violet'
    @colour = 'blank'
  when 'red'
    @colour = ARRAY_COLOURS[1]
  when 'blue'
    @colour = ARRAY_COLOURS[2]
  when 'green'
    @colour = ARRAY_COLOURS[3]
  when 'yellow'
    @colour = ARRAY_COLOURS[4]
  when 'orange'
    @colour = ARRAY_COLOURS[5]
  else
    e ::Colours.swarn('ERROR: not found colour: '+colour.to_s)
  end
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


120
121
122
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 120

def padding?
  2
end

#previous?(colour) ⇒ Boolean

#

previous?

#

Returns:

  • (Boolean)


134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 134

def previous?(colour)
  case colour
  when 'red'          then @colour = 'blank'
  when 'blue'         then @colour = ARRAY_COLOURS[0]
  when 'green'        then @colour = ARRAY_COLOURS[1]
  when 'yellow'       then @colour = ARRAY_COLOURS[2]
  when 'orange'       then @colour = ARRAY_COLOURS[3]
  when 'violet'       then @colour = ARRAY_COLOURS[4]
  when 'blank','rand' then @colour = ARRAY_COLOURS[5]
  else
    e swarn('ERROR!!!')
  end
end

#remove_imageObject

#

remove_image

#


219
220
221
222
223
224
225
226
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 219

def remove_image
  unless @flag_image_blank == true
    set_image(
      gtk_image(DIRECTORY_TO_THE_IMAGES+CIRCLE_BLANK)
    )
    @flag_image_blank = true
  end 
end

#resetObject

#

reset

#


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 87

def reset
  reset_the_internal_variables
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  # ======================================================================= #
  # === @title
  # ======================================================================= #
  @title  = TITLE
  # ======================================================================= #
  # === @width
  # ======================================================================= #
  set_width(WIDTH)
  # ======================================================================= #
  # === @height
  # ======================================================================= #
  set_height(HEIGHT)
  @flag_image_blank = false # flag is false at beginning
  set_use_this_font(:dejavu_condensed_25)
  use_project_css_file
end

#set_blankObject

#

set_blank

Blanks out our image again.

#


212
213
214
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 212

def set_blank
  attach_image('blank')
end

#set_parent_widget(i) ⇒ Object

#

set_parent_widget

#


113
114
115
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 113

def set_parent_widget(i)
  @parent_widget = i
end

#use_this_colour=(i) ⇒ Object

#

use_this_colour?

#


202
203
204
205
# File 'lib/games_paradise/mastermind/shared_code/circle_module.rb', line 202

def use_this_colour=(i)
  @colour = i
  attach_image(@colour)
end