Brightness slider works with mouse wheel.
This commit is contained in:
@ -7,14 +7,14 @@ declblock {\#if 1} {
|
|||||||
extern void saverChosen();
|
extern void saverChosen();
|
||||||
extern void perfChosen();} open public map 1 after {\#endif}
|
extern void perfChosen();} open public map 1 after {\#endif}
|
||||||
} {
|
} {
|
||||||
decl {\#include "power_console_common.h"} {selected public global
|
decl {\#include "power_console_common.h"} {public global
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Function {make_window()} {open
|
Function {make_window()} {open
|
||||||
} {
|
} {
|
||||||
Fl_Window {} {open
|
Fl_Window {} {open
|
||||||
xywh {506 191 177 183} type Double box GLEAM_UP_BOX visible
|
xywh {506 1271 177 183} type Double box GLEAM_UP_BOX visible
|
||||||
} {
|
} {
|
||||||
Fl_Light_Button conserveButton {
|
Fl_Light_Button conserveButton {
|
||||||
label {Conserve Battery}
|
label {Conserve Battery}
|
||||||
@ -52,6 +52,7 @@ Function {make_window()} {open
|
|||||||
label Brightness
|
label Brightness
|
||||||
callback adjustBrightness
|
callback adjustBrightness
|
||||||
xywh {129 81 20 52} labelsize 12
|
xywh {129 81 20 52} labelsize 12
|
||||||
|
class MouseWheelSlider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,49 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <Fl/Fl.H>
|
||||||
|
#include <Fl/Fl_Window.H>
|
||||||
|
#include <Fl/Fl_Value_Slider.H>
|
||||||
|
|
||||||
|
|
||||||
void saverChosen();
|
void saverChosen();
|
||||||
void perfChosen();
|
void perfChosen();
|
||||||
void balChosen();
|
void balChosen();
|
||||||
|
|
||||||
|
class MouseWheelSlider : public Fl_Value_Slider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit
|
||||||
|
MouseWheelSlider( const int x, const int y, const int w, const int h,
|
||||||
|
const char *const l= 0 )
|
||||||
|
: Fl_Value_Slider( x, y, w, h, l )
|
||||||
|
{
|
||||||
|
|
||||||
|
step( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
handle( const int event ) override
|
||||||
|
{
|
||||||
|
switch( event )
|
||||||
|
{
|
||||||
|
case FL_MOUSEWHEEL:
|
||||||
|
{
|
||||||
|
// Negative, because I use this for the Brightness control.
|
||||||
|
const int dy= -Fl::event_dy();
|
||||||
|
|
||||||
|
value( value() - dy * step() );
|
||||||
|
|
||||||
|
do_callback();
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return this->Fl_Value_Slider::handle( event );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -88,7 +89,7 @@ scheduledUpdate( void * )
|
|||||||
int in;
|
int in;
|
||||||
inf >> in;
|
inf >> in;
|
||||||
|
|
||||||
brightness->value( 101 - 100 * in / max );
|
brightness->value( 100 * in / max );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since this requires launching bg processes, we only do it at startup and then every 30s.
|
// Since this requires launching bg processes, we only do it at startup and then every 30s.
|
||||||
@ -115,9 +116,9 @@ main( const int argcnt, char **argvec )
|
|||||||
level->value( 0 );
|
level->value( 0 );
|
||||||
level->label( battLevelString.c_str() );
|
level->label( battLevelString.c_str() );
|
||||||
|
|
||||||
brightness->minimum( 1 );
|
brightness->maximum( 1 );
|
||||||
brightness->maximum( 100 );
|
brightness->minimum( 100 );
|
||||||
brightness->step( 1 );
|
brightness->step( -1 );
|
||||||
|
|
||||||
|
|
||||||
w->hotspot( w );
|
w->hotspot( w );
|
||||||
@ -203,9 +204,9 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
adjustBrightness( Fl_Slider *, void * )
|
adjustBrightness( MouseWheelSlider *, void * )
|
||||||
{
|
{
|
||||||
const int amount= 101 - brightness->value();
|
const int amount= brightness->value();
|
||||||
std::cerr << "Adjusting brightness by " << amount << std::endl;
|
std::cerr << "Adjusting brightness by " << amount << std::endl;
|
||||||
changeBrightness( amount );
|
changeBrightness( std::clamp( amount, 1, 100 ) );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user