class BBS::Petscii::CanvasMenu
A BBS::Selector drawn on a BBS::Petscii::Canvas: the cursor menu of a graphics screen of a C64 board, in the uppercase/graphics set. The keys and the items are the Selectorâs (CRSR, RETURN, an itemâs key, RUN/STOP or â for back, numbers, columns, pages, the about and status rows); only the drawing differs: the lit item is a reversed bar in its own colour, and each change goes out as raw PETSCII, the spans of the rows that changed, through session.write_raw.
The menu takes the rectangle at row, col (0-based), width columns wide, of the canvas the board draws its screen on. Either the board draws the whole screen first (paint the menu onto the canvas, send the canvasâs frame, then run(drawn: true)), or run paints the menu and sends its rows itself.
The colours (colors and an Itemâs color) are C64 colours: a BBS::Petscii::Canvas code, a name (:yellow) or a colour of the palette (BBS::Petscii::Colors, YE); the roles default to the Selectorâs COLORS.
canvas = BBS::Petscii::Canvas.new house.draw_canvas(canvas) # a BBS::Art items = [BBS::Selector.item('CORK BOARD', key: 'm', value: :boards, color: :light_blue), BBS::Selector.item('GAMES ROOM', key: 'r', value: :doors, color: :orange), BBS::Selector.item('LEAVE', key: 'q', value: :quit)] menu = BBS::Petscii::CanvasMenu.new(session, items, canvas: canvas, row: 12, col: 1, width: 36, columns: 2, hint: 'CRSR: CHOOSE RETURN: OPEN') menu.paint session.write_raw(canvas.frame) choice = menu.run(drawn: true)
With idle seconds and a block the menu animates while the caller thinks: the block is called each time idle seconds pass without a key and returns the bytes to send (or nil); a key stops waiting at once.
Attributes
The canvas the menu is drawn on.
Public Class Methods
Source
# File lib/bbs/petscii/canvas_menu.rb, line 59 def initialize(session, items, canvas:, row:, col:, rest: [Canvas::ROWS - 1, 0], idle: nil, **, &on_idle) super(session, items, **) @canvas = canvas @top = row @left = col @rest = rest @keys = Keys.new(session, idle, on_idle) @colors = @colors.transform_values { |c| Canvas.color(c) } end
Creates a menu for session on canvas.
- items
-
the cells,
Selector::Item(BBS::Selector.itemandBBS::Selector.heading); an itemâscoloris a C64 colour - canvas
-
the
BBS::Petscii::Canvasof the screen - row
-
the screen row of the first item, 0-based
- col
-
the screen column of the menuâs left edge, 0-based
- rest
-
where the cursor waits after each change, [row, col]; default the start of the screenâs last row
- idle
-
seconds without a key after which the block is called, or
nil
The other options (width, height, columns, index, numbers, across, hint, exits, back, colors) are those of BBS::Selector.new. Raises ArgumentError for a menu with nothing to select or an unknown colour.
Public Instance Methods
Source
# File lib/bbs/petscii/canvas_menu.rb, line 71 def paint (1..rows).each { |l| paint_line(l) } self end
Draws the whole menu onto the canvas, sending nothing. Returns self.
Source
# File lib/bbs/petscii/canvas_menu.rb, line 83 def run(drawn: false) @drawn = drawn super() end
Reads keys until an item is taken or the caller goes back, as BBS::Selector#run does. With drawn the caller has already sent the screen with the menu paint ed on it; otherwise the menu paints itself and sends its rows first.
Returns the taken itemâs value, an exits value, or back. Raises IOError when the caller hangs up.