39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
#include "w_volume_bar.h"
|
|
|
|
#include "arona_application.h"
|
|
#include "tool/math/lerp.h"
|
|
|
|
w_volume_bar::w_volume_bar(bool vertical) : is_vertical(vertical)
|
|
{
|
|
set_content_height(10);
|
|
set_content_width(10);
|
|
set_draw_func(sigc::mem_fun(*this, &w_volume_bar::on_draw));
|
|
}
|
|
|
|
void w_volume_bar::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height) {
|
|
// Draw a black rectangle.
|
|
cr->set_source_rgba(0.0, 0.0, 0.0, 1.0);
|
|
cr->fill();
|
|
|
|
Cairo::RefPtr<Cairo::LinearGradient> line_color;
|
|
if (is_vertical) {
|
|
line_color = Cairo::LinearGradient::create(0, 0, 0, height);
|
|
} else {
|
|
line_color = Cairo::LinearGradient::create(0, 0, width, 0);
|
|
}
|
|
line_color->add_color_stop_rgb(0, 0.0, 1.0, 0.0);
|
|
line_color->add_color_stop_rgb(0.7, 0.5, 0.5, 0.0); // (0.5, 0.5, 0.5)
|
|
line_color->add_color_stop_rgb(1, 1.0, 0.0, 0.0);
|
|
cr->set_source(line_color);
|
|
|
|
// draw value bar
|
|
if (is_vertical) {
|
|
cr->rectangle(0, height * (1 - value_), width, height * value_);
|
|
} else {
|
|
cr->rectangle(0, 0, width * value_, height);
|
|
}
|
|
cr->fill();
|
|
|
|
cr->stroke();
|
|
}
|