screenruler-0.960+bzr41/0000775000175000017500000000000011707631652014353 5ustar rainctrainctscreenruler-0.960+bzr41/preferences_window.glade0000664000175000017500000006625211707631463021254 0ustar rainctrainct 10 1000 96 1 10 False 6 Settings False center gtk-preferences True False True False 12 True False 18 True False 0 none True False 6 12 True False 3 2 6 6 True True False False Background Color 1 2 1 2 True True False False Ticks and Numbers Color 1 2 True False 6 True False 0 _Font: True text_fontbutton True True 0 True True False False True False True 1 2 2 3 GTK_FILL True False 0 _Numbers and lines: True foreground_color_button GTK_FILL True False 0 _Background: True background_color_button 1 2 GTK_FILL True False <b>Appearance</b> True True True 0 True False 0 none True False 12 6 True False True False 6 True True False False True True False 6 True False _System Settings True False False 0 True False (set in code) True False False 1 False False 0 _Custom Settings True True False False True True radiobutton False False 1 False False 0 True False False 6 16 True False 2 2 6 6 True True 4 False False False True True horizontal_pixels_per_inch_adjustment 1 True 1 2 GTK_FILL True True 4 False False True True vertical_pixels_per_inch_adjustment 1 1 2 1 2 GTK_FILL True False 0 _Horizontal pixels per inch: True ppi_horizontal_spinbutton True False 0 _Vertical pixels per inch: True ppi_vertical_spinbutton 1 2 True True 1 True False 6 True False <b>Screen Pixels per Inch</b> True False False 0 True True 1 True True 0 True False end gtk-close True True True True False False True False False 0 False True 1 10 1000 96 1 10 screenruler-0.960+bzr41/help_window.rb0000664000175000017500000000232711707631463017223 0ustar rainctrainct ############################################################################### # Copyright 2011 Ian McIntosh # # 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 Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ############################################################################### require 'glade_window' class HelpWindow < GladeWindow def initialize super('help_window') @window.signal_connect('delete_event') { hide } on_key_press(Gdk::Keyval::GDK_Escape) { hide } end def on_close_button_clicked hide end end # Local Variables: # tab-width: 2 # End: screenruler-0.960+bzr41/AUTHORS0000664000175000017500000000004311707631463015420 0ustar rainctrainctIan McIntosh screenruler-0.960+bzr41/screenruler-icon-32x32.png0000664000175000017500000000101711707631463021116 0ustar rainctrainctPNG  IHDR szzsRGBbKGD pHYs B(xtIME 'VxIDATXW;N@}3Y'Cp@(RJ 87 @*"qKᏼIxAf ̼4WK /ocZ+Q2Z.H\ngCH yߋ9,$j%`z7g@r_bP@)g/hmFI7hZCR"JBg.jb,ZtJBSvj+vLdQI+Z|GK}s mMc.APszω̞23~ ^)KVPZ6ѳlSpsW2|6ADc`KeMH xksH&/ hIENDB`screenruler-0.960+bzr41/ruler_window.rb0000664000175000017500000003673211707631463017433 0ustar rainctrainct ############################################################################### # Copyright 2011 Ian McIntosh # # 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 Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ############################################################################### require 'glade_window', 'ruler_popup_menu', 'canvas', 'unique_timeout' Unit = Struct.new('Unit', :name, :tick_pattern, :units_per_pattern_repetition, :per_inch) class RulerWindow < GladeWindow DEFAULT_RULER_LENGTH = 600 MOVE_SMALL, MOVE_LARGE = 1, 15 GROW_SMALL, GROW_LARGE = 1, 15 ORIENTATION_LEFT, ORIENTATION_UP = 'left', 'up' # where the value '0 pixels' is MENU_BOX_WIDTH, MENU_BOX_HEIGHT = 10, 10 MENU_BOX_RELIEF = 10 # distance from edge OVERDRAW = 200 # ensures that final tick labels get drawn, even when the tick itself is past the window MEASUREMENT_TOOLTIP_UPDATE_FREQUENCY = 80 # in milliseconds @@unit_settings = { UNIT_INCHES => Unit.new(_('in'), 'MMMLMMML', 1, 1), UNIT_CENTIMETERS => Unit.new(_('cm'), 'MMMMLMMMML', 1, 0.3937), UNIT_PICAS => Unit.new(_('pc'), 'MMLMML', 6, 0.1667), UNIT_POINTS => Unit.new(_('pt'), 'MMMMMLMMMMML', 72, 0.0139), UNIT_PIXELS => Unit.new(_('px'), 'SSSSMSSSSMSSSSMSSSSMSSSSL' * 2, 100, -1), # :per_inch not used... UNIT_PERCENTAGE => Unit.new(_('%'), 'ML', 10, -1) # ...ditto }.freeze @@tick_sizes = {'S' => 4, 'M' => 7, 'L' => 10}.freeze # length of tick marks (in pixels) in above patterns def initialize super('ruler_window') self.icon_list = APP_ICON_LIST # Fill our window with a DrawingArea to render the ruler @canvas = Canvas.new.set_draw_proc { |cr| draw(cr) } @window << @canvas.widget @mouse_is_in_window = false # we'll get a notify right away if mouse begins in the window @orientation = ORIENTATION_LEFT configure_ppi configure_orientation # GTK signal handlers (others hooked up by Glade) @canvas.widget.add_events(Gdk::Event::ENTER_NOTIFY_MASK).signal_connect('enter_notify_event') { self.mouse_is_in_window = true } @canvas.widget.add_events(Gdk::Event::LEAVE_NOTIFY_MASK).signal_connect('leave_notify_event') { self.mouse_is_in_window = false } @measurement_tooltip_timeout = UniqueTimeout.new(MEASUREMENT_TOOLTIP_UPDATE_FREQUENCY) { update_measurement_tooltip } end def present super self.opacity = $preferences_window.opacity if self.respond_to? :opacity= end def show_measurement_tooltip=(val) if val @measurement_tooltip_timeout.start else @measurement_tooltip_timeout.stop end @enable_mouse_tracking = val redraw end def update_measurement_tooltip # Force a redraw if mouse has moved __window__unused__, mouse_x, mouse_y, key_mask = Gdk::Window.default_root_window.pointer if mouse_x != @previous_mouse_x or mouse_y != @previous_mouse_y or key_mask != @previous_key_mask # save for later comparison @previous_mouse_x, @previous_mouse_y, @previous_key_mask = mouse_x, mouse_y, key_mask redraw end end def progress_pixels_to_unit_string(progress_pixels) unit = @@unit_settings[$ruler_popup_menu.unit] case $ruler_popup_menu.unit when UNIT_PIXELS sprintf("%d %s", progress_pixels, unit.name) when UNIT_PERCENTAGE sprintf("%3.1f %%", 100.0 * progress_pixels.to_f / length.to_f) else sprintf("%3.2f %s", (progress_pixels.to_f / pixels_per_inch) / unit.per_inch, unit.name) end end def on_delete_event Gtk.main_quit true # handled end def length case @orientation when ORIENTATION_LEFT then @canvas.width when ORIENTATION_UP then @canvas.height end end def length=(value) grow(value - length) end def pixels_per_inch case @orientation when ORIENTATION_LEFT then $preferences_window.ppi_horizontal when ORIENTATION_UP then $preferences_window.ppi_vertical end end def redraw @canvas.redraw end def rotate(root_x, root_y, window_x, window_y) case @orientation when ORIENTATION_LEFT # rotate to ORIENTATION_UP @window.window.move_resize(root_x - (@breadth - window_y), root_y - window_x, @breadth, length) @orientation = ORIENTATION_UP when ORIENTATION_UP @window.window.move_resize(root_x - window_y, root_y - (@breadth - window_x), length, @breadth) @orientation = ORIENTATION_LEFT end configure_orientation end ################################################################### # Settings ################################################################### def read_settings(settings) move( settings['ruler_x'], settings['ruler_y'] ) if settings['ruler_x'] self.length = (settings['ruler_length'] || DEFAULT_RULER_LENGTH) end def write_settings(settings) settings['ruler_x'], settings['ruler_y'] = position settings['ruler_length'] = length end private def configure_ppi @edge_size = 8 @breadth = 35 # together with 'length', these are the two dimensions, independent of ruler rotation (whereas width=x, height=y) end def distance_from_zero(x, y) case @orientation when ORIENTATION_LEFT then x when ORIENTATION_UP then y end end def configure_orientation # make changes necessary for a new orientation case @orientation when ORIENTATION_LEFT @menu_box = Gdk::Rectangle.new(MENU_BOX_RELIEF, (@breadth / 2) - (MENU_BOX_HEIGHT / 2), MENU_BOX_WIDTH, MENU_BOX_HEIGHT) @near_edge, @far_edge = Gdk::Window::EDGE_WEST, Gdk::Window::EDGE_EAST when ORIENTATION_UP @menu_box = Gdk::Rectangle.new(MENU_BOX_RELIEF, (@breadth / 2) - (MENU_BOX_HEIGHT / 2), MENU_BOX_WIDTH, MENU_BOX_HEIGHT) @near_edge, @far_edge = Gdk::Window::EDGE_NORTH, Gdk::Window::EDGE_SOUTH end @window.set_size_request(@breadth, @breadth) end def mouse_is_in_window=(value) @mouse_is_in_window = value redraw end def grow(amount) # can be negative case @orientation when ORIENTATION_LEFT then resize(@canvas.width + amount, @canvas.height) when ORIENTATION_UP then resize(@canvas.width, @canvas.height + amount) end end def prepare_rotated_canvas(cr) case @orientation when ORIENTATION_UP cr.translate(@breadth, 0) cr.rotate(Math::PI / 2) end end ################################################################### # Drawing ################################################################### def draw(cr) prepare_rotated_canvas(cr) pangolayout = cr.create_pango_layout.set_font_from_string($preferences_window.font) # Background cr.set_source_color($preferences_window.background_color) cr.rectangle(0, 0, length, @breadth) cr.fill # Foreground lines cr.set_source_color($preferences_window.foreground_color) cr.set_line_width(line_width_for_ppi) unit = @@unit_settings[$ruler_popup_menu.unit] # Two unit types require special code, as they are unrelated to inches case $ruler_popup_menu.unit when UNIT_PIXELS pixels_per_tick = 2 units_per_pattern_repetition = unit.units_per_pattern_repetition when UNIT_PERCENTAGE # Change how many ticks we show, based on length of ruler ticks, units_per_pattern_repetition = if length > 600 then [20, 10] elsif length > 260 then [10, 20] else [4, 50] end pixels_per_tick = length.to_f / ticks.to_f else pixels_per_tick = (pixels_per_inch * unit.per_inch * unit.units_per_pattern_repetition) / unit.tick_pattern.size units_per_pattern_repetition = unit.units_per_pattern_repetition end # Loop, drawing ticks (top and bottom) and labels repetitions, tick_index = 0, 0 loop(pixels_per_tick, length + OVERDRAW, pixels_per_tick) { |x| x = x.floor + 0.5 # Cairo likes lines in the 'center' of pixels tick_size = @@tick_sizes[ unit.tick_pattern[tick_index, 1].to_s ] # Top tick cr.move_to(x, 1.0) # don't double-draw border pixel here... cr.line_to(x, tick_size) # Bottom tick cr.move_to(x, @breadth - tick_size) cr.line_to(x, @breadth - 1.0) # ...not here either cr.stroke # Tick labels (once after each time we complete a tick_pattern) if tick_index == unit.tick_pattern.size - 1 repetitions += 1 pangolayout.text = sprintf("%d %s", repetitions * units_per_pattern_repetition, (repetitions == 1) ? unit.name : '') cr.show_pango_layout_centered(pangolayout, x, @breadth / 2) # (see addons_gtk.rb) end tick_index = (tick_index + 1) % unit.tick_pattern.size # tick_index repeats eg. 0->7 if there are 8 in the pattern } draw_mouse_tracker(cr) if @enable_mouse_tracking draw_menu_button(cr) if @mouse_is_in_window # Outline the ruler cr.rectangle(0.5, 0.5, length - 1.0, @breadth - 1.0) cr.stroke end def draw_mouse_tracker(cr) __window__unused__, mouse_x, mouse_y, key_mask = Gdk::Window.default_root_window.pointer tooltip_pango_layout = cr.create_pango_layout.set_font_from_string($preferences_window.font) window_x, window_y = position # Determine what measurement to show user progress_pixels = distance_from_zero((mouse_x - window_x), (mouse_y - window_y)) progress_pixels = progress_pixels.clamp(0, length) tooltip_pango_layout.text = progress_pixels_to_unit_string(progress_pixels) tooltip_width, tooltip_height = tooltip_pango_layout.pixel_size case @orientation when ORIENTATION_LEFT tooltip_x = (mouse_x - window_x - (tooltip_width / 2.0)).clamp(@menu_box.x + @menu_box.width + @menu_box.x, (length - tooltip_width)) tooltip_y = (@breadth - tooltip_height) / 2.0 when ORIENTATION_UP tooltip_x = (mouse_y - window_y - (tooltip_width / 2.0)).clamp(@menu_box.x + @menu_box.width + @menu_box.x, (length - tooltip_width)) tooltip_y = (@breadth - tooltip_height) / 2.0 end # Cairo draws crisp lines when coordinates end in .5 (it's already either .0 or .5 due to division above) tooltip_x += 0.5 if (tooltip_x == tooltip_x.to_i) tooltip_y += 0.5 if (tooltip_y == tooltip_y.to_i) # Draw a line crossing the ruler at the measurement spot cr.set_source_color($preferences_window.foreground_color) cr.move_to(progress_pixels + 0.5, 0) cr.line_to(progress_pixels + 0.5, @breadth) cr.stroke # Fill a box with the background color cr.set_source_color($preferences_window.background_color) cr.rectangle(tooltip_x - 2.0, tooltip_y - 2.0, tooltip_width + 4.0, tooltip_height + 4.0) cr.fill_preserve # (preserve so we can outline it below) # Draw outline around the box cr.set_source_color($preferences_window.foreground_color) cr.stroke # Draw measurement text cr.move_to(tooltip_x, tooltip_y) cr.show_pango_layout(tooltip_pango_layout) end def draw_menu_button(cr) # Outline cr.set_source_color($preferences_window.background_color) cr.rectangle(@menu_box.x + 0.5, @menu_box.y + 0.5, @menu_box.width, @menu_box.height) cr.fill_preserve # Fill with 'horizontal' lines cr.set_source_color($preferences_window.foreground_color) loop(@menu_box.y + 2.5, @menu_box.y + @menu_box.height + -1.5, 2) { |y| cr.move_to(@menu_box.x + 2.0, y) cr.line_to(@menu_box.x + @menu_box.width - 1, y) } cr.stroke end ################################################################### # GTK Signal Handlers ################################################################### def on_button_press_event(obj, event) case event.event_type when Gdk::Event::BUTTON_PRESS # single-clicks case event.button when MOUSE_BUTTON_1 # popup, resize, or drag if menu_hit(event.x, event.y) $ruler_popup_menu.popup(event.x_root, event.y_root, event.x, event.y, event.time) elsif edge = edge_hit(event.x, event.y) begin_resize_drag(edge, event.button, event.x_root, event.y_root, event.time) else begin_move_drag(event.button, event.x_root, event.y_root, event.time) end when MOUSE_BUTTON_2 # middle-click = rotate ruler rotate(event.x_root, event.y_root, event.x, event.y) when MOUSE_BUTTON_3 # right-click anywhere = popup menu $ruler_popup_menu.popup(event.x_root, event.y_root, event.x, event.y, event.time) end when Gdk::Event::BUTTON2_PRESS # double-click = preferences window $preferences_window.present end end def on_motion_notify_event(obj, event) if menu_hit(event.x, event.y) @window.window.cursor = Gdk::Cursor.new(Gdk::Cursor::HAND2) elsif edge = edge_hit(event.x, event.y) lookup = { Gdk::Window::EDGE_NORTH => Gdk::Cursor::TOP_SIDE, Gdk::Window::EDGE_SOUTH => Gdk::Cursor::BOTTOM_SIDE, Gdk::Window::EDGE_WEST => Gdk::Cursor::LEFT_SIDE, Gdk::Window::EDGE_EAST => Gdk::Cursor::RIGHT_SIDE} @window.window.cursor = Gdk::Cursor.new(lookup[edge]) else @window.window.cursor = Gdk::Cursor.new(Gdk::Cursor::FLEUR) end end def on_key_press_event(obj, event) move_distance = (event.state.shift_mask?) ? MOVE_LARGE : MOVE_SMALL grow_amount = (event.state.shift_mask?) ? GROW_LARGE : GROW_SMALL if event.state.mod1_mask? # alt key case event.keyval when Gdk::Keyval::GDK_Right, Gdk::Keyval::GDK_Down then grow(grow_amount) when Gdk::Keyval::GDK_Left, Gdk::Keyval::GDK_Up then grow(-grow_amount) # shrink ;) else return false # not handled end else case event.keyval # quick-change unit measures when Gdk::Keyval::GDK_1 then $ruler_popup_menu.unit = UNIT_PIXELS when Gdk::Keyval::GDK_2 then $ruler_popup_menu.unit = UNIT_CENTIMETERS when Gdk::Keyval::GDK_3 then $ruler_popup_menu.unit = UNIT_INCHES when Gdk::Keyval::GDK_4 then $ruler_popup_menu.unit = UNIT_PICAS when Gdk::Keyval::GDK_5 then $ruler_popup_menu.unit = UNIT_POINTS when Gdk::Keyval::GDK_6 then $ruler_popup_menu.unit = UNIT_PERCENTAGE # move ruler by keyboard when Gdk::Keyval::GDK_Left then offset(-move_distance, 0) when Gdk::Keyval::GDK_Right then offset( move_distance, 0) when Gdk::Keyval::GDK_Up then offset(0, -move_distance) when Gdk::Keyval::GDK_Down then offset(0, move_distance) # hide ruler when Gdk::Keyval::GDK_Escape then Gtk.main_quit # show menu via keyboard when Gdk::Keyval::GDK_Return # popup menu (provide "click point" in case user chooses 'rotate') offset_x, offset_y = @breadth / 2, @breadth / 2 # provides a visually appealing rotation $ruler_popup_menu.popup(@window.position[0] + offset_x, @window.position[1] + offset_y, offset_x, offset_y, event.time) else return false # not handled end end return true # handled end ################################################################### # Hit detection (menu button, edges) ################################################################### def edge_hit(x, y) offset = distance_from_zero(x, y) if offset < @edge_size return @near_edge elsif offset > (length - @edge_size) return @far_edge else return nil end end def menu_hit(x, y) @menu_box.grow(2).contains(x,y) # grow a little to be easier to click on end ################################################################### # Utils ################################################################### def line_width_for_ppi 1.0 # TODO end def offset(x, y) move(position[0] + x, position[1] + y) end end # Local Variables: # tab-width: 2 # End: screenruler-0.960+bzr41/preferences_window.rb0000664000175000017500000001077311707631463020600 0ustar rainctrainct ############################################################################### # Copyright 2011 Ian McIntosh # # 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 Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ############################################################################### require 'glade_window' class PreferencesWindow < GladeWindow DEFAULT_FOREGROUND_COLOR = '#202020' DEFAULT_BACKGROUND_COLOR = '#E6E36B' DEFAULT_OPACITY = 0.85 MM_TO_INCHES = (1.0 / 25.4) # 1 inch = 25.4 millimeters def initialize super('preferences_window', :widgets => [:foreground_color_button, :background_color_button, :text_fontbutton, :system_ppi_setting_label, :use_custom_ppi_radiobutton, :custom_ppi_settings_container, :ppi_horizontal_spinbutton, :ppi_vertical_spinbutton]) # GTK signal handlers @window.signal_connect('delete_event') { hide } @system_ppi_setting_label.markup = sprintf("(%d x %d)", system_ppi_horizontal, system_ppi_vertical) on_key_press(Gdk::Keyval::GDK_Escape) { hide } end def foreground_color ; return @foreground_color_button.color ; end def background_color ; return @background_color_button.color ; end def font ; return @text_fontbutton.font_name ; end def watch_mouse? ; return @watch_mouse_checkbutton.active? ; end def watch_mouse=(value) ; @watch_mouse_checkbutton.active = value ; end attr_reader :opacity def ppi_horizontal if @use_custom_ppi_radiobutton.active? @ppi_horizontal_spinbutton.value else system_ppi_horizontal end end def ppi_vertical if @use_custom_ppi_radiobutton.active? @ppi_vertical_spinbutton.value else system_ppi_vertical end end def system_ppi_horizontal ; Gdk::Screen.default.width / (Gdk::Screen.default.width_mm * MM_TO_INCHES) ; end def system_ppi_vertical ; Gdk::Screen.default.width / (Gdk::Screen.default.width_mm * MM_TO_INCHES) ; end ################################################################### # Settings ################################################################### def read_settings(settings) @foreground_color_button.color = Gdk::Color.parse(settings['foreground_color'] || DEFAULT_FOREGROUND_COLOR) @background_color_button.color = Gdk::Color.parse(settings['background_color'] || DEFAULT_BACKGROUND_COLOR) @text_fontbutton.font_name = settings['font'] if settings['font'] @opacity = settings['opacity'] || DEFAULT_OPACITY @ppi_horizontal_spinbutton.value = settings['horizontal_pixels_per_inch'] || system_ppi_horizontal @ppi_vertical_spinbutton.value = settings['vertical_pixels_per_inch'] || system_ppi_vertical @use_custom_ppi_radiobutton.active = (settings['use_custom_pixels_per_inch'] || false) end def write_settings(settings) settings['foreground_color'] = self.foreground_color.to_hex settings['background_color'] = self.background_color.to_hex settings['font'] = self.font settings['opacity'] = @opacity settings['use_custom_pixels_per_inch'] = @use_custom_ppi_radiobutton.active? settings['horizontal_pixels_per_inch'] = @ppi_horizontal_spinbutton.value settings['vertical_pixels_per_inch'] = @ppi_vertical_spinbutton.value end def present super ; super ; super # TODO: remove this hack when it's no longer needed to prevent window from popping up UNDER the ruler (on Ubuntu 8.04) end private ################################################################### # Signal Handlers ################################################################### def on_style_changed $ruler_window.redraw end def on_ppi_vertical_spinbutton_changed on_style_changed end def on_ppi_horizontal_spinbutton_changed on_style_changed end def on_use_custom_ppi_radiobutton_toggled @custom_ppi_settings_container.sensitive = @use_custom_ppi_radiobutton.active? @system_ppi_setting_label.sensitive = !@use_custom_ppi_radiobutton.active? on_style_changed end def on_close_clicked hide end end # Local Variables: # tab-width: 2 # End: screenruler-0.960+bzr41/COPYING0000664000175000017500000003542211707631463015414 0ustar rainctrainct GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS screenruler-0.960+bzr41/ruler_popup_menu.rb0000664000175000017500000000711211707631463020301 0ustar rainctrainct ############################################################################### # Copyright 2011 Ian McIntosh # # 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 Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ############################################################################### require 'glade_window' class RulerPopupMenu < GladeWindow def initialize super('ruler_popup_menu', :widgets => [:keep_above_menuitem, :track_mouse_menuitem, :unit_pixels_menuitem, :unit_centimeters_menuitem, :unit_inches_menuitem, :unit_picas_menuitem, :unit_points_menuitem, :unit_percentage_menuitem]) @unit_menuitems = { UNIT_PIXELS => @unit_pixels_menuitem, UNIT_CENTIMETERS => @unit_centimeters_menuitem, UNIT_INCHES => @unit_inches_menuitem, UNIT_PICAS => @unit_picas_menuitem, UNIT_POINTS => @unit_points_menuitem, UNIT_PERCENTAGE => @unit_percentage_menuitem }.freeze end def track_mouse=(val) @track_mouse_menuitem.active = val end def track_mouse? return @track_mouse_menuitem.active? end def keep_above=(val) @keep_above_menuitem.active = val end def keep_above? return @keep_above_menuitem.active? end def popup(root_x, root_y, x, y, time) @click_properties = [root_x, root_y, x, y, time] # save for rotation point super(nil, nil, MOUSE_BUTTON_3, time) end def unit @unit_menuitems.each_pair { | unit, menuitem | return unit if menuitem.active? } end def unit=(value) @unit_menuitems[value].active = true end ################################################################### # Settings ################################################################### def read_settings(settings) self.track_mouse = (settings['track_mouse'] || false) self.keep_above = (settings['keep_above'] || false) self.unit = (settings['metric'] || UNIT_PIXELS) end def write_settings(settings) settings['track_mouse'] = track_mouse? settings['metric'] = unit settings['keep_above'] = keep_above? end private ################################################################### # Signal Handlers for menu items ################################################################### def on_preferences_activate $preferences_window.present end def on_track_mouse_activate $ruler_window.show_measurement_tooltip = track_mouse? end def on_keep_above_activate $ruler_window.keep_above = keep_above? $preferences_window.keep_above = keep_above? # confusing if preferences won't go above ruler end def on_rotate_activate $ruler_window.rotate(*(@click_properties[0..3])) # send first 4 items end def on_style_changed $ruler_window.redraw end def on_help_menuitem_activate $help_window.present end def on_about_activate Gtk::AboutDialog.show(nil, :logo => APP_ICON_LIST.last, :program_name => APP_NAME, :copyright => APP_COPYRIGHT, :version => APP_VERSION, :authors => APP_AUTHORS, :artists => APP_ARTISTS) end def on_quit_activate Gtk.main_quit end end # Local Variables: # tab-width: 2 # End: screenruler-0.960+bzr41/screenruler.rb0000775000175000017500000000702611707631463017241 0ustar rainctrainct#!/usr/bin/env ruby #coding: utf-8 ############################################################################### # Copyright 2011 Ian McIntosh # # 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 Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ############################################################################### Dir.chdir(File.dirname(File.expand_path(File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__))) # So that this file can be run from anywhere $LOAD_PATH << './utils' require 'gettext' # Internationalization Support include GetText bindtextdomain("screenruler", :path => "locale") ################################################################### # Constants ################################################################### UNIT_PIXELS, UNIT_CENTIMETERS, UNIT_INCHES, UNIT_PICAS, UNIT_POINTS, UNIT_PERCENTAGE = (0..5).to_a UNIT_LAST = UNIT_PERCENTAGE APP_NAME = _('Screen Ruler') APP_COPYRIGHT = "Copyright (c) #{Time.now.year} Ian McIntosh" APP_AUTHORS = ['Ian McIntosh '] APP_ARTISTS = ['János Horváth '] APP_VERSION = '0.9.6' APP_LOGO_FILENAME = 'screenruler-logo.png' SETTINGS_SUBDIRECTORY_NAME = 'screenruler' SETTINGS_FILE_NAME = 'settings.yml' ################################################################### # Includes ################################################################### puts _('Loading libraries...') require 'addons_ruby' # for multi-file 'require' require 'gtk2', 'settings', 'addons_gtk', 'ruler_window', 'preferences_window', 'help_window' ################################################################### # Main ################################################################### Gtk.init APP_ICON_LIST = ['screenruler-icon-16x16.png', 'screenruler-icon-32x32.png', 'screenruler-icon-64x64.png'].collect { |filename| Gdk::Pixbuf.new(filename) } # # Load Settings # settings_directory = File.join(GLib.user_config_dir, SETTINGS_SUBDIRECTORY_NAME) Dir.mkdir(GLib.user_config_dir) rescue nil ; Dir.mkdir(settings_directory) rescue nil settings_file_path = File.join(settings_directory, SETTINGS_FILE_NAME) settings = Settings.new.load(settings_file_path) # # Startup # puts _('Creating windows...') $preferences_window = PreferencesWindow.new $ruler_window = RulerWindow.new $ruler_popup_menu = RulerPopupMenu.new $help_window = HelpWindow.new puts _('Reading settings...') $preferences_window.read_settings(settings) $ruler_window.read_settings(settings) $ruler_popup_menu.read_settings(settings) puts _('Presenting ruler...') $ruler_window.present begin Gtk.main ensure puts _('Shutting down...') [$ruler_window, $ruler_popup_menu, $preferences_window].each { |win| win.hide } # feels snappy [$ruler_window, $ruler_popup_menu, $preferences_window].each { |win| win.write_settings(settings) } settings.save(settings_file_path) end # Local Variables: # tab-width: 2 # End: screenruler-0.960+bzr41/utils/0000775000175000017500000000000011707631463015513 5ustar rainctrainctscreenruler-0.960+bzr41/utils/addons_ruby.rb0000664000175000017500000000352011707631463020351 0ustar rainctrainct ############################################################################### # Copyright 2008 Ian McIntosh # # 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 Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ############################################################################### # extend/simplify/standardize some Ruby objects class String def limit(max_length, indicator='...') return self[0, max_length] + indicator if length > max_length return self end end class Dir def each_matching(pattern) # patterns like '*.png' each { |filename| yield filename if File.fnmatch(pattern, filename) } end end class Numeric def clamp(low, high) return low if self <= low return high if self >= high return self end end class Fixnum def within?(low, high) return (to_i >= low and to_i <= high) end end class Object def to_a return self if is_a?(Array) return [self] end end module Kernel # a new 'require' supporting multiple files alias_method :orig_require, :require def require(*list) list.each { |file| orig_require(file) } end def loop(from, to, step=1) i = from while i <= to yield i i += step end end end # Local Variables: # tab-width: 2 # End: screenruler-0.960+bzr41/utils/unique_timeout.rb0000664000175000017500000000262711707631463021123 0ustar rainctrainct ############################################################################### # Copyright 2006 Ian McIntosh # # 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 Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ############################################################################### # UniqueTimeoutCallback will call the provided block ONCE after the given delay. # If 'set' is called again, it will cancel the previous callback. class UniqueTimeout def initialize(time_in_millisecond, &proc) @time = time_in_millisecond.to_f @proc = proc end def start stop @callback_id = Gtk.timeout_add(@time) { ret = @proc.call ; true } # true = don't call again end def stop Gtk.timeout_remove(@callback_id) if @callback_id @callback_id = nil end end screenruler-0.960+bzr41/utils/addons_gtk.rb0000664000175000017500000000574211707631463020165 0ustar rainctrainct ############################################################################### # Copyright 2008 Ian McIntosh # # 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 Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ############################################################################### # extend/simplify/standardize some GTK objects ################################# # GTK classes ################################# class Gtk::Window def toggle_visibility if active? # is this window the current top level window on the current desktop? hide else present # show / move to current desktop / bring to top end end end class Gdk::Rectangle def grow(m) return Gdk::Rectangle.new(self.x - m, self.y - m, self.width + m*2, self.height + m*2) end def shrink(m) grow(-m) end def contains(x, y) return false if x < self.x return false if y < self.y return false if x > self.x + self.width return false if y > self.y + self.height return true end def center return [self.x + (self.width/2), self.y + (self.height/2)] end end class Gdk::Color def to_hex # use Gdk::Color.parse to parse sprintf('#%02x%02x%02x', red / 257, green / 257, blue / 257) # because 255 * 257 == 65535 end end ################################# # other ################################# class Cairo::Context def show_pango_layout_centered(pangolayout, x, y) w,h = pangolayout.pixel_size move_to(x - (w / 2), y - (h / 2)) show_pango_layout(pangolayout) end end class Pango::Layout def set_font_from_string(str) set_font_description(Pango::FontDescription.new(str)) end end class Gtk::Widget def on_key_press_event(event) modifiers = nil # TODO: extract from event ? if @key_press_handlers and @key_press_handlers[modifiers] and @key_press_handlers[modifiers][event.keyval] @key_press_handlers[modifiers][event.keyval].each { |proc| proc.call(event) } true else false end end def on_key_press(keyval, modifiers = nil, &proc) if @key_press_handlers.nil? # On first use of on_key_press() setup GLib signal handler self.signal_connect('key-press-event') { |obj, event| on_key_press_event(event) } @key_press_handlers = {} end @key_press_handlers[modifiers] ||= {} @key_press_handlers[modifiers][keyval] ||= [] @key_press_handlers[modifiers][keyval] << proc end end # Local Variables: # tab-width: 2 # End: screenruler-0.960+bzr41/utils/settings.rb0000664000175000017500000000150611707631463017702 0ustar rainctrainctrequire 'yaml' class Settings def initialize @settings = {} @setting_callbacks = {} end def on_change(key, &proc) @setting_callbacks[key] ||= [] @setting_callbacks[key] << proc end def load(path) File.open(path, 'r') { |file| load_settings_from_file(file) } rescue nil self end def save(path) File.open(path, 'w') { |file| save_settings_to_file(file) } rescue nil self end def [](key) @settings[key] end def []=(key, value) return if (@settings[key] && @settings[key] == value) @settings[key] = value @setting_callbacks[key].each { |proc| proc.call(value) } if @setting_callbacks[key] end private def load_settings_from_file(file) settings = YAML.load(file) @settings = settings if settings.is_a? Hash end def save_settings_to_file(file) YAML.dump(@settings, file) end end screenruler-0.960+bzr41/utils/canvas.rb0000664000175000017500000000427311707631463017321 0ustar rainctrainct ############################################################################### # Copyright 2008 Ian McIntosh # # 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 Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ############################################################################### require 'pathname' require 'cairo' require 'delegate' class Canvas < DelegateClass(Gdk::Pixmap) # so we can use Pixmap methods on our Canvas object attr_reader :widget, :height, :width def initialize @widget = Gtk::DrawingArea.new.show # widget to draw on to @widget.double_buffered = false @redraw_needed = true # GTK Signal Handlers @widget.signal_connect('configure-event') { |obj, event| # Widget changed size @width, @height = event.width, event.height # save it @buffer = Gdk::Pixmap.new(@widget.window, @width, @height, @widget.window.depth) __setobj__(@buffer) # set a new object to delegate to redraw } @widget.signal_connect('expose-event') { |obj, event| # Widget changed visibility @gc ||= @widget.style.fg_gc(Gtk::STATE_NORMAL) @draw_proc.call(@buffer.create_cairo_context) if @redraw_needed @redraw_needed = false a = event.area ; @widget.window.draw_drawable(@gc, @buffer, a.x, a.y, a.x, a.y, a.width, a.height) } super(nil) # 'nil' is the object to delegate to. this is set later in 'configure-event' callback. end def set_draw_proc(&proc) @draw_proc = proc self end def redraw @redraw_needed = true @widget.queue_draw_area(0,0, @width, @height) end end # Local Variables: # tab-width: 2 # End: screenruler-0.960+bzr41/utils/glade_window.rb0000664000175000017500000000346011707631463020506 0ustar rainctrainct ############################################################################### # Copyright 2011 Ian McIntosh # # 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 Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ############################################################################### require 'delegate' class GladeWindow < DelegateClass(Gtk::Window) # Useful constants MOUSE_BUTTON_1, MOUSE_BUTTON_2, MOUSE_BUTTON_3 = (1..3).to_a def initialize(root_widget_name, options = {}) file_name = sprintf("%s.glade", root_widget_name) instance_variable_names = options[:widgets] || [] @builder = Gtk::Builder.new.add_from_file(file_name) # create instance variables out of created widgets instance_variable_names.each { |name| instance_variable_set('@' + name.to_s, @builder.get_object(name.to_s)) } # hookup signal handlers @builder.connect_signals { |handler_name| method(handler_name) } # in the class, we will refer to the GtkWindow as @window when referencing variables @window = @builder.get_object(root_widget_name) @window.realize super(@window) # ...as required by delegation end end # Local Variables: # tab-width: 2 # End: screenruler-0.960+bzr41/ruler_window.glade0000664000175000017500000000213711707631463020074 0ustar rainctrainct False GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK Screen Ruler center 400 36 dialog False False screenruler-0.960+bzr41/screenruler.pot0000664000175000017500000000772111707631463017437 0ustar rainctrainct# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2011-08-18 00:31-0700\n" "PO-Revision-Date: 2011-08-18 00:31-0700\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" #: ruler_window.rb:39 msgid "in" msgstr "" #: ruler_window.rb:40 msgid "cm" msgstr "" #: ruler_window.rb:41 msgid "pc" msgstr "" #: ruler_window.rb:42 msgid "pt" msgstr "" #: ruler_window.rb:43 msgid "px" msgstr "" #: ruler_window.rb:44 msgid "%" msgstr "" #: screenruler.rb:35 screenruler.glade:987 msgid "Screen Ruler" msgstr "" #: screenruler.rb:47 msgid "Loading libraries..." msgstr "" #: screenruler.rb:59 msgid "Connecting to GConf..." msgstr "" #: screenruler.rb:63 msgid "Creating windows..." msgstr "" #: screenruler.rb:69 msgid "Reading settings..." msgstr "" #: screenruler.rb:74 msgid "Presenting ruler..." msgstr "" #: screenruler.rb:80 msgid "Shutting down..." msgstr "" #: screenruler.glade:7 msgid "Screen Ruler Help" msgstr "" #: screenruler.glade:44 msgid "Keyboard Tips" msgstr "" #: screenruler.glade:61 msgid "Arrow Keys move the ruler by 1 pixel." msgstr "" #: screenruler.glade:80 msgid "Alt + Arrow Keys resize the ruler." msgstr "" #: screenruler.glade:99 msgid "Hold Shift to move or resize faster." msgstr "" #: screenruler.glade:118 msgid "1, 2, 3, 4, 5, and 6 keys set ruler metric." msgstr "" #: screenruler.glade:137 msgid "Enter key to see menu." msgstr "" #: screenruler.glade:164 msgid "Mouse Tips" msgstr "" #: screenruler.glade:181 msgid "Drag the ruler around your screen." msgstr "" #: screenruler.glade:200 msgid "Drag ruler ends to resize the ruler." msgstr "" #: screenruler.glade:219 msgid "Left-Click on menu button to see menu." msgstr "" #: screenruler.glade:238 msgid "Right-Click to see menu." msgstr "" #: screenruler.glade:257 msgid "Double-Click to see Settings window." msgstr "" #: screenruler.glade:276 msgid "Middle-Click to rotate the ruler." msgstr "" #: screenruler.glade:372 msgid "Settings" msgstr "" #: screenruler.glade:416 msgid "Background Color" msgstr "" #: screenruler.glade:434 msgid "Ticks and Numbers Color" msgstr "" #: screenruler.glade:454 msgid "_Font:" msgstr "" #: screenruler.glade:492 msgid "_Numbers and lines:" msgstr "" #: screenruler.glade:505 msgid "_Background:" msgstr "" #: screenruler.glade:523 msgid "Appearance" msgstr "" #: screenruler.glade:574 msgid "_System Settings" msgstr "" #: screenruler.glade:607 msgid "_Custom Settings" msgstr "" #: screenruler.glade:690 msgid "_Horizontal pixels per inch:" msgstr "" #: screenruler.glade:703 msgid "_Vertical pixels per inch:" msgstr "" #: screenruler.glade:735 msgid "Screen Pixels per Inch" msgstr "" #: screenruler.glade:802 msgid "_Settings" msgstr "" #: screenruler.glade:830 msgid "On _Top" msgstr "" #: screenruler.glade:840 msgid "Track _Mouse" msgstr "" #: screenruler.glade:856 msgid "_Rotate" msgstr "" #: screenruler.glade:872 msgid "_1. Pixels" msgstr "" #: screenruler.glade:882 msgid "_2. Centimeters" msgstr "" #: screenruler.glade:893 msgid "_3. Inches" msgstr "" #: screenruler.glade:904 msgid "_4. Picas" msgstr "" #: screenruler.glade:915 msgid "_5. Points" msgstr "" #: screenruler.glade:926 msgid "_6. Percentage" msgstr "" #: screenruler.glade:943 msgid "_Help" msgstr "" #: screenruler.glade:953 msgid "_About" msgstr "" #: screenruler.glade:966 msgid "_Quit" msgstr "" screenruler-0.960+bzr41/screenruler-icon-16x16.png0000664000175000017500000000060211707631463021121 0ustar rainctrainctPNG  IHDRasRGBbKGD pHYs B(xtIME ).I*qIDAT8Œ1N@D@H(W-r8 }"SVEт" lڱŽEFTYdž\x 0(Q>U1f֮36{! cvMY1U q.*`\(mA^bFp%/f (=FeѨwQzhsF>"f olҾrzqxfBw[}fw0 ),YRAsPIENDB`screenruler-0.960+bzr41/help_window.glade0000664000175000017500000004176111707631463017701 0ustar rainctrainct False Screen Ruler Help False center-always True False 8 True False 12 True False 0 2 gtk-help 6 False True 0 True False True False 0 <big><b>Keyboard Tips</b></big> True True True 0 True False 0 0 8 4 <b><i>Arrow Keys</i></b> move the ruler by 1 pixel. True True True False False 1 True False 0 0 8 4 <b><i>Alt + Arrow Keys</i></b> resize the ruler. True True True False False 2 True False 0 0 8 4 Hold <b><i>Shift</i></b> to move or resize faster. True True True False False 3 True False 0 0 8 4 <b><i>1</i></b>, <b><i>2</i></b>, <b><i>3</i></b>, <b><i>4</i></b>, <b><i>5</i></b>, and <b><i>6</i></b> keys set ruler metric. True True True False False 4 True False 0 0 8 4 <b><i>Enter</i></b> key to see menu. True True True False False 5 True False True True 6 True False 0 <big><b>Mouse Tips</b></big> True True True 7 True False 0 0 8 4 <b><i>Drag</i></b> the ruler around your screen. True True True False False 8 True False 0 0 8 4 <b><i>Drag</i></b> ruler ends to resize the ruler. True True True False False 9 True False 0 0 8 4 <b><i>Left-Click</i></b> on menu button to see menu. True True True False False 10 True False 0 0 8 4 <b><i>Right-Click</i></b> to see menu. True True True False False 11 True False 0 0 8 4 <b><i>Double-Click</i></b> to see Settings window. True True True False False 12 True False 0 0 8 4 <b><i>Middle-Click</i></b> to rotate the ruler. True True True False False 13 True True 1 False False 0 True False end gtk-close True True True False False True False False 0 False True 4 1 screenruler-0.960+bzr41/ruler_popup_menu.glade0000664000175000017500000001717711707631463020766 0ustar rainctrainct False _Settings True False False True False True False True False False On _Top True True False False Track _Mouse True True False True False False _Rotate True True False True False False _1. Pixels True True False False _2. Centimeters True unit_pixels_menuitem True False False _3. Inches True unit_pixels_menuitem True False False _4. Picas True unit_pixels_menuitem True False False _5. Points True unit_pixels_menuitem True False False _6. Percentage True unit_pixels_menuitem True False True False False _Help True True False False _About True True False _Quit True False False True False screenruler-0.960+bzr41/screenruler-icon-64x64.png0000664000175000017500000000132211707631463021127 0ustar rainctrainctPNG  IHDR@@iqsRGBbKGD pHYs B(xtIME )FRIDATx훽@66j**@4D:(8PSAE T\wG$g|sgh7{&o{M"{w!d~P?k[.b~KGH@w D3|OoW7! C 0 0!`p$K0,!S+v囷z_ N ="EL0)ħgH88X:&ߑT@A돀<+@q\=IQyXJ)U Y/9!I^)P.-> 0B{}`&(qq1[g#o2!Vם/. .E\HZSD⹧絋Y9vQ-|3B^;aP:ĥ8狊‹+yd^(x(xE۟|\fH&׶5Ck'䷹fߪGX,SWM7000wLMMBh|Y("os!1TÿIENDB`