diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-29 19:24:18 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-29 19:24:18 +0200 |
commit | 0ae475ff5b68d204ee31775107b3cccec2acc97f (patch) | |
tree | b1d8c2b244337006fc4c21070795a9eb8380e783 /Applications/Terminal | |
parent | 9c6be9b21e3da727ef41908f0377cf1547dfc9c3 (diff) | |
download | serenity-0ae475ff5b68d204ee31775107b3cccec2acc97f.zip |
Terminal: Add ability to adjust the terminal's opacity.
Diffstat (limited to 'Applications/Terminal')
-rw-r--r-- | Applications/Terminal/Terminal.cpp | 8 | ||||
-rw-r--r-- | Applications/Terminal/Terminal.h | 2 | ||||
-rw-r--r-- | Applications/Terminal/main.cpp | 23 |
3 files changed, 32 insertions, 1 deletions
diff --git a/Applications/Terminal/Terminal.cpp b/Applications/Terminal/Terminal.cpp index b95ba07b30..f4f9dc3fb7 100644 --- a/Applications/Terminal/Terminal.cpp +++ b/Applications/Terminal/Terminal.cpp @@ -882,3 +882,11 @@ void Terminal::update_cursor() invalidate_cursor(); flush_dirty_lines(); } + +void Terminal::set_opacity(float opacity) +{ + if (m_opacity == opacity) + return; + m_opacity = opacity; + force_repaint(); +} diff --git a/Applications/Terminal/Terminal.h b/Applications/Terminal/Terminal.h index faee6ed02a..b447de196d 100644 --- a/Applications/Terminal/Terminal.h +++ b/Applications/Terminal/Terminal.h @@ -24,6 +24,8 @@ public: void apply_size_increments_to_window(GWindow&); + void set_opacity(float); + private: typedef Vector<unsigned, 4> ParamVector; diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp index cb82da4470..e7662718b6 100644 --- a/Applications/Terminal/main.cpp +++ b/Applications/Terminal/main.cpp @@ -15,6 +15,7 @@ #include <LibGUI/GMenuBar.h> #include <LibGUI/GAction.h> #include <LibGUI/GFontDatabase.h> +#include <LibGUI/GSlider.h> static void make_shell(int ptm_fd) { @@ -93,16 +94,36 @@ int main(int argc, char** argv) window->set_should_exit_event_loop_on_close(true); Terminal terminal(ptm_fd); - window->set_has_alpha_channel(false); + window->set_has_alpha_channel(true); window->set_main_widget(&terminal); window->move_to(300, 300); terminal.apply_size_increments_to_window(*window); window->show(); window->set_icon_path("/res/icons/16x16/app-terminal.png"); + auto* opacity_adjustment_window = new GWindow; + opacity_adjustment_window->set_title("Adjust opacity"); + opacity_adjustment_window->set_rect(50, 50, 200, 100); + + auto* slider = new GSlider(nullptr); + opacity_adjustment_window->set_main_widget(slider); + slider->set_fill_with_background_color(true); + slider->set_background_color(Color::LightGray); + + slider->on_value_changed = [&terminal] (int value) { + float opacity = value / 100.0; + terminal.set_opacity(opacity); + }; + + slider->set_range(0, 100); + slider->set_value(80); + auto menubar = make<GMenuBar>(); auto app_menu = make<GMenu>("Terminal"); + app_menu->add_action(GAction::create("Adjust opacity...", [opacity_adjustment_window] (const GAction&) { + opacity_adjustment_window->show(); + })); app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [] (const GAction&) { dbgprintf("Terminal: Quit menu activated!\n"); GApplication::the().quit(0); |