Class: GamesAndRpgParadise::GUI::Gtk::ViewCard

Inherits:
Gtk::Box
  • Object
show all
Includes:
Gtk::BaseModule
Defined in:
lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb

Overview

GamesAndRpgParadise::GUI::Gtk::ViewCard

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
TITLE =
#

TITLE

#
'View card'
WIDTH =
#

WIDTH

#
'35% or minimum 400px'
HEIGHT =
#

HEIGHT

#
'25% or minimum 300px'
USE_THIS_FONT =
#

USE_THIS_FONT

#
:dejavu_condensed_20
USE_THIS_AS_BACKGROUND_COLOUR_FOR_THE_WIDGET =
#

USE_THIS_AS_BACKGROUND_COLOUR_FOR_THE_WIDGET

#
:white
DEFAULT_CARD =
#

DEFAULT_CARD

#
::GamesAndRpgParadise::MagicTheGathering.log_directory?+
'aether_revolt/'\
'Aerial_Modification.png'
HASH_DESIGNATED_KEY_COMBINATIONS =
#

HASH_DESIGNATED_KEY_COMBINATIONS

#
{
  'alt+a':  'activate_about_menu',
  'ctrl+a': 'activate_about_menu'
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commandline_arguments = ARGV, run_already = true) ⇒ ViewCard

#

initialize

#


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 75

def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  super(:vertical)
  register_sigint
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  modify_background(
    :normal,
    USE_THIS_AS_BACKGROUND_COLOUR_FOR_THE_WIDGET
  )
  handle_events
  run if run_already
end

Class Method Details

.run(i = ARGV, run_already = true) ⇒ Object

#

GamesAndRpgParadise::GUI::Gtk::ViewCard.run

This method can be used to instantiate a new ViewCard GUI widget. This widget will show a magic card (if available locally).

#


379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 379

def self.run(
    i           = ARGV,
    run_already = true
  )
  require 'gtk_paradise/run'
  # ======================================================================= #
  # Instantiate a new GUI object next.
  # ======================================================================= #
  _ = ::GamesAndRpgParadise::GUI::Gtk::ViewCard.new(i, run_already)
  r = ::Gtk.run { :add_a_new_accel_group }
  r << _
  _.enable_these_key_combinations(HASH_DESIGNATED_KEY_COMBINATIONS)
  r.show_all
  r.background_colour :white
  r.automatic_size_then_automatic_title
  r.add_shortcut(1, 'activate_about_menu', :strg)
  r.top_left_then_run
end

Instance Method Details

#activate_about_menuObject

#

activate_about_menu

#


369
370
371
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 369

def activate_about_menu
e 'YO!'
end

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


172
173
174
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 172

def border_size?
  10
end

#connect_skeletonObject

#

connect_skeleton (connect tag)

#


204
205
206
207
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 204

def connect_skeleton
  abort_on_exception
  add(@event_box) # Add the image here.
end

#create_skeletonObject

#

create_skeleton (create tag)

#


186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 186

def create_skeleton
  try_to_create_the_pixbuf_image
  # ======================================================================= #
  # We can scale our image here. Keep in mind that a magic card has a
  # dimension of:
  #
  #   65mm (width) x 92mm (height)
  #
  # At 150ppi, it's 375 by 525 pixels. This is a ratio of 1 : 1.4.
  # At 300ppi, it's 750 by 1050pixels. This is a ratio of 1 : 1.4.
  # ======================================================================= #
  @main_image = gtk_image(@pixbuf_image)
  create_the_event_box
end

#create_the_event_boxObject

#

create_the_event_box

This method will handle the events.

#


278
279
280
281
282
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 278

def create_the_event_box
  @event_box = gtk_event_box(@main_image)
  @event_box.on_clicked { do_reveal_the_popover }
  @event_box.show_all
end

#do_reveal_the_popoverObject

#

do_reveal_the_popover

This will currently only work on ruby-gtk3.

#


289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 289

def do_reveal_the_popover
  # ===================================================================== #
  # Create the popover next.
  # ===================================================================== #
  @popover = gtk_popover
  vbox = gtk_vbox
  text_of_the_header = text("Path to the image file:\n")
  text_of_the_header.use_this_font = :dejavu_18
  vbox.pack_start(
    text_of_the_header,
    fill: false, expand: true, padding: 10
  )
  _ = text(path?, 5) # This represents the path.
  _.use_this_font = :hack_14
  _.make_selectable
  _.deselect
  vbox.minimal(_)
  vbox.set_border_width(12)
  @popover.add(vbox)
  @popover.set_position(:bottom)
  @popover.set_relative_to(@main_image)
  @popover.show_all
  @popover.popup
end

#handle_eventsObject

#

handle_events

#


267
268
269
270
271
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 267

def handle_events
  on_button_press_event {
    output_the_location_of_the_image
  }
end

#location_to_the_image_file?Boolean Also known as: path?

#

location_to_the_image_file?

#

Returns:

  • (Boolean)


212
213
214
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 212

def location_to_the_image_file?
  @location_to_the_image_file
end

#main_image?Boolean

#

main_image?

#

Returns:

  • (Boolean)


260
261
262
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 260

def main_image?
  @main_image
end

#output_the_location_of_the_image(i = @location_to_the_image_file) ⇒ Object

#

output_the_location_of_the_image

#


