# background.rb: the style of the background of a plot. # copyright (c) 2009 by Vincent Fourmond # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details (in the COPYING file). require 'ctioga2/utils' require 'ctioga2/log' module CTioga2 Version::register_svn_info('$Revision$', '$Date$') module Graphics module Styles # The style of the background of a plot. Handles: # * uniform background colors (fine) # * (text) watermark # * pictures (in a distant future ?) class BackgroundStyle < BasicStyle # The background color for a uniform fill. attr_accessor :background_color # The text of the watermark, or _nil_ if there should be no # watermark. attr_accessor :watermark_text # A MarkerStringStyle object representing the style of the # watermark. attr_accessor :watermark_style # Creates a new AxisStyle object at the given location with # the given style. def initialize(location = nil, type = nil, label = nil) @background_color = nil @watermark_style = MarkerStringStyle.new @watermark_style.color = [0.5,0.5,0.5] end # Draws the background of the current plot. Fills up the # current frame. def draw_background(t) t.context do xl, yb, xr, yt = t.bounds_left, t.bounds_bottom, t.bounds_right, t.bounds_top if @background_color t.fill_color = @background_color t.fill_frame end draw_watermark(t) end end def draw_watermark(t) if @watermark_text x = t.convert_frame_to_figure_x(0.5) y = t.convert_frame_to_figure_y(0.5) delta_y = t.default_text_height_dy * @watermark_style. real_vertical_scale # We split lines on \\, just like in standard LaTeX lines = @watermark_text.split(/\s*\\\\\s*/) i = + (lines.size-1)/2.0 for text in lines @watermark_style. draw_string_marker(t, text, x, y + delta_y * i) i -= 1 end end end end BackgroundGroup = CmdGroup.new('background', "Background", <