# 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 . 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()