219
220
221
222
223
224
225
226
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 219

def output_the_location_of_the_image(
    i = @location_to_the_image_file
  )
  e "#{Colours.rev}The path to the image is:"
  e
  e "  #{Colours.sfile(i)}"
  e
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


165
166
167
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 165

def padding?
  12
end

#register_sigintObject

#

register_sigint

#


179
180
181
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 179

def register_sigint
  Signal.trap('SIGINT') { exit }
end

#resetObject

#

reset (reset tag)

#


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 96

def reset
  reset_the_internal_variables
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
  use_gtk_paradise_project_css_file 
  infer_the_size_automatically
  # ======================================================================= #
  # === @location_to_the_image_file
  # ======================================================================= #
  @location_to_the_image_file = DEFAULT_CARD
  # ======================================================================= #
  # === @pixbuf_image
  # ======================================================================= #
  @pixbuf_image = nil
  # ======================================================================= #
  # === @width_of_a_regular_magic_card
  # ======================================================================= #
  @width_of_a_regular_magic_card = 365
  # ======================================================================= #
  # === @height_of_a_regular_magic_card
  # ======================================================================= #
  @height_of_a_regular_magic_card = 509
  # ======================================================================= #
  # === @scale_up_by_n_percent
  # ======================================================================= #
  @scale_up_by_n_percent = 12
  # ======================================================================= #
  # === @scaling_mode_to_use
  #
  # Next determine which scaling mode should be used.
  #
  # Note that :nearest is the fastest scaling method, but has horrible
  # quality when scaling down.
  #
  # :bilinear is the best choice if you are not sure what to choose. It
  # has a good speed/quality balance.
  #
  # :hyper is the slowest and highest quality reconstruction function.
  # ======================================================================= #
  @scaling_mode_to_use = :bilinear # :nearest # :hyper
  add_more_CSS_rules_then_apply_them '
tooltip {
border: 3px solid darkblue;
padding: 12px;
}
'
end

#runObject

#

run (run tag)

#


317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 317

def run
  create_skeleton_then_connect_skeleton
  # ======================================================================= #
  # 365x509 pixels. # 401x560
  # ======================================================================= #
  @event_box.signal_connect(:event) {|widget, event|
    # ===================================================================== #
    # === original_pixbuf
    # ===================================================================== #
    original_pixbuf = main_image?.pixbuf
    case name_of_this_event?(event)
    # ===================================================================== #
    # === GDK_LEAVE_NOTIFY
    #
    # On mouse-leave we will down-shrink the card to its original size.
    # ===================================================================== #
    when 'GDK_LEAVE_NOTIFY'
      upscaled_image = original_pixbuf.scale(
        @width_of_a_regular_magic_card,
        @height_of_a_regular_magic_card,
        @scaling_mode_to_use
      )
      @main_image.pixbuf = upscaled_image
    # ===================================================================== #
    # === GDK_ENTER_NOTIFY
    #
    # On mouse-enter we will increase the size of the card by n%.
    # ===================================================================== #
    when 'GDK_ENTER_NOTIFY'
      new_width  = (@width_of_a_regular_magic_card  * (100 + percentage_upscaling?.to_f)) / 100.0
      new_height = (@height_of_a_regular_magic_card * (100 + percentage_upscaling?.to_f)) / 100.0
      # =================================================================== #
      # Next two small "safeguards" are used. I did not check for this in
      # the past, and the above formula used to be wrong or may still have
      # issues - thus this small safeguard should help avoid freezing the
      # computer.
      # =================================================================== #
      new_width  = 1400 if new_width > 2000
      new_height = 1000 if new_height > 2000
      upscaled_image = original_pixbuf.scale(
        new_width,
        new_height,
        @scaling_mode_to_use
      )
      @main_image.pixbuf = upscaled_image
    end
  }
end

#scale_up_by_n_percent?Boolean Also known as: percentage_upscaling?

#

scale_up_by_n_percent?

#

Returns:

  • (Boolean)


150
151
152
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 150

def scale_up_by_n_percent?
  @scale_up_by_n_percent
end

#set_path(i = DEFAULT_CARD) ⇒ Object

#

set_path

This method can be used to assign to a new image for the widget that displays the card at hand.

#


250
251
252
253
254
255
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 250

def set_path(
    i = DEFAULT_CARD
  )
  @location_to_the_image_file = i
  @main_image.set_path(@location_to_the_image_file)
end

#set_scale_up_by_n_percent(i) ⇒ Object

#

set_scale_up_by_n_percent

#


157
158
159
160
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 157

def set_scale_up_by_n_percent(i)
  i = i.to_i
  @scale_up_by_n_percent = i
end

#try_to_create_the_pixbuf_image(i = @location_to_the_image_file) ⇒ Object

#

try_to_create_the_pixbuf_image

This method will create the pixbuf image.

#


233
234
235
236
237
238
239
240
241
242
# File 'lib/games_and_rpg_paradise/gui/gtk3/magic_the_gathering/view_card/view_card.rb', line 233

def try_to_create_the_pixbuf_image(
    i = @location_to_the_image_file
  )
  # ======================================================================= #
  # === @pixbuf_image
  # ======================================================================= #
  if File.exist? i
    @pixbuf_image = GdkPixbuf::Pixbuf.new(file: @location_to_the_image_file)#,50, 40)
  end
end