Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/console/interface/xo/drwarea.py
blob: b0e598a7951d2e9c3b6fd11d1790b5a397a8e6f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python

# Copyright (C) 2007, Eduardo Silva (edsiper@gmail.com).
#
# 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.
#
# 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

#############################################
# Drawing area tools
#############################################

import gtk
import gtk.gdk

class Drawing_Area_Tools:
    
    height	= 0 
    width	= 0

    margin = 5 # Left and bottom margin

    range_x = []
    range_y = []
    
    def __init__(self, drwarea):
        drwarea_size = drwarea.get_size_request()

        self.width	= drwarea_size[0]
        self.height	= drwarea_size[1]

        # print "width %i" % self.width
        # print "height %i" % self.height
        
        self.range_x = {'from': self.margin+2, 'to': self.width - (self.margin+2)}
        self.range_y = {'from': self.margin+2, 'to': self.height - (self.margin+2)}
                
    def draw_line(self, context, from_x, from_y, to_x, to_y):				
        context.move_to(from_x, from_y)
        context.line_to(to_x, to_y)			
            
    def draw_border_lines(self, context):
        context.set_source_rgb(1, 1, 1)
        self.draw_line(context, self.margin, self.margin, self.margin, self.height - self.margin)
        self.draw_line(context, self.margin, self.height - self.margin - 1, self.width - self.margin, self.height - self.margin - 1)
        context.stroke()
        
    # Draw a grid
    def draw_grid(self, context, init_x, init_y, end_x, end_y):
    
        x_range = (end_x - init_x) + 5
        y_range = (end_y - init_y) + 1
        
        current_y = init_y
        context.set_line_width(0.3)
        
        for y in range(y_range):
            if (y%20) == 0:
                context.move_to(init_x, y)
                context.line_to(end_x, y)
        
        for x in range(x_range):
            if (x%20) == 0:
                context.move_to(x, init_y)
                context.line_to(x, end_y)
        
        context.stroke()