Beispiel #1
0
 def createPlane(self, frame=None, color=VBase4(1, 1, 1, 1)):
     """ Creates a Plane/Card with the Panda3d Cardmaker() class
     Keyword Arguments:
         frame {list} -- The coordinates [x1,y1,x2,y2] of the planes/cards edges (default: {[-1, -1, 1, 1]})
         color {VBase4} -- The color of the planes/cards (default: {VBase4(1, 1, 1, 1)})
     """
     frame = frame or [-1, -1, 1, 1]
     card = CardMaker("plane")
     card.set_color(color)
     card.set_frame(frame[0], frame[1], frame[2], frame[3])
     n = NodePath()
     self.plane = n.attach_new_node(card.generate())
     self.plane.reparentTo(self.render)
     self.plane.setHpr(0, 270, 0)
Beispiel #2
0
 def show_match_sample(self, task):
     print 'show match sample'
     print self.color_match[:]
     # match_image.fill(*self.color_match[:])
     card = CardMaker('card')
     color_match = self.color_match[:]
     # add alpha channel
     color_match.append(1)
     print color_match
     card.set_color(*color_match[:])
     card.set_frame(-12, -8, 0, 4)
     # log this
     self.card = self.base.render.attach_new_node(card.generate())
     return task.done
Beispiel #3
0
 def show_match_sample(self, task):
     print 'show match sample'
     print self.color_match[:]
     # match_image.fill(*self.color_match[:])
     card = CardMaker('card')
     color_match = self.color_match[:]
     # add alpha channel
     color_match.append(1)
     print color_match
     card.set_color(*color_match[:])
     card.set_frame(-12, -8, 0, 4)
     # log this
     self.card = self.base.render.attach_new_node(card.generate())
     return task.done
Beispiel #4
0
class TextFileSelectionNode(DirectObject, TextFileNode):
    def __init__(self, name, filename=None, **options):
        DirectObject.__init__(self)
        TextFileNode.__init__(self, name, None, **options)

        self.cardmaker = CardMaker('selection cards')
        self.selection_cards = []
        self.selecting = False
        self.rect_w, self.rect_h = 1, 1

        self.accept('shift', self.toggle_select, extraArgs=[True])
        self.accept('shift-up', self.toggle_select, extraArgs=[False])

    # Selection editing
    def clear_rects(self):
        for card in self.selection_cards:
            if card in list(self.children):
                self.remove_child(card)
        self.selection_cards = []

    def draw_rect(self, rect, color=(1,1,1,1)):
        rx, ry, rw, rh = rect
        l = ((rx)*self.rect_w)
        r = ((rx+rw+1)*self.rect_w)-0.2
        u = ((ry-1)*self.rect_h)+0.5
        d = ((ry+rh)*self.rect_h)+0.3
        self.cardmaker.set_frame(l,r,-u,-d)
        self.cardmaker.set_color(color)
        card = self.cardmaker.generate()
        self.add_child(card)
        return card

    def draw_line_rect(self, line_number, start, end=0):
        x = self.line_number_width+start
        y = line_number-self.line_offset
        w = len(self.lines[line_number])-start
        if end:
            w = min(w,end)
        self.selection_cards.append(self.draw_rect([x,y,w,0]))

    def remove_range(self):
        end, start = self.selection_direction()
        if start[1] == end[1]:
            a = self.lines[start[1]][:end[0]]
            b = self.lines[start[1]][start[0]:]
            self.lines[start[1]] = a + b
            self.x, self.y = end
        else:
            a = self.lines[start[1]][:start[0]]
            b = self.lines[end[1]][end[0]:]
            self.lines[start[1]] = a + b
            for i in range(1, (end[1]-start[1])+2):
                self.lines.pop(start[1]+1)
            self.x, self.y = start

    def select_range(self):
        self.clear_rects()
        self.selection_buffer = []
        start, end = self.selection_direction()
        if start[1] == end[1]:
            self.draw_line_rect(start[1], end[0], start[0]-end[0])
            self.selection_buffer.append(self.lines[start[1]][start[0]:end[0]])
        else:
            if start[0] > 0:
                self.draw_line_rect(start[1], 0, start[0])
                self.selection_buffer.append(self.lines[start[1]][:start[0]])
            for i in range(1, start[1]-end[1]):
                i = start[1] - i
                self.draw_line_rect(i,0)
                self.selection_buffer.append(self.lines[i])
            self.draw_line_rect(end[1], end[0])
            self.selection_buffer.append(self.lines[end[1]][start[0]:])

    def selection_direction(self):
        if self.y > self.selection_start[1]:
            return (self.x, self.y), self.selection_start
        else:
            return self.selection_start, (self.x, self.y)

    def toggle_select(self, on=True):
        if len(self.selection_buffer) > 0:
            already_selecting = True
        else:
            already_selecting = False
        self.selecting = on
        if self.selecting and not already_selecting:
            self.selection_start = [self.x, self.y]