Module: Shellfie::Rendering::WindowChrome
- Includes:
- ShapeHelpers
- Included in:
- Shellfie::RasterPainter
- Defined in:
- lib/shellfie/rendering/window_chrome.rb
Instance Method Summary collapse
- #button_group_width(geometry) ⇒ Object
- #circle_button_centers(geometry) ⇒ Object
- #draw_border(convert, geometry) ⇒ Object
- #draw_buttons(convert, geometry) ⇒ Object
- #draw_shadow(convert, geometry) ⇒ Object
- #draw_title(convert, geometry) ⇒ Object
- #draw_title_bar(convert, geometry) ⇒ Object
- #draw_title_separator(convert, geometry, y) ⇒ Object
- #draw_window(convert, geometry, transparent:) ⇒ Object
- #draw_windows_buttons(convert, geometry) ⇒ Object
- #title_x(min_x, max_x, centered_x) ⇒ Object
Methods included from ShapeHelpers
#draw_roundrect, #draw_windows_icon
Instance Method Details
#button_group_width(geometry) ⇒ Object
183 184 185 186 187 188 189 190 191 192 |
# File 'lib/shellfie/rendering/window_chrome.rb', line 183 def (geometry) scale = geometry[:scale] if theme. == :icons ((theme.window_decoration[:button_width] || 46) * 3 * scale).to_i else size = theme.window_decoration[:button_size] spacing = theme.window_decoration[:button_spacing] ((size * 3 + spacing * 2) * scale).to_i end end |
#circle_button_centers(geometry) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/shellfie/rendering/window_chrome.rb', line 119 def (geometry) scale = geometry[:scale] size = (theme.window_decoration[:button_size] * scale).to_i spacing = ((theme.window_decoration[:button_spacing] + theme.window_decoration[:button_size]) * scale).to_i y = geometry[:margin] + geometry[:scaled_title_bar] / 2 start_x = if theme. == :left geometry[:margin] + (16 * scale).to_i else group_width = size * 3 + (theme.window_decoration[:button_spacing] * scale).to_i * 2 geometry[:margin] + geometry[:scaled_width] - (16 * scale).to_i - group_width + size / 2 end 3.times.map { |index| [start_x + index * spacing, y] } end |
#draw_border(convert, geometry) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/shellfie/rendering/window_chrome.rb', line 86 def draw_border(convert, geometry) color = theme.colors[:border] return unless color convert.fill "none" convert.stroke color convert.strokewidth [geometry[:scale].to_i, 1].max draw_roundrect( convert, geometry[:margin], geometry[:margin], geometry[:margin] + geometry[:scaled_width] - 1, geometry[:margin] + geometry[:scaled_height] - 1, geometry[:scaled_radius] ) convert.stroke "none" end |
#draw_buttons(convert, geometry) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/shellfie/rendering/window_chrome.rb', line 104 def (convert, geometry) return (convert, geometry) if theme. == :icons = ((theme.window_decoration[:button_size] / 2.0) * geometry[:scale]).to_i centers = (geometry) centers.each_with_index do |(x, y), index| convert.fill theme.[index] convert.stroke "rgba(0,0,0,0.18)" convert.strokewidth [geometry[:scale].to_i, 1].max ImageMagickCommandBuilder.circle(convert, x, y, ) end convert.stroke "none" end |
#draw_shadow(convert, geometry) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/shellfie/rendering/window_chrome.rb', line 12 def draw_shadow(convert, geometry) shadow = theme.window_decoration[:shadow] scale = geometry[:scale] offset_x = (shadow[:offset_x] * scale).to_i offset_y = (shadow[:offset_y] * scale).to_i radius = geometry[:scaled_radius] margin = geometry[:margin] convert.fill shadow[:color] draw_roundrect( convert, margin + offset_x, margin + offset_y, margin + geometry[:scaled_width] - 1 + offset_x, margin + geometry[:scaled_height] - 1 + offset_y, radius ) convert.blur "0x#{(shadow[:blur] * scale).to_i}" end |
#draw_title(convert, geometry) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/shellfie/rendering/window_chrome.rb', line 155 def draw_title(convert, geometry) scaled_font_size = geometry[:scaled_font_size] group_width = (geometry) reserve_left = theme. == :left ? group_width + (32 * geometry[:scale]).to_i : (12 * geometry[:scale]).to_i reserve_right = theme. == :right ? group_width + (12 * geometry[:scale]).to_i : (12 * geometry[:scale]).to_i available_width = geometry[:scaled_width] - reserve_left - reserve_right title = fit_text(config.title.to_s, available_width, scaled_font_size) title_width = TextMetrics.pixel_width(title, scaled_font_size) min_x = geometry[:margin] + reserve_left max_x = geometry[:margin] + geometry[:scaled_width] - reserve_right - title_width centered_x = geometry[:margin] + (geometry[:scaled_width] - title_width) / 2 x = title_x(min_x, max_x, centered_x) y = geometry[:margin] + geometry[:scaled_title_bar] / 2 + scaled_font_size / 3 draw_text(convert, title, x, y - scaled_font_size, theme.colors[:title_text], scaled_font_size, geometry[:font_config]) end |
#draw_title_bar(convert, geometry) ⇒ Object
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 |
# File 'lib/shellfie/rendering/window_chrome.rb', line 49 def (convert, geometry) margin = geometry[:margin] title_y2 = margin + geometry[:scaled_title_bar] - 1 convert.fill theme.colors[:title_bar] draw_roundrect( convert, margin, margin, margin + geometry[:scaled_width] - 1, title_y2, geometry[:scaled_radius] ) convert.fill theme.colors[:title_bar] ImageMagickCommandBuilder.rectangle( convert, margin, margin + geometry[:scaled_radius], margin + geometry[:scaled_width] - 1, title_y2 ) draw_title_separator(convert, geometry, title_y2) (convert, geometry) draw_title(convert, geometry) end |
#draw_title_separator(convert, geometry, y) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/shellfie/rendering/window_chrome.rb', line 76 def draw_title_separator(convert, geometry, y) color = theme.colors[:title_bar_border] return unless color convert.stroke color convert.strokewidth 1 ImageMagickCommandBuilder.line(convert, geometry[:margin], y, geometry[:margin] + geometry[:scaled_width] - 1, y) convert.stroke "none" end |
#draw_window(convert, geometry, transparent:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/shellfie/rendering/window_chrome.rb', line 32 def draw_window(convert, geometry, transparent:) margin = geometry[:margin] background = color_with_opacity(theme.colors[:background], config.window[:opacity], true) convert.fill background draw_roundrect( convert, margin, margin, margin + geometry[:scaled_width] - 1, margin + geometry[:scaled_height] - 1, geometry[:scaled_radius] ) draw_border(convert, geometry) end |
#draw_windows_buttons(convert, geometry) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/shellfie/rendering/window_chrome.rb', line 135 def (convert, geometry) scale = geometry[:scale] = ((theme.window_decoration[:button_width] || 46) * scale).to_i icon_size = (10 * scale).to_i start_x = geometry[:margin] + geometry[:scaled_width] - * 3 center_y = geometry[:margin] + geometry[:scaled_title_bar] / 2 color = theme.colors[:title_text] convert.stroke color convert.strokewidth [scale.to_i, 1].max convert.fill "none" 3.times do |index| center_x = start_x + * index + / 2 draw_windows_icon(convert, index, center_x, center_y, icon_size) end convert.stroke "none" end |
#title_x(min_x, max_x, centered_x) ⇒ Object
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/shellfie/rendering/window_chrome.rb', line 172 def title_x(min_x, max_x, centered_x) case theme.title_alignment when :left min_x when :right max_x else [[centered_x, min_x].max, max_x].min end end |