Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/linesegmentoriginobject.py
blob: e7231a7805b565acc7e256917bec733bb657ee4a (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Copyright 2008 by Peter Moxhay and Wade Brainerd.  
# This file is part of Math.
#
# Math 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 3 of the License, or
# (at your option) any later version.
# 
# Math 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 Math.  If not, see <http://www.gnu.org/licenses/>.
from objectarea import Object
from vector import Vector

import gtk
from droporiginobject import DropOriginObject
from linesegmentobject import LineSegmentObject

class LineSegmentOriginObject(DropOriginObject):
    """Rectangular area that is a source of draggable line segments."""

    def __init__(self, pos, container, drop_targets):
        DropOriginObject.__init__(self, pos,  Vector(80, 320), container)
        
        self.drop_targets = drop_targets
        
        #print "LineSegmentOriginObject: creating LineSegmentObject 1 with len(self.drop_targets) = ",len(self.drop_targets)
        self.line1 = LineSegmentObject(Vector(40, 10), 100, self.drop_targets, self.container)
        self.line1.drop_origin = self
        
        #print "LineSegmentOriginObject: creating LineSegmentObject 2 with len(self.drop_targets) = ",len(self.drop_targets)
        self.line2 = LineSegmentObject(Vector(40, 110), 200, self.drop_targets, self.container)
        self.line2.drop_origin = self
        
        self.line1.drag_type = None
        self.line1.selected = False
        self.line1.selectable = True
        self.line1.dragged = False
        self.line1.draggable = True

        self.line2.drag_type = None
        self.line2.selected = False
        self.line2.selectable = True
        self.line2.dragged = False
        self.line2.draggable = True
        
        self.add_object(self.line1)
        self.add_object(self.line2)
        
        self.background_visible = True
        
    def reset(self):
        self.line1.move(self.pos + Vector(40, 10))
        self.line2.move(self.pos + Vector(40, 110))
        
        self.line1.drag_type = None
        self.line1.selectable = True
        self.line1.dragged = False
        self.line1.draggable = True
        self.line1.moving_by_key_press = False

        self.line2.drag_type = None
        self.line2.selectable = True
        self.line2.dragged = False
        self.line2.draggable = True
        self.line2.moving_by_key_press = False
        
        # Adjust tabbing order.
        if self.container:
            #self.container.select_object(self.line1)
            self.container.adjust_tab_order()
        
    #def adjust_tab_order(self):
    #    if self.container:
    #        self.container.remove_object(self.line1)
    #        self.container.remove_object(self.line2)
    #        self.container.add_object(self.line1)
    #        self.container.add_object(self.line2)
    #        
    def remove_contents(self): 
        self.line1.drag_type = None
        self.line1.selected = False
        self.line1.selectable = False
        self.line1.dragged = False
        self.line1.draggable = False

        self.line2.drag_type = None
        self.line2.selected = False
        self.line2.selectable = False
        self.line2.dragged = False
        self.line2.draggable = False
        
        self.line1.move(Vector(10000, 10000))
        self.line2.move(Vector(10000, 10000))
        
        self.remove_object(self.line1)
        self.remove_object(self.line2)
        
    def get_bounds(self):
        return self.pos, self.pos + self.size
    
    def select_primary_object(self):
        #print "SELECT PRIMARY OBJECT!"
        self.container.select_object(self.line1)
        
    def draw_background(self, cr):
        if not self.background_visible:
            return
        
        shift_x = -500
        shift_y = 250
        
        if self.container.problem_type == 'amount':
            self.pos1 = Vector (950 + shift_x, 150 + shift_y)
            self.pos2 = Vector (950 + shift_x, 250 + shift_y)
        else:
            self.pos1 = Vector (950, 150)
            self.pos2 = Vector (950, 250)

        self.length = 100
        self.line_segment_length = 100
        
        cr.set_source_rgb(0, 0, 0)

        cr.move_to(self.pos1.x - 25, self.pos1.y + self.length - self.line_segment_length)
        cr.line_to(self.pos1.x + 25, self.pos1.y + self.length - self.line_segment_length)

        cr.move_to(self.pos1.x - 25, self.pos1.y + self.length)
        cr.line_to(self.pos1.x + 25, self.pos1.y + self.length)

        cr.move_to(self.pos1.x, self.pos1.y + self.length - self.line_segment_length)
        cr.line_to(self.pos1.x, self.pos1.y + self.length)

        cr.set_line_width(8.0)  
        cr.stroke()

        self.length = 200
        self.line_segment_length = 162

        cr.move_to(self.pos2.x - 25, self.pos2.y + self.length - self.line_segment_length)
        cr.line_to(self.pos2.x + 25, self.pos2.y + self.length - self.line_segment_length)

        cr.move_to(self.pos2.x - 25, self.pos2.y + self.length)
        cr.line_to(self.pos2.x + 25, self.pos2.y + self.length)

        cr.move_to(self.pos2.x, self.pos2.y + self.length - self.line_segment_length)
        cr.line_to(self.pos2.x, self.pos2.y + self.length)

        cr.set_line_width(8.0)  
        cr.stroke()