Package dtk :: Package ui :: Module mask

Source Code for Module dtk.ui.mask

  1  #! /usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3   
  4  # Copyright (C) 2011 ~ 2012 Deepin, Inc. 
  5  #               2011 ~ 2012 Wang Yong 
  6  #  
  7  # Author:     Wang Yong <lazycat.manatee@gmail.com> 
  8  # Maintainer: Wang Yong <lazycat.manatee@gmail.com> 
  9  #  
 10  # This program is free software: you can redistribute it and/or modify 
 11  # it under the terms of the GNU General Public License as published by 
 12  # the Free Software Foundation, either version 3 of the License, or 
 13  # any later version. 
 14  #  
 15  # This program is distributed in the hope that it will be useful, 
 16  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 18  # GNU General Public License for more details. 
 19  #  
 20  # You should have received a copy of the GNU General Public License 
 21  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 22   
 23  from iconview import IconView 
 24  from listview import ListView 
 25  from scrolled_window import ScrolledWindow 
 26  from utils import cairo_state, get_match_parent, get_window_shadow_size 
 27  from window import Window 
 28   
29 -def draw_mask(widget, x, y, w, h, render_callback):
30 ''' 31 Draw mask with given render method. 32 33 @param widget: Target widget. 34 @param x: X coordinate of draw area. 35 @param y: Y coordinate of draw area. 36 @param w: Width of draw area. 37 @param h: Height of draw area. 38 @param render_callback: Render callback. 39 ''' 40 if isinstance(widget, Window): 41 draw_window_mask(widget, x, y, w, h, render_callback) 42 elif isinstance(widget, ScrolledWindow): 43 draw_scrolled_window_mask(widget, x, y, w, h, render_callback) 44 elif isinstance(widget, IconView): 45 draw_icon_view_mask(widget, x, y, w, h, render_callback) 46 elif isinstance(widget, ListView): 47 draw_list_view_mask(widget, x, y, w, h, render_callback) 48 else: 49 print "draw_mask: unsupport widget: %s" % (widget)
50
51 -def draw_window_mask(widget, x, y, w, h, render_callback):
52 ''' 53 Draw window mask with given render method. 54 55 @param widget: Target widget. 56 @param x: X coordinate of draw area. 57 @param y: Y coordinate of draw area. 58 @param w: Width of draw area. 59 @param h: Height of draw area. 60 @param render_callback: Render callback. 61 ''' 62 # Init. 63 cr = widget.window.cairo_create() 64 65 with cairo_state(cr): 66 cr.rectangle(x + 1, y, w - 2, 1) 67 cr.rectangle(x, y + 1, w, h - 2) 68 cr.rectangle(x + 1, y + h - 1, w - 2, 1) 69 cr.clip() 70 71 render_callback(cr, x, y, w, h)
72
73 -def draw_scrolled_window_mask(widget, x, y, w, h, render_callback):
74 ''' 75 Draw scrolled window mask with given render method. 76 77 @param widget: Target widget. 78 @param x: X coordinate of draw area. 79 @param y: Y coordinate of draw area. 80 @param w: Width of draw area. 81 @param h: Height of draw area. 82 @param render_callback: Render callback. 83 ''' 84 # Init. 85 cr = widget.window.cairo_create() 86 toplevel = widget.get_toplevel() 87 (offset_x, offset_y) = widget.translate_coordinates(toplevel, 0, 0) 88 89 with cairo_state(cr): 90 cr.rectangle(x, y, w, h) 91 cr.clip() 92 93 render_callback( 94 cr, 95 x - offset_x, 96 y - offset_y, 97 toplevel.allocation.width, 98 toplevel.allocation.height)
99
100 -def draw_icon_view_mask(widget, x, y, w, h, render_callback):
101 ''' 102 Draw icon view mask with given render method. 103 104 @param widget: Target widget. 105 @param x: X coordinate of draw area. 106 @param y: Y coordinate of draw area. 107 @param w: Width of draw area. 108 @param h: Height of draw area. 109 @param render_callback: Render callback. 110 ''' 111 cr = widget.window.cairo_create() 112 viewport = get_match_parent(widget, ["Viewport"]) 113 toplevel = widget.get_toplevel() 114 (offset_x, offset_y) = viewport.translate_coordinates(toplevel, 0, 0) 115 (shadow_x, shadow_y) = get_window_shadow_size(toplevel) 116 117 with cairo_state(cr): 118 cr.rectangle(x, y, w, h) 119 cr.clip() 120 121 render_callback( 122 cr, 123 x - offset_x + shadow_x, 124 y - offset_y + shadow_y, 125 toplevel.allocation.width, 126 toplevel.allocation.height)
127
128 -def draw_list_view_mask(widget, x, y, w, h, render_callback):
129 ''' 130 Draw list view mask with given render method. 131 132 @param widget: Target widget. 133 @param x: X coordinate of draw area. 134 @param y: Y coordinate of draw area. 135 @param w: Width of draw area. 136 @param h: Height of draw area. 137 @param render_callback: Render callback. 138 ''' 139 cr = widget.window.cairo_create() 140 viewport = get_match_parent(widget, ["Viewport"]) 141 toplevel = widget.get_toplevel() 142 (offset_x, offset_y) = viewport.translate_coordinates(toplevel, 0, 0) 143 (shadow_x, shadow_y) = get_window_shadow_size(toplevel) 144 145 with cairo_state(cr): 146 cr.rectangle(x, y, w, h) 147 cr.clip() 148 149 render_callback( 150 cr, 151 x - offset_x + shadow_x, 152 y - offset_y + shadow_y, 153 toplevel.allocation.width, 154 toplevel.allocation.height)
155