class Alexandria::UI::BarcodeAnimation
Attributes
canvas[R]
Public Class Methods
new()
click to toggle source
# File lib/alexandria/ui/barcode_animation.rb, line 55 def initialize @canvas = GooCanvas::Canvas.new @canvas.set_size_request(300, 70) @canvas.set_bounds(0, 0, 350, 70) @root = @canvas.root_item @barcode_bars = [] @barcode_data = [] @hpos = 0 @scale = 3 @bar_left_edge = 0 @bar_top = 8 @bar_height = 50 create_ean_barcode_data draw_barcode_bars @timeout = nil @index = 0 @fade_opacity = 255 set_active @canvas.show end
Public Instance Methods
destroy()
click to toggle source
# File lib/alexandria/ui/barcode_animation.rb, line 88 def destroy @canvas.destroy @canvas = nil end
manual_input()
click to toggle source
# File lib/alexandria/ui/barcode_animation.rb, line 106 def manual_input # TODO: distinguish between scanner and manual input # @canvas.set_property(:background_color, "#FFF8C0") end
scanner_input()
click to toggle source
# File lib/alexandria/ui/barcode_animation.rb, line 111 def scanner_input # TODO: distinguish between scanner and manual input # @canvas.set_property(:background_color, "white") end
set_active()
click to toggle source
# File lib/alexandria/ui/barcode_animation.rb, line 93 def set_active @canvas.set_property(:background_color, "white") @barcode_bars.each { |rect| rect.set_property(:fill_color, "white") } end
set_passive()
click to toggle source
# File lib/alexandria/ui/barcode_animation.rb, line 98 def set_passive @canvas or return passive_bg = "#F4F4F4" @canvas.set_property(:background_color, passive_bg) @barcode_bars.each { |rect| rect.set_property(:fill_color, passive_bg) } end
start()
click to toggle source
# File lib/alexandria/ui/barcode_animation.rb, line 81 def start @timeout = GLib::Timeout.add(20) do scan_animation (@index >= 0) end end
Private Instance Methods
create_ean_barcode_data()
click to toggle source
# File lib/alexandria/ui/barcode_animation.rb, line 118 def create_ean_barcode_data d = "211113123121112331122131113211111123122211132321112311231111" # ####911113... but that's too much padding on the left... until d.empty? space_width = d[0].chr.to_i bar_width = d[1].chr.to_i d = d[2..] @barcode_data << [space_width, bar_width] end end
draw_barcode_bars()
click to toggle source
# File lib/alexandria/ui/barcode_animation.rb, line 129 def draw_barcode_bars @barcode_data.each do |space_width, bar_width| @hpos += space_width rect_item = GooCanvas::CanvasRect.new(parent: @root, x: @bar_left_edge + @scale * @hpos, y: @bar_top, width: @scale * bar_width, height: @bar_height, line_width: 0, fill_color: "white") @hpos += bar_width @barcode_bars << rect_item end end
fade_animation()
click to toggle source
# File lib/alexandria/ui/barcode_animation.rb, line 166 def fade_animation @fade_opacity = 255 if @fade_opacity == -1 if @fade_opacity >= 0 grey = 0x00000000 + @fade_opacity @barcode_bars.each { |rect| rect.set_property(:fill_color_rgba, grey) } @fade_opacity -= 5 else @fade_opacity = -1 end end
scan_animation()
click to toggle source
# File lib/alexandria/ui/barcode_animation.rb, line 143 def scan_animation if @index < @barcode_bars.size @index = 0 if @index < 0 alpha = 7 * (@index + 1) @barcode_bars.each_with_index do |rect, i| rect.set_property(:fill_color_rgba, 0xFF000000 + alpha) break if i >= @index end @index += 1 else @index = -1 GLib::Timeout.add(5) do @barcode_bars.each { |rect| rect.set_property(:fill_color_rgba, 0x000000C0) } GLib::Timeout.add(15) do fade_animation (@fade_opacity != -1) end false end end end