diff options
| author | Kevin Fischer <[email protected]> | 2020-04-04 21:50:45 +0900 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-04-05 07:59:40 -0500 |
| commit | e1be96936d07f5260a0a92b75e30116aa1b9290c (patch) | |
| tree | f69448f331f59e0f207942b9e818524369151df8 | |
| parent | 6e2d3d9d90ec56c510f5200d89eb98d69ae4e012 (diff) | |
| download | dragonruby-game-toolkit-contrib-e1be96936d07f5260a0a92b75e30116aa1b9290c.tar.gz dragonruby-game-toolkit-contrib-e1be96936d07f5260a0a92b75e30116aa1b9290c.zip | |
Refactor render method
| -rw-r--r-- | dragon/console.rb | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/dragon/console.rb b/dragon/console.rb index 0037d1b..841b040 100644 --- a/dragon/console.rb +++ b/dragon/console.rb @@ -18,6 +18,10 @@ module GTK def to_a @color end + + def to_h + { r: @color[0], g: @color[1], b: @color[2], a: @color[3] } + end end class FontStyle @@ -36,6 +40,18 @@ module GTK def line_height_px @line_height_px ||= letter_size.y * line_height end + + def label(options = {}, x:, y:, text:, color:) + { + x: x, + y: y.shift_up(line_height_px), # !!! FIXME: remove .shift_up(line_height_px) when we fix coordinate origin on labels. + text: text, + font: font, + size_enum: size_enum, + **color.to_h, + **options + }.label + end end attr_accessor :show_reason, :log, :prompt, :logo, :background_color, @@ -493,20 +509,17 @@ S bottom = top - (h * percent) args.outputs.reserved << [left, bottom, w, h, *@background_color.mult_alpha(percent)].solid + args.outputs.reserved << [right.shift_left(210), bottom.shift_up(540), 200, 200, @logo, 0, (80.0 * percent).to_i].sprite txtinfo = [*@text_color.mult_alpha(percent), font_style.font] errorinfo = [*@error_color.mult_alpha(percent), font_style.font] - cursorinfo = [*@cursor_color.mult_alpha(percent), font_style.font] headerinfo = [*@header_color.mult_alpha(percent), font_style.font] y = bottom + 2 # just give us a little padding at the bottom. - y += line_height_px # !!! FIXME: remove this when we fix coordinate origin on labels. - args.outputs.reserved << [right.shift_left(210), bottom.shift_up(540), 200, 200, @logo, 0, (80.0 * percent).to_i].sprite - args.outputs.reserved << [left.shift_right(10), y, "#{@prompt}#{@current_input_str}", font_style.size_enum, 0, *txtinfo].label - args.outputs.reserved << [left.shift_right(8), y + 3, (" " * (prompt.length + @current_input_str.length)) + "|", font_style.size_enum, 0, *cursorinfo ].label - - y += line_height_px.to_f / 2.0 - args.outputs.reserved << [left, y, right, y, *txtinfo].line + args.outputs.reserved << font_style.label(x: left.shift_right(10), y: y, text: "#{@prompt}#{@current_input_str}", color: @text_color) + args.outputs.reserved << font_style.label(x: left.shift_right(8), y: y + 3, text: (" " * (prompt.length + @current_input_str.length)) + "|", color: @cursor_color) + y += line_height_px * 1.5 + args.outputs.reserved << line(y: y, color: @text_color.mult_alpha(percent)) y += line_height_px.to_f / 2.0 y += line_height_px # !!! FIXME: remove this when we fix coordinate origin on labels. @@ -517,13 +530,12 @@ S end # past log seperator - args.outputs.reserved << [0, y - line_height_px.half, right, y - line_height_px.half, [txtinfo[0..2], txtinfo[3].idiv(4)]].line + args.outputs.reserved << line(y: y - line_height_px.half, color: @text_color.mult_alpha(0.25 * percent)) y += line_height_px txtinfo = [*@text_color.mult_alpha(percent.half), font_style.font] errorinfo = [*@error_color.mult_alpha(percent.half), font_style.font] - cursorinfo = [*@cursor_color.mult_alpha(percent.half), font_style.font] headerinfo = [*@header_color.mult_alpha(percent.half), font_style.font] ((@archived_log.size - @log_offset) - 1).downto(0) do |idx| @@ -640,5 +652,9 @@ S def lines_on_one_page (h - 4).idiv(line_height_px) end + + def line(y:, color:) + [left, y, right, y, *color].line + end end end |
