From: cedlemo <nu...@co...> - 2017-08-29 00:06:06
|
cedlemo 2017-08-29 02:19:01 +0900 (Tue, 29 Aug 2017) New Revision: c9d876071fedae2feeb027fc0942b3d4b19a5e55 https://github.com/ruby-gnome2/ruby-gnome2/commit/c9d876071fedae2feeb027fc0942b3d4b19a5e55 Merged b3f3ba3: Merge pull request #1098 from cedlemo/gtk3_sample_gtk_demo_css_blendmodes_rb Message: Add css_blendmodes demo Added files: gtk3/sample/gtk-demo/css_blendmodes.rb Added: gtk3/sample/gtk-demo/css_blendmodes.rb (+90 -0) 100644 =================================================================== --- /dev/null +++ gtk3/sample/gtk-demo/css_blendmodes.rb 2017-08-29 02:19:01 +0900 (4cd5ec612) @@ -0,0 +1,90 @@ +# Copyright (c) 2017 Ruby-GNOME2 Project Team +# This program is licenced under the same licence as Ruby-GNOME2. +# +=begin += Theming/CSS Blend Modes + + You can blend multiple backgrounds using the CSS blend modes available. +=end + +BlendMode = Struct.new(:name, :id) + +class CssBlendmodesDemo + def initialize(main_window) + @builder = Gtk::Builder.new(:resource => "/css_blendmodes/blendmodes.ui") + @window = @builder["window"] + @window.transient_for = main_window + + # Setup the CSS provider for window + @provider = Gtk::CssProvider.new + Gtk::StyleContext.add_provider_for_screen(Gdk::Screen.default, + @provider, + Gtk::StyleProvider::PRIORITY_APPLICATION) + + initialize_blend_modes + setup_listbox + end + + def run + if !@window.visible? + @window.show_all + else + @window.destroy + end + @window + end + + private + + def initialize_blend_modes + @blend_modes = [] + @blend_modes << BlendMode.new("Color", "color") + @blend_modes << BlendMode.new("Color (burn)", "color-burn") + @blend_modes << BlendMode.new("Color (dodge)", "color-dodge") + @blend_modes << BlendMode.new("Darken", "darken") + @blend_modes << BlendMode.new("Difference", "difference") + @blend_modes << BlendMode.new("Exclusion", "exclusion") + @blend_modes << BlendMode.new("Hard Light", "hard-light") + @blend_modes << BlendMode.new("Hue", "hue") + @blend_modes << BlendMode.new("Lighten", "lighten") + @blend_modes << BlendMode.new("Luminosity", "luminosity") + @blend_modes << BlendMode.new("Multiply", "multiply") + @blend_modes << BlendMode.new("Normal", "normal") + @blend_modes << BlendMode.new("Overlay", "overlay") + @blend_modes << BlendMode.new("Saturate", "saturate") + @blend_modes << BlendMode.new("Screen", "screen") + @blend_modes << BlendMode.new("Soft Light", "soft-light") + end + + def setup_listbox + normal_row = nil + listbox = Gtk::ListBox.new + @builder["scrolledwindow"].add(listbox) + + listbox.signal_connect "row-activated" do |widget, w_row, w_provider| + blend_mode = @blend_modes[w_row.index].id + update_css_for_blend_mode(blend_mode) + end + + @blend_modes.each do |blend_mode| + row = Gtk::ListBoxRow.new + label = Gtk::Label.new(blend_mode.name) + label.xalign = 0 + row.add(label) + listbox.add(row) + + normal_row = row if blend_mode.id == "normal" + end + + # select the "normal" row + listbox.select_row(normal_row) + normal_row.signal_emit("activate") + normal_row.grab_focus + end + + def update_css_for_blend_mode(blend_mode) + raw_css = Gio::Resources.lookup_data("/css_blendmodes/css_blendmodes.css", 0) + css = sprintf(raw_css, blend_mode, blend_mode, blend_mode) + @provider.load_from_data(css) + end +end |