Module: DXRubyEditor::Core::Renderer
- Defined in:
- lib/dxruby_editor/core/renderer.rb
Constant Summary collapse
- @@font21 =
Font.new(21)
- @@font_ =
Font.new(14)
- @@font10 =
Font.new(10)
- @@editor_main_y =
20
Class Method Summary collapse
- .draw_cursor(target, context, theme) ⇒ Object
- .draw_footer(_target, context, _theme) ⇒ Object
- .draw_lineno(target, context, theme) ⇒ Object
- .draw_notifications(target, _context, _theme) ⇒ Object
- .draw_text(target, context, theme) ⇒ Object
- .draw_text_syntax(target, context, theme) ⇒ Object
- .update(target, context, theme) ⇒ Object
Class Method Details
.draw_cursor(target, context, theme) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/dxruby_editor/core/renderer.rb', line 110 def draw_cursor(target, context, theme) _w = @@font21.get_width(context.text[context.cursor_y - 1][0..context.cursor_x - 2]) _w = 0 if context.cursor_x == 1 if theme[:cursor].length == 3 _alpha = Math.sin(context.tick / 20.0).abs * 255 _color = theme[:cursor].dup _color.unshift(_alpha) else _alpha = Math.sin(context.tick / 20.0).abs * theme[:cursor][0] _color = theme[:cursor].dup _color[0] = _alpha end target.draw_box_fill(@editor_main_x + _w, @@editor_main_y + @@font21.size * (context.cursor_y - 1), @editor_main_x + _w + 1, @@editor_main_y + @@font21.size * context.cursor_y, _color) end |
.draw_footer(_target, context, _theme) ⇒ Object
135 136 137 138 |
# File 'lib/dxruby_editor/core/renderer.rb', line 135 def (_target, context, _theme) Window.draw_font(Window.width - 300, Window.height - 20, "行 #{context.cursor_y}、列 #{context.cursor_x}", @@font10) end |
.draw_lineno(target, context, theme) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dxruby_editor/core/renderer.rb', line 22 def draw_lineno(target, context, theme) context.text.length.times do |i| if i + 1 == context.cursor_y _color = theme[:lineno_active] # draw line highlight target.draw_box_fill(0, @@editor_main_y + @@font21.size * i, target.width, @@editor_main_y + @@font21.size * (i + 1), theme[:line_highlight]) else _color = theme[:lineno] end target.draw_font(@editor_main_x - 10 - @@font21.get_width((i + 1).to_s), @@editor_main_y + @@font21.size * i, (i + 1).to_s, @@font21, color: _color) end end |
.draw_notifications(target, _context, _theme) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/dxruby_editor/core/renderer.rb', line 128 def draw_notifications(target, _context, _theme) @notifications.each_with_index do |msg, i| # target.draw_box_fill() target.draw_font(240, 300 + i * (@@font_.size + 10), msg, @@font_) end end |
.draw_text(target, context, theme) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/dxruby_editor/core/renderer.rb', line 38 def draw_text(target, context, theme) context.text.each_with_index do |str, i| target.draw_font(@editor_main_x, @@editor_main_y + i * @@font21.size, str.chomp, @@font21, color: theme[:font]) end end |
.draw_text_syntax(target, context, theme) ⇒ Object
45 46 47 48 49 50 51 52 53 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/dxruby_editor/core/renderer.rb', line 45 def draw_text_syntax(target, context, theme) # TODO: シンタックスハイライト機能 # pp Ripper.lex(context.string) if context.tick % 100 == 0 _width = 0 before_line = -1 str = '' context.text.each { |_| str << _ << "\n" } Ripper.lex(str).each do |_| line = _[0][0] column = _[0][1] symbol = _[1] char = _[2] lexer_state = _[3] if before_line != line _width = 0 before_line = line end # Ref https://github.com/ruby/ruby/blob/master/ext/ripper/eventids2.c#L83 _color = case symbol when :on_comment # comment theme[:syntax_comment] || theme[:font] when :on_kw # keyword ( class, def, end ... ) theme[:syntax_keyword] || theme[:font] when :on_op # operator theme[:syntax_op] || theme[:font] when :on_const # CONSTANT, ClassName theme[:syntax_constant] || theme[:font] when :on_label, :symbeg # symbol theme[:syntax_constant] || theme[:font] when :on_int, :on_float # integer theme[:syntax_numeric] || theme[:font] when :on_ident, :on_ivar, :on_cvar, :on_gvar, :on_backref # variable theme[:syntax_variable] || theme[:font] when :on_tstring_beg, :on_tstring_text, :on_tstring_end # string theme[:syntax_string] || theme[:font] when :on_regexp_beg, :on_regexp_end # regex theme[:syntax_regex] || theme[:font] # when :on_comma # comma # theme[:font] # when :on_period # period # theme[:font] # when :on_semicolon # semicolon # theme[:font] # when :on_lparen, :on_rparen # () # C_WHITE # when :on_lbracket, :on_rbracket # [] # C_WHITE # when :on_lbrace, :on_rbrace # {} # C_WHITE else theme[:font] end target.draw_font(@editor_main_x + _width, @@editor_main_y + (line - 1) * @@font21.size, char.chomp, @@font21, color: _color) _width += @@font21.get_width(char) end # context.text.each_with_index do |c, i| # draw_font_ex(@editor_main_x, @@editor_main_y + i * @@font21.size, c, @@font21) # end end |
.update(target, context, theme) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/dxruby_editor/core/renderer.rb', line 4 def update(target, context, theme) draw_lineno(target, context, theme) # draw_text(target, context, theme) draw_text_syntax(target, context, theme) draw_cursor(target, context, theme) # draw_scrollbar(target, context, theme) # draw_notifications(target, context, theme) (target, context, theme) end |