Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
Add Particles drawing mode
Browse files Browse the repository at this point in the history
Related: #7
  • Loading branch information
fsobolev committed Jan 4, 2023
1 parent a6070c1 commit a009fb1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions data/io.github.fsobolev.Cavalier.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<choices>
<choice value="wave"/>
<choice value="levels"/>
<choice value="particles"/>
<choice value="bars"/>
</choices>
<default>"wave"</default>
Expand Down
11 changes: 11 additions & 0 deletions src/draw_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ def levels(sample, cr, width, height, colors, offset, radius):
step - offset_px * 2, height / 10 - offset_px * 2, radius)
cr.fill()

def particles(sample, cr, width, height, colors, offset, radius):
set_source(cr, height, colors)
ls = len(sample)
step = width / ls
offset_px = step * offset / 100
for i in range(ls):
draw_element(cr, step * i + offset_px, \
height * 0.9 - height * 0.9 * sample[i] + offset_px, step - offset_px * 2, \
height / 10 - offset_px * 2, radius)
cr.fill()

def bars(sample, cr, width, height, colors, offset):
set_source(cr, height, colors)
ls = len(sample)
Expand Down
7 changes: 4 additions & 3 deletions src/drawing_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from gi.repository import Gtk, GObject
from threading import Thread
from cavalier.cava import Cava
from cavalier.draw_functions import wave, levels, bars
from cavalier.draw_functions import wave, levels, particles, bars
from cavalier.settings import CavalierSettings

class CavalierDrawingArea(Gtk.DrawingArea):
Expand Down Expand Up @@ -93,11 +93,12 @@ def draw_func(self, area, cr, width, height, data, n):
elif self.draw_mode == 'levels':
levels(self.cava_sample, cr, width, height, self.colors, \
self.offset, self.roundness)
elif self.draw_mode == 'particles':
particles(self.cava_sample, cr, width, height, self.colors, \
self.offset, self.roundness)
elif self.draw_mode == 'bars':
bars(self.cava_sample, cr, width, height, self.colors, \
self.offset)
else:
print(f'Error: Unknown drawing mode "{self.draw_mode}"')

def redraw(self):
self.queue_draw()
Expand Down
16 changes: 13 additions & 3 deletions src/preferences_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ def create_cavalier_page(self):
self.levels_row.set_activatable_widget(self.levels_check_btn)
self.cavalier_mode_group.add(self.levels_row)

self.particles_row = Adw.ActionRow.new()
self.particles_row.set_title(_('Particles'))
self.particles_check_btn = Gtk.CheckButton.new()
self.particles_check_btn.set_group(self.wave_check_btn)
self.particles_row.add_prefix(self.particles_check_btn)
self.particles_row.set_activatable_widget(self.particles_check_btn)
self.cavalier_mode_group.add(self.particles_row)

self.bars_row = Adw.ActionRow.new()
self.bars_row.set_title(_('Bars'))
self.bars_check_btn = Gtk.CheckButton.new()
Expand Down Expand Up @@ -294,9 +302,9 @@ def create_colors_page(self):
self.bg_color_btns = []

def load_settings(self):
(self.wave_check_btn, self.levels_check_btn, self.bars_check_btn)[ \
('wave', 'levels', 'bars').index(self.settings.get('mode')) \
].set_active(True)
(self.wave_check_btn, self.levels_check_btn, self.particles_check_btn, \
self.bars_check_btn)[ ('wave', 'levels', 'particles', \
'bars').index(self.settings.get('mode')) ].set_active(True)
self.pref_margin_scale.set_value(self.settings.get('margin'))
self.pref_offset_scale.set_value(self.settings.get('items-offset'))
self.pref_roundness_scale.set_value(round(self.settings.get('items-roundness') / 50.0, 2))
Expand Down Expand Up @@ -333,6 +341,8 @@ def load_settings(self):
def bind_settings(self):
self.wave_row.connect('activated', self.on_save, 'mode', 'wave')
self.levels_row.connect('activated', self.on_save, 'mode', 'levels')
self.particles_row.connect('activated', self.on_save, 'mode', \
'particles')
self.bars_row.connect('activated', self.on_save, 'mode', 'bars')
self.pref_margin_scale.connect('value-changed', self.on_save, \
'margin', self.pref_margin_scale.get_value)
Expand Down

0 comments on commit a009fb1

Please sign in to comment.