Exemplo n.º 1
0
class Renderer(Widget):

    def __init__(self, **kw):
        self.shader_file = kw.pop("shader_file", None)
        self.canvas = Canvas()
        super(Renderer, self).__init__(**kw)

        with self.canvas:
            self._viewport = Rectangle(size=self.size, pos=self.pos)
            self.fbo = Fbo(size=self.size,
                           with_depthbuffer=True, compute_normal_mat=True)
        self._config_fbo()
        self.texture = self.fbo.texture
        self.camera = None
        self.scene = None

    def _config_fbo(self):
        # set shader file here
        self.fbo.shader.source = self.shader_file or \
                                os.path.join(kivy3_path, "default.glsl")
        with self.fbo:
            Callback(self._setup_gl_context)
            PushMatrix()
            # instructions set for all instructions
            self._instructions = InstructionGroup()
            PopMatrix()
            Callback(self._reset_gl_context)

    def _setup_gl_context(self, *args):
        glEnable(GL_DEPTH_TEST)
        self.fbo.clear_buffer()

    def _reset_gl_context(self, *args):
        glDisable(GL_DEPTH_TEST)

    def render(self, scene, camera):
        self.scene = scene
        self.camera = camera
        self.camera.bind_to(self)
        self._instructions.add(scene.as_instructions())
        Clock.schedule_once(self._update_matrices, -1)

    def on_size(self, instance, value):
        self.fbo.size = value
        self._viewport.texture = self.fbo.texture
        self._viewport.size = value
        self._update_matrices()

    def on_texture(self, instance, value):
        self._viewport.texture = value

    def _update_matrices(self, dt=None):
        if self.camera:
            self.fbo['projection_mat'] = self.camera.projection_matrix
            self.fbo['modelview_mat'] = self.camera.modelview_matrix
        else:
            raise RendererError("Camera is not defined for renderer")

    def set_clear_color(self, color):
        self.fbo.clear_color = color
Exemplo n.º 2
0
    def __init__(self, **kwargs):
        # make sure we aren't overriding any important functionality
        super(PrRoll, self).__init__(**kwargs)

        # midi
        self.midi = None

        # props
        self.size_hint = (None, None)
        self.abs_width = 1280
        self.size = (1280, 1640)
        self.scale = None

        # meters
        self.pips = None
        self.meters = None
        self.meter_width = 1

        # notemap : [note(int)] { x / y / height }
        self.notemap = []
        self.set_notemap()

        # instruction groups
        self.notes = {'all': InstructionGroup()}
        self.meterbars = {'bar': InstructionGroup()}
        self.timebar = InstructionGroup()
        self._timebar = None

        # canvas
        self.draw_timebar()
        self.draw_canvas()
Exemplo n.º 3
0
 def on_bgColor(self, root, val):
     if self.shape_up == None:
         self.shape_up = InstructionGroup(grup="shape_up")
     else:
         self.container.canvas.before.remove(self.shape_up)
         self.shape_up.clear()
     self.draw_color()
Exemplo n.º 4
0
 def on___container___pos(self, root, val):
     if self.__shape_up__ == None:
         self.__shape_up__ = InstructionGroup(grup="__shape_up__ ")
     else:
         self.__container__.canvas.before.remove(self.__shape_up__)
         self.__shape_up__.clear()
     self.draw_color()
Exemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     super().__init__(**kwargs)
     self.fret_bars = InstructionGroup()
     self.inlays = InstructionGroup()
     self.beat_num = 0
     self.background = Rectangle(size=self.size, pos=self.pos)
     self.bind(size=self._update_canvas, pos=self._update_canvas)
Exemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        super(LevelProgressBar, self).__init__(*args, **kwargs)

        texture = Texture.create(size=(1, 16))

        size = 1 * 16 * 3

        buf = [
            int(Color(
                .66 - (float(data) / size) * .66,
                .75,
                .75,
                mode='hsv'
            ).rgb[data % 3] * 255) for data in range(size)
        ]

        buf = b''.join(map(chr, buf))

        texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')

        self.progress_bar = Rectangle(texture=texture)
        self.progress_mask = Rectangle()

        group = InstructionGroup()
        group.add(Color(0, 0, 0))
        group.add(self.progress_mask)

        self.canvas.add(Color(1, 1, 1))
        self.canvas.add(self.progress_bar)
        self.canvas.add(group)

        self.bind(pos=self.redraw, size=self.redraw)
Exemplo n.º 7
0
 def __init__(self, target, **kwargs):
     super(SelectAttackState, self).__init__(target, **kwargs)
     self.amount = self.target.map.tile_width
     self.moving = False
     self.velocity = [0, 0]
     self.layer = self.target.map.layers.by_name['below']
     self.foreshadowed = self.layer.get_at(*target.center)
     self.move_keys = [
         Keyboard.keycodes['left'], Keyboard.keycodes['right'],
         Keyboard.keycodes['up'], Keyboard.keycodes['down'],
         Keyboard.keycodes['enter']
     ]
     self.travelled = set()
     self.checked = set()
     self.index = {}
     self.instructions = InstructionGroup()
     self.layer = self.target.map.layers.by_name['below']
     self.confirmed = False
     self.effect = MeleeDamage
     tile = self.layer.get_at(*self.target.pos)
     self.cursor = Sprite(pos=[tile.px, tile.py],
                          size=self.target.size,
                          texture=images['cursor'],
                          opacity=0.5)
     self.current_tile = self.target.get_current_cell()
     self.target.game.layer_widgets['sprite_layer'].add_widget(self.cursor)
     self.get_tiles_in_range(tile, 0)
     self.selected = None
     self.last_touched = None
     self.highlight_tiles()
 def get_graphics(self, gc, polygons, points_line, rgbFace, closed=False):
     '''Return an instruction group which contains the necessary graphics
        instructions to draw the respective graphics.
     '''
     instruction_group = InstructionGroup()
     if isinstance(gc.line['dash_list'], tuple):
         gc.line['dash_list'] = list(gc.line['dash_list'])
     if rgbFace is not None:
         if len(polygons.meshes) != 0:
             instruction_group.add(Color(*rgbFace))
             for vertices, indices in polygons.meshes:
                 instruction_group.add(
                     Mesh(vertices=vertices,
                          indices=indices,
                          mode=str("triangle_fan")))
     instruction_group.add(Color(*gc.get_rgb()))
     if _mpl_1_5 and closed:
         points_poly_line = points_line[:-2]
     else:
         points_poly_line = points_line
     if gc.line['width'] > 0:
         instruction_group.add(
             Line(points=points_poly_line,
                  width=int(gc.line['width'] / 2),
                  dash_length=gc.line['dash_length'],
                  dash_offset=gc.line['dash_offset'],
                  dash_joint=gc.line['joint_style'],
                  dash_list=gc.line['dash_list']))
     return instruction_group
Exemplo n.º 9
0
    def __init__(self, target, following):
        super(EntityFollow, self).__init__(target)
        self.following = following
        self.cells = []
        self.moving = False
        self.instructions = InstructionGroup()
        targeted = self.target.map.layers.by_name['below'].get_at(*self.following.pos)
        # targeted = self.target.map.layers.by_name['below'].get_neighbor_cells(following_cell)[0]
        origin_cell = self.target.map.layers.by_name['below'].get_at(*self.target.pos)

        if targeted is not None and targeted.tile.is_passable():
            cells = targeted.layer.a_star_search(origin_cell, targeted)
            # if there's only two cells selected, and goal is not origin neighbor... then run away, RUN AWAY!
            if len(cells) == 2 and targeted not in self.target.map.layers.by_name['below'].get_neighbor_cells(origin_cell):
                return
            if len(cells) > 1:
                cells.reverse()
                # self.instructions.clear()
                self.instructions = InstructionGroup()
                # self.highlight_tiles(cells)
                self.cells = cells
                self.moving = False
        if not self.cells:
            print('no cells here dawg')
            self.target.state = EntityIdle(self.target)
            self.end()
            return
        # self.highlight_tiles(self.cells)
        self.foreshadowed = None
        self.velocity = [0, 0]
        self.target.anim_delay = .2
        self.task = Clock.schedule_interval(self.slow_update, .6)
Exemplo n.º 10
0
 def make_line(self, touch):
     c1 = self.bright_color()
     l1 = Line(points=(touch.x, touch.y), width=10)
     line = InstructionGroup(group='line')
     line.add(c1)
     line.add(l1)
     return line
Exemplo n.º 11
0
    def clone(self):
        new_left_line = Line()
        new_left_line.points = [
            self.left_line.points[0], self.left_line.points[1],
            self.left_line.points[2], self.left_line.points[3]
        ]
        new_right_line = Line()
        new_right_line.points = [
            self.right_line.points[0], self.right_line.points[1],
            self.right_line.points[2], self.right_line.points[3]
        ]
        new_top_line = Line()
        new_top_line.points = [
            self.top_line.points[0], self.top_line.points[1],
            self.top_line.points[2], self.top_line.points[3]
        ]
        new_bottom_line = Line()
        new_bottom_line.points = [
            self.bottom_line.points[0], self.bottom_line.points[1],
            self.bottom_line.points[2], self.bottom_line.points[3]
        ]

        rect_lines = InstructionGroup()
        rect_lines.add(new_left_line)
        rect_lines.add(new_right_line)
        rect_lines.add(new_top_line)
        rect_lines.add(new_bottom_line)
        new_rect = Rectangle(new_left_line, new_bottom_line, new_right_line,
                             new_top_line, rect_lines)
        new_rect.set_string(self.get_text())
        return new_rect
Exemplo n.º 12
0
 def make_demo_line(self, x, y):
     c1 = self.bright_color()
     l1 = Line(points=(x, y), width=10)
     line = InstructionGroup(group='demo')
     line.add(c1)
     line.add(l1)
     return line
Exemplo n.º 13
0
    def add_explosion(self, line):
        line += self.currently_exploding
        self.currently_exploding += 1

        explosion = InstructionGroup()
        color = Color(1, 1, .5, .8)

        explosion.add(color)

        explosion.add(Rectangle(
            pos=self.coord_to_pos(0, line),
            size=(
                self.tile_size()[0] * self.cols,
                self.tile_size()[1]
            )
        ))

        self.canvas.add(explosion)

        def remove(self):
            self.canvas.remove(explosion)
            self.currently_exploding -= 1

        anim = Animation(
            a=0,
            duration=.125
        )
        anim.bind(on_complete=lambda *args: remove(self))
        anim.start(color)
Exemplo n.º 14
0
    def __init__(self, midi, **kwargs):
        # make sure we aren't overriding any important functionality
        super(PrRoll, self).__init__(**kwargs)

        # midi
        self.midi = midi

        # props
        self.size_hint = (None, None)
        self.abs_width = 1280
        self.size = (1280, 1640)

        # meters
        self.pips = None
        self.meters = None

        # notemap : [note(int)] { y / height }
        self.notemap = Env.ROLL_NOTEMAP()

        # instruction groups
        self.tracks = PrTracks()
        self.meterbars = {'bar': InstructionGroup()}
        self.timebar = InstructionGroup()

        # timebar object
        self._timebar = None

        # load_midi
        self.load_midi(midi)
Exemplo n.º 15
0
 def __init__(self, scene, priority, args, **kwargs):
     """ Actor constructor """
     super(Actor, self).__init__(**kwargs)
     keys = args.keys()
     self.size = (0, 0)
     self.frame_counter = 0
     self.collision = False
     self.debug = False
     self.sizeUnscaled = (25, 50)
     self.updateThread = None
     self.animateThread = None
     self.doesAnimate = args[
         'doesAnimate'] if 'doesAnimate' in keys else False
     self.doesUpdate = args['doesUpdate'] if 'doesUpdate' in keys else False
     self.updateInterval = args[
         'updateInterval'] if 'updateInterval' in keys else 30.0
     self.animateInterval = args[
         'animateInterval'] if 'animateInterval' in keys else 30.0
     self.pos = (0, 0)
     self.frame_counter_offset = 0
     self.posUnscaled = (0, 0)
     self.scene = scene
     self.priority = priority
     self.canvasSize = self.scene.size
     self.group = InstructionGroup()
     self.init = False
     self.__destroy__ = False
     self.__resize__(self.canvasSize[0], self.canvasSize[1])
     self.count = 0
     self.touched = False
     self.scene.resize_event.append(self.__resize__)
     self.scene.on_setActive.append(self.__set_intervals__)
     self.__main_start__()
Exemplo n.º 16
0
    def __init__(self,
                 data,
                 axis,
                 color=(1, 0, 0),
                 name="Line",
                 units="Hz",
                 **kwargs):
        self.axis = axis
        self.axis.add_line(self)
        self.color = color
        self.name = name
        self.units = units

        if "min" in kwargs:
            self.min = kwargs["min"]
        if "max" in kwargs:
            self.max = kwargs["max"]

        with self.axis.parent.canvas:
            Color(*self.color)
            self.line = Line(width=1.2)

        self.circles = []
        self.circles_draw_group = InstructionGroup()

        self.axis.parent.canvas.add(self.circles_draw_group)

        self.data_update(data)
Exemplo n.º 17
0
class MenuIcon(Widget):
	#spawns moving icon on touch
	def __init__(self, **kwargs):
		super(MenuIcon,self).__init__(**kwargs)
		self.local_c=[0,0]
		self.r=30
		if kwargs is not None:
			for key, value in kwargs.items():
				if(key=='pos'): self.local_c=value
		self.icon=InstructionGroup()
		self.icon.add(Color(1,1,1))
		self.icon.add(Ellipse(size=(2*self.r,2*self.r),pos=(self.local_c[0]-self.r,self.local_c[1]-self.r)))
		self.icon.add(SmoothLine(circle=(self.local_c[0],self.local_c[1],self.r+4),width=3))
		self.icon.add(Color(.3,.3,.3))
		self.icon.add(SmoothLine(circle=(self.local_c[0],self.local_c[1],self.r),width=3))
		for group in [self.icon]:
			self.canvas.add(group)
			
	def options(self):
		pass
	
	def on_touch_down(self,touch):
		if get_dis(self.local_c,touch.pos) < 40:
			a=MovingIcon(pos=touch.pos)
			a.init(self.r*.8)
			self.parent.add_widget(a)#adds moving icon to screen
Exemplo n.º 18
0
    def __init__(self, parent, **kwargs):
        self.lines = []
        self.parent = parent
        self.parent.add_axis(self)

        self.ruler_lines = []
        self.ruler_labels = []
        self.ruler_draw_group = InstructionGroup()
        self.parent.canvas.add(self.ruler_draw_group)

        if "min" in kwargs:
            self.min = kwargs["min"]
        if "max" in kwargs:
            self.max = kwargs["max"]
        if "step" in kwargs:
            self.step = kwargs["step"]
        if "auto_min" in kwargs:
            self.auto_min = kwargs["auto_min"]
        if "auto_max" in kwargs:
            self.auto_max = kwargs["auto_max"]
        if "left" in kwargs:
            self.left = kwargs["left"]
        if "format" in kwargs:
            self.format = kwargs["format"]

        self.delta = self.max - self.min
Exemplo n.º 19
0
    def draw_field(self):
        with self.canvas.before:
            Color(0.992, 0.925, 0.863, 1)
            Rectangle(pos=self.engine.screen_utils.start,
                      size=self.engine.screen_utils.size)

        self.grid = InstructionGroup()
        points = self.engine.screen_utils.create_grid()
        self.grid.add(Color(rgba=(0.29, 0, 0.153, 1)))
        for a, b in points:
            self.grid.add(Line(points=[a[0], a[1], b[0], b[1]]))

        border_width = 5
        dl = self.engine.screen_utils.start
        width, height = self.engine.screen_utils.size
        self.grid.add(
            Line(points=[
                dl[0] - border_width, dl[1] - border_width,
                dl[0] - border_width, dl[1] + height + border_width,
                dl[0] + width + border_width, dl[1] + height + border_width,
                dl[0] + width + border_width, dl[1] - border_width
            ],
                 width=border_width,
                 close=True))
        self.canvas.before.add(self.grid)
Exemplo n.º 20
0
    def __init__(self, **kwargs):
        super(ScrollBox, self).__init__(**kwargs)

        self.bgColor_1 = (1, 1, 1, 1)  #White

        self.instr = InstructionGroup()
        self.canvas.before.add(self.instr)
Exemplo n.º 21
0
 def __init__(self, color=Color(142/255, 206/255, 229/255, 1),**kwargs):  
     self.bg = InstructionGroup()        
     self.color_widget = color
     self._rectangle = Rectangle()
     self.bg.add(self.color_widget)
     self.bg.add(self._rectangle)
     super(ColorBoxLayout, self).__init__(**kwargs)  
     self.canvas.add(self.bg)
Exemplo n.º 22
0
 def __init__(self, master, **kwargs):
     super().__init__(**kwargs)
     self.master = master
     self.rects = InstructionGroup()
     self.ids.mask.canvas.add(self.rects)
     Window.bind(on_joy_axis=self.on_joy_axis)
     Window.bind(on_joy_button_down=self.on_joy_button_down)
     Window.bind(on_joy_button_up=self.on_joy_button_up)
Exemplo n.º 23
0
 def afficheBut(self, positionBut):
     self.but = InstructionGroup()
     for goal in positionBut:
         self.but.add(
             Rectangle(source='labyrinthC/Sprites/Artefacts/Treasure.png',
                       pos=self.transpose(goal),
                       size=(self.tailleCase, self.tailleCase)))
     self.canvas.add(self.but)
Exemplo n.º 24
0
 def draw_line(self, line, line_width=1, color=(0, 0, 0)):
     instructions = InstructionGroup()
     self.set_color(instructions, color)
     instructions.add(
         Line(points=[(line.start.x, line.start.y),
                      (line.end.x, line.end.y)],
              width=line_width))
     self.canvas.add(instructions)
Exemplo n.º 25
0
 def ecranDefaite(self):
     self.canvas.clear()
     self.canvas.after.clear()
     self.loose = InstructionGroup()
     self.loose.add(
         Rectangle(source='labyrinthC/Sprites/DEFAITE.png',
                   size=self.size,
                   pos=(0, 0)))
     self.canvas.after.add(elf.loose)
Exemplo n.º 26
0
    def __init__(self, width, height, canvas):
        self.width = width
        self.height = height
        self.start = 0

        self.canvas = canvas

        self.loop = False
        self.loops = InstructionGroup()
Exemplo n.º 27
0
 def ecranVictoire(self):
     self.canvas.clear()
     self.canvas.after.clear()
     self.win = InstructionGroup()
     self.win.add(
         Rectangle(source='labyrinthC/Sprites/VICTOIRE.png',
                   size=self.size,
                   pos=(0, 0)))
     self.canvas.after.add(self.win)
Exemplo n.º 28
0
 def draw_line(self, next_hold_coordinates):
     group_of_lines = InstructionGroup()
     group_of_lines.add(
         Line(width=2.,
              points=(self.last_hold_coordinates[0],
                      self.last_hold_coordinates[1],
                      next_hold_coordinates[0], next_hold_coordinates[1])))
     self.line_objects.append(group_of_lines)
     self.canvas.add(group_of_lines)
Exemplo n.º 29
0
 def __init__(self, *args, **kwargs):
     super().__init__(**kwargs)
     self.fret_bars = InstructionGroup()
     self.inlays = InstructionGroup()
     self.beat_num = 0
     self.color_map = {}
     self.bind(size=self._update_canvas, pos=self._update_canvas)
     Clock.schedule_once(self._tune_to_standard,
                         0)  # cannot use kv id's until __init__ is done.
Exemplo n.º 30
0
 def __init__(self, **kwargs):
     super(PuzzleGameWidget, self).__init__(**kwargs)
     self.bkg = "data/images/steampunk-bkg.png"
     app = App.get_running_app()
     self.atlas = app.default_atlas
     self.piece = app.piece
     self.board = app.game_board
     self.piece_group = InstructionGroup()
     self.canvas.add(self.piece_group)
     Clock.schedule_interval(self.next_state, .1)
Exemplo n.º 31
0
    def create_cell_grid(self, data_frame):
        for cell_row in range(0, len(data_frame)):
            row_instructions = InstructionGroup()
            for cell_col in range(len(data_frame[cell_row])):
                color = create_color(data_frame[cell_row][cell_col])
                cell_instructions = self._create_cell(cell_row, cell_col,
                                                      color)
                row_instructions.insert(cell_col, cell_instructions)

            self.grid.canvas.insert(cell_row, row_instructions)
Exemplo n.º 32
0
def put_pixel(x, y, color, canvas, token, alpha=None, thickness=2):
    r, g, b = color.r, color.g, color.b
    c = Color(r, g, b)
    if alpha:
        c.a = alpha
    group = InstructionGroup(group=token)
    group.add(c)
    group.add(Rectangle(pos=(x, y), size=(thickness, thickness)))

    canvas.add(group)
Exemplo n.º 33
0
 def __init__(self, target, cells, **kwargs):
     super(RealtimeTouchMove, self).__init__(target, **kwargs)
     self.cells = cells
     self.moving = False
     self.instructions = InstructionGroup()
     self.highlight_tiles(cells)
     self.foreshadowed = self.target._current_cell
     self.velocity = [0, 0]
     self.target.anim_delay = .2
     self.movement_axis = 0
Exemplo n.º 34
0
 def get_graphics(self, gc, polygons, points_line, rgbFace, closed=False):
     '''Return an instruction group which contains the necessary graphics
        instructions to draw the respective graphics.
     '''
     instruction_group = InstructionGroup()
     if isinstance(gc.line['dash_list'], tuple):
         gc.line['dash_list'] = list(gc.line['dash_list'])
     if rgbFace is not None:
         if len(polygons.meshes) != 0:
             instruction_group.add(Color(*rgbFace))
             for vertices, indices in polygons.meshes:
                 instruction_group.add(Mesh(
                     vertices=vertices,
                     indices=indices,
                     mode=str("triangle_fan")
                 ))
     instruction_group.add(Color(*gc.get_rgb()))
     if _mpl_1_5 and closed:
         points_poly_line = points_line[:-2]
     else:
         points_poly_line = points_line
     if gc.line['width'] > 0:
         instruction_group.add(Line(points=points_poly_line,
             width=int(gc.line['width'] / 2),
             dash_length=gc.line['dash_length'],
             dash_offset=gc.line['dash_offset'],
             dash_joint=gc.line['joint_style'],
             dash_list=gc.line['dash_list']))
     return instruction_group
    def __init__(self, body, size, texture=None, halfShift=True):

        ig = InstructionGroup()
        ig.add(Color(1,1,1, 1.0))
        ig.add(Rectangle(pos=(0,0), size=size, texture=texture))

        offset = None
        if halfShift:
            offset = [-1.0*s/2.0 for s in size]

        super(TextrueRect, self).__init__(body, instruction=ig, offset=offset)
Exemplo n.º 36
0
    def __init__(self, **kwargs):
        super(AltLabel, self).__init__(**kwargs)

        self.onColor = (1, 0, 0, 1)
        self.offColor = (0, 1, 0, 1)

        self.bold = False
        self.font_size = 14

        self.instr = InstructionGroup()
        self.canvas.before.add(self.instr)
Exemplo n.º 37
0
 def _add_play_sign(self, *largs):
     self.play_sign = InstructionGroup()
     self.play_sign.add(Color(1, 1, 1, 1))
     self.play_sign.add(
         Triangle(points=[
             self.x + self.width * 0.35, self.y +
             self.height * 0.25, self.x + self.width * 0.35, self.y +
             self.height * 0.75, self.x + self.width * 0.75, self.y +
             self.height * 0.50
         ]))
     self.canvas.after.add(self.play_sign)
Exemplo n.º 38
0
class PaintAreaBackgroundWidget(RelativeLayout):

    selectedColor = ListProperty([1,0,0,1])

    def __init__(self, *args, **kwargs):
        super(PaintAreaBackgroundWidget, self).__init__(*args, **kwargs)

        self.lineGroup = None
        self.line = None
        self.isDrawing = False

    def on_touch_down(self, touch):

        # only draw if no widget is selected 
        if self.paintWidget.selectedItem is None:

            if self.collide_point(*touch.pos):

                self.isDrawing = True

                width = self.lineWidth
                self.lineGroup = InstructionGroup()
                #print self.lineGroup
                self.line = Line(points=(touch.x, touch.y),width=width,dash_offset=2)
                self.lineGroup.add(Color(*self.selectedColor))
                self.lineGroup.add(self.line)
                self.canvas.add(self.lineGroup)

    def on_touch_move(self, touch):
        if self.paintWidget.selectedItem is None:
            if self.collide_point(*touch.pos):
                self.line.points += [touch.x, touch.y]

    def on_touch_up(self, touch):
        if self.paintWidget.selectedItem is None:
            if self.collide_point(*touch.pos) and len(self.line.points)>1:
                    

                self.canvas.remove(self.lineGroup)

                lp = numpy.array(self.line.points)
                scatterPolyLine = ScatterPolyLineWidget(paintWidget=self.paintWidget,
                    linePoints=lp, lineWidth=self.lineWidth, lineColor=self.selectedColor)


                self.line.points = []
        
                scatterPolyLine.pos =  [scatterPolyLine.minX,
                                        scatterPolyLine.minY]
                #.size = polyLineWidget.size
                self.addPaintedThingsWidget.add_widget(scatterPolyLine)
                #self.addedOne = True
            self.isDrawing = False
Exemplo n.º 39
0
 def clear(self):
     """Reset the entire letter grid, eliminating all letter boxes."""
     self._labels = dict()
    
     self.canvas.clear()
     self.canvas.add(Color(0,0,0,1))
     self.canvas.add(Rectangle(pos=self.pos,size=self.size))
     
     self._back  = InstructionGroup()
     self._front = InstructionGroup()
     self.canvas.add(self._back)
     self.canvas.add(self._front)
Exemplo n.º 40
0
    def __init__(self, player1, player2, **kwargs):
        self.canvas = InstructionGroup()

        self.beamColor = Color(0.0, 0.0, 0.0, 1.0)
        self.beamGroup = InstructionGroup()
        self.beamThickness = 40
        self.canvas.add(self.beamGroup)

        self.player1 = player1
        self.player2 = player2

        self.beamState = 0
        self.isColliding = False
Exemplo n.º 41
0
    def __init__(self, enemyType, **kwargs):
        self.canvas = InstructionGroup()

        self.enemyType = enemyType
        self.sprite = Sprite()

        if self.enemyType == 'normal':
            self.setOffsetTheta(0)
            self.sprite.color.r = 0.0
            self.sprite.color.g = 0.2
            self.sprite.color.b = 0.5
        else:
            self.setOffsetTheta(math.pi / 2)
            self.sprite.color.r = 0.5
            self.sprite.color.g = 0.1
            self.sprite.color.b = 0.1

        self.health = 100

        self.pos = (0, 0)
        self.velocity = [0, 0]

        self.updateAppearance()

        self.canvas.add(self.sprite.canvas)

        self.shouldRemove = False
Exemplo n.º 42
0
 def __init__(self, target, **kwargs):
     super(SelectAttackState, self).__init__(target, **kwargs)
     self.amount = self.target.map.tile_width
     self.moving = False
     self.velocity = [0, 0]
     self.layer = self.target.map.layers.by_name['below']
     self.foreshadowed = self.layer.get_at(*target.center)
     self.move_keys = [Keyboard.keycodes['left'], Keyboard.keycodes['right'],
                       Keyboard.keycodes['up'], Keyboard.keycodes['down'], Keyboard.keycodes['enter']]
     self.travelled = set()
     self.checked = set()
     self.index = {}
     self.instructions = InstructionGroup()
     self.layer = self.target.map.layers.by_name['below']
     self.confirmed = False
     self.effect = MeleeDamage
     tile = self.layer.get_at(*self.target.pos)
     self.cursor = Sprite(pos=[tile.px, tile.py],
                          size=self.target.size, texture=images['cursor'], opacity=0.5)
     self.current_tile = self.target.get_current_cell()
     self.target.game.layer_widgets['sprite_layer'].add_widget(self.cursor)
     self.get_tiles_in_range(tile, 0)
     self.selected = None
     self.last_touched = None
     self.highlight_tiles()
Exemplo n.º 43
0
    def __init__(self, playerCode, **kwargs):
        self.canvas = InstructionGroup()

        self.sprite = Sprite()

        self.playerCode = playerCode
        self.frameNum = 0

        self.bottomLeft = (0, 0)
        self.topRight = (700, 500)
        self.pos = (0, 0)

        self.direction = (0, 0)
        self.speed = 0
        self.targetDirection = (0, 0)
        self.targetSpeed = 0
        self.isTweeningDirection = False
        self.isTweeningSpeed = False
        self.newDirectionSince = 0
        self.newSpeedSince = 0
        self.directionChange = (0, 0)

        if playerCode == 'p2':
        	self.sprite.color.r = 1

        if playerCode == 'enemy1':
        	self.sprite.color.b = 1

        self.canvas.add(self.sprite.canvas)
    def __init__(self, body, instruction, offset=None):
        #self.size = size
        self.body = body
        self.instructionGroup = InstructionGroup()



        self.instructionGroup.add(PushMatrix())

        self.s = Scale(50.0)
        self.t = Translate(0,0)
        self.r = Rotate(0.0)

        #self.rect  = Rectangle(pos=(0,0), size=(1, 1))

        self.instructionGroup.add(self.s)
        self.instructionGroup.add(self.t)
        self.instructionGroup.add(self.r)
        if offset is not None:
            self.instructionGroup.add(Translate(offset[0], offset[1]))

        #g = InstructionGroup()
        #g.add(Color(1,1,1,1))
        #g.add(self.rect)

        self.instructionGroup.add(instruction)

        #self.instructionGroup.add(Color(1,1,1,1))
        #self.instructionGroup.add(self.rect)


        self.instructionGroup.add(PopMatrix())
Exemplo n.º 45
0
 def __init__(self, target, cells, **kwargs):
     super(RealtimeTouchMove, self).__init__(target, **kwargs)
     self.cells = cells
     self.moving = False
     self.instructions = InstructionGroup()
     self.highlight_tiles(cells)
     self.foreshadowed = self.target._current_cell
     self.velocity = [0, 0]
     self.target.anim_delay = .2
     self.movement_axis = 0
Exemplo n.º 46
0
 def __init__(self, **kw):
     """**Constructor**: Create a new letter box
     
         :param keywords: dictionary of keyword arguments 
         **Precondition**: See below.
     
     To use the constructor for this class, you should provide
     it with a list of keyword arguments that initialize various
     attributes.  For example, to initialize a 2x3 grid, use
     the constructor call
     
         GObject(rows=2,cols=3)
     
     You do not need to provide the keywords as a dictionary.
     The ** in the parameter `keywords` does that automatically.
     
     Any attribute of this class may be used as a keyword.  The
     argument must satisfy the invariants of that attribute.  See
     the list of attributes of this class for more information."""
     Widget.__init__(self,**kw)
     self._resized = True
     self._labels = dict()
     self._set_properties(kw)
     self.bind(pos=self._reposition)
     
     # Create a layer for proper state control.
     self._back  = InstructionGroup()
     self._front = InstructionGroup()
     self.canvas.add(self._back)
     self.canvas.add(self._front)
     
     # Bind kivy attributes to methods
     self.bind(size=self._resize)
     self.bind(cols=self._resize)
     self.bind(rows=self._resize)
     self.bind(border=self._set_border)
     self.bind(font_size=self._set_font_size)
     self.bind(bold=self._set_bold)
     self.bind(italic=self._set_italic)
     self.bind(foreground=self._set_foreground)
     self.bind(background=self._set_background)
     self.bind(textcolor=self._set_textcolor)
Exemplo n.º 47
0
 def _config_fbo(self):
     # set shader file here
     self.fbo.shader.source = self.shader_file or \
                             os.path.join(kivy3_path, "default.glsl")
     with self.fbo:
         Callback(self._setup_gl_context)
         PushMatrix()
         # instructions set for all instructions
         self._instructions = InstructionGroup()
         PopMatrix()
         Callback(self._reset_gl_context)
Exemplo n.º 48
0
class Sprite():
    def __init__(self, **kwargs):
        self.canvas = InstructionGroup()

        self.sizeScalar = 50
        self.color = Color(0.0, 0.5, 0.2)
        self.centerPos = (MIDDLE_X, MIDDLE_Y)

        self.rect = Rectangle(pos=(330, 220), size=(50, 45))
        self.setCenterPos((330, 220))
        self.repos()

        self.canvas.add(self.color)
        self.canvas.add(self.rect)

    def repos(self):
        size = (self.sizeScalar, self.sizeScalar * ASPECT)
        self.rect.pos = (self.centerPos[0] - (size[0] / 2), self.centerPos[1] - (size[1] / 2))
        self.rect.size = size

    def setSizeScalar(self, sizeScalar):
        self.sizeScalar = sizeScalar
        self.repos()

    def setCenterPos(self, centerPos):
        self.centerPos = centerPos
        self.repos()

    def collidesWithLine(self, lineCoords):
        halfWidth = self.rect.size[0] / 2
        halfHeight = self.rect.size[1] / 2

        topLeft = (self.centerPos[0] - halfWidth, self.centerPos[1] + halfHeight)
        topRight = (self.centerPos[0] + halfWidth, self.centerPos[1] + halfHeight)
        bottomLeft = (self.centerPos[0] - halfWidth, self.centerPos[1] - halfHeight)
        bottomRight = (self.centerPos[0] + halfWidth, self.centerPos[1] - halfHeight)

        intersection1 = Vector.segment_intersection(topLeft, bottomRight, (lineCoords[0], lineCoords[1]), (lineCoords[2], lineCoords[3]))
        intersection2 = Vector.segment_intersection(bottomLeft, topRight, (lineCoords[0], lineCoords[1]), (lineCoords[2], lineCoords[3]))

        return True if intersection1 or intersection2 else False
Exemplo n.º 49
0
    def __setitem__(self, key, cell):
        ret = super().__setitem__(key, cell)

        group = InstructionGroup()
        if cell.food == 0:
            group.add(self.color)
            group.add(Mesh(vertices=self._mesh_vertices(cell),
                           indices=list(range(6)),
                           mode=self.mesh_mode))
        else:
            group.add(Color(0, 1, 0, 1))
            group.add(Mesh(vertices=self._mesh_vertices(cell),
                           indices=list(range(6)),
                           mode='triangle_fan'))

        self.canvas_groups[key] = group
        self.canvas.add(group)
        return ret
Exemplo n.º 50
0
    def __init__(self, **kwargs):
        self.canvas = InstructionGroup()

        self.sizeScalar = 50
        self.color = Color(0.0, 0.5, 0.2)
        self.centerPos = (MIDDLE_X, MIDDLE_Y)

        self.rect = Rectangle(pos=(330, 220), size=(50, 45))
        self.setCenterPos((330, 220))
        self.repos()

        self.canvas.add(self.color)
        self.canvas.add(self.rect)
Exemplo n.º 51
0
    def calc_hillbodies(self, force, planet):
        # typecasting problem while crosscompiling
        foo = Utilitys.get_app_config('planetapp','showforcemode')
        if foo == u'0':
            return
        if ((force / self.mass) > (self.showforcelimit * 0.0002)):
            if not planet.fixed:
                if not planet in self.hillbodies: 
                    self.hillbodies.append(planet)
        else:
            if planet in self.hillbodies:
                self.hillbodies.remove(planet)

        for dude in self.canvas.children:
            if 'InstructionGroup' in  type(dude).__name__:
                self.canvas.remove(dude)
        shit = InstructionGroup()
        for body in self.hillbodies:
            shit.add(Line(points=(self.center_x,self.center_y,
                                  body.center_x,body.center_y),
                          width=1,
                          group=str(self.uid)))
        if len(self.hillbodies) > 0:
            self.canvas.add(shit)
Exemplo n.º 52
0
 def draw_rubberband(self, event, x0, y0, x1, y1):
     w = abs(x1 - x0)
     h = abs(y1 - y0)
     rect = [int(val)for val in (min(x0, x1) + self.canvas.x, min(y0, y1)
                     + self.canvas.y, w, h)]
     if self.lastrect is None:
         self.canvas.canvas.add(Color(*self.rubberband_color))
     else:
         self.canvas.canvas.remove(self.lastrect)
     self.lastrect = InstructionGroup()
     self.lastrect.add(Line(rectangle=rect, width=1.0, dash_length=5.0,
             dash_offset=5.0))
     self.lastrect.add(Color(1.0, 0.0, 0.0, 0.2))
     self.lastrect.add(Rectangle(pos=(rect[0], rect[1]),
                                 size=(rect[2], rect[3])))
     self.canvas.canvas.add(self.lastrect)
Exemplo n.º 53
0
    def on_touch_down(self, touch):

        # only draw if no widget is selected 
        if self.paintWidget.selectedItem is None:

            if self.collide_point(*touch.pos):

                self.isDrawing = True

                width = self.lineWidth
                self.lineGroup = InstructionGroup()
                #print self.lineGroup
                self.line = Line(points=(touch.x, touch.y),width=width,dash_offset=2)
                self.lineGroup.add(Color(*self.selectedColor))
                self.lineGroup.add(self.line)
                self.canvas.add(self.lineGroup)
Exemplo n.º 54
0
	def _updateView(self):
		if not self.calibrating:
			pass
		else:
			location = self._getExpectedPosition()

			if self.savePointInstructionGroup == None:
				self.savePointInstructionGroup = InstructionGroup()
				self.savePointInstructionGroup.add(Color(1, 0, 0))
				self._drawCircle(location, 100, self.savePointInstructionGroup)
				self.savePointInstructionGroup.add(Color(0, 0, 0))
				self._drawCircle(location, 66, self.savePointInstructionGroup)
				self.savePointInstructionGroup.add(Color(1, 1, 1))
				self._drawCircle(location, 33, self.savePointInstructionGroup)

				self.canvas.add(self.savePointInstructionGroup)
Exemplo n.º 55
0
    def touch(self, touch, *args):
        pos = self.target.map.pixel_from_screen(*touch.pos)
        cell = self.target.map.layers.by_name['below'].get_at(*pos)
        origin_cell = self.target.map.layers.by_name['below'].get_at(*self.target.pos)

        if cell is not None and cell.tile.is_passable():
            cells = cell.layer.a_star_search(origin_cell, cell)
            # if there's only two cells selected, and goal is not origin neighbor... then run away, RUN AWAY!
            if len(cells) == 2 and cell not in self.target.map.layers.by_name['below'].get_neighbor_cells(origin_cell):
                return
            if len(cells) > 1:
                cells.reverse()
                self.instructions.clear()
                self.instructions = InstructionGroup()
                self.highlight_tiles(cells)
                self.cells = cells
                self.moving = False
Exemplo n.º 56
0
 def __init__(self, target, **kwargs):
     super(SelectMoveState, self).__init__(target, **kwargs)
     self.amount = self.target.map.tile_width
     self.moving = False
     self.velocity = [0, 0]
     self.layer = self.target.map.layers.by_name['below']
     self.foreshadowed = self.layer.get_at(*target.center)
     self.current_tile = self.target.get_current_cell()
     self.move_keys = [Keyboard.keycodes['left'], Keyboard.keycodes['right'],
                       Keyboard.keycodes['up'], Keyboard.keycodes['down'], Keyboard.keycodes['enter']]
     self.travelled = set()
     self.checked = set()
     self.index = {}
     self.instructions = InstructionGroup()
     self.layer = self.target.map.layers.by_name['below']
     tile = self.layer.get_at(*self.target.pos)
     self.get_tiles_in_range(tile, 0)
     self.last_touched = None
     self.selected = []
     self.highlight_tiles()
Exemplo n.º 57
0
 def mark_row(self, row, border_width=1):
     """Mark a row. The old mark is removed."""
     assert self._pattern, "I can only mark a row if I show a pattern."
     row = self._layout.row_in_grid(row)
     if self._mark:
         self.canvas.remove(self._mark)
     border_width *= self.zoom
     width = row.width * self._zoom + border_width + border_width
     height = row.height * self._zoom + border_width + border_width
     x = (self._flip_x - row.x - row.width) * self._zoom - border_width
     y = (row.y - self._min_y) * self._zoom - border_width
     self._mark = InstructionGroup()
     self._mark.add(Color(0, 0, 1, 1))
     self._mark.add(Rectangle(pos=(x, y), size=(width, border_width)))
     self._mark.add(Rectangle(pos=(x, y + height),
                              size=(width, border_width)))
     self._mark.add(Rectangle(pos=(x, y), size=(border_width, height)))
     self._mark.add(Rectangle(pos=(x + width, y),
                              size=(border_width, height)))
     self.canvas.add(self._mark)
Exemplo n.º 58
0
    def __init__(self, **kw):

        super(Object3D, self).__init__(**kw)
        self.name = kw.pop('name', '')
        self.children = list()
        self.parent = None

        self.scale = Scale(1., 1., 1.)
        self._position = Vector3(0, 0, 0)
        self._rotation = Vector3(0, 0, 0)
        self._position.set_change_cb(self.on_pos_changed)
        self._rotation.set_change_cb(self.on_angle_change)

        # general instructions
        self._pop_matrix = PopMatrix()
        self._push_matrix = PushMatrix()
        self._translate = Translate(*self._position)
        self._rotors = {
                        "x": Rotate(self._rotation.x, 1, 0, 0),
                        "y": Rotate(self._rotation.y, 0, 1, 0),
                        "z": Rotate(self._rotation.z, 0, 0, 1),
                        }

        self._instructions = InstructionGroup()
Exemplo n.º 59
0
def draw_point(point):
    token = str(hash(point))
    group = InstructionGroup(group=token)
    point.obj.widget.canvas.remove_group(token)
    x, y = point.x, point.y

    if point.texture is not None:
        group.add(
        Ellipse(
            pos=(x - point.size/2, y - point.size/2),
            size=(point.size, point.size),
            texture=point.texture
        )
    )
    else:
        group.add(POINT_COLOR)
        group.add(
            Ellipse(
                pos=(x - point.size/2, y - point.size/2),
                size=(point.size, point.size)
            )
        )

    point.obj.widget.canvas.add(group)
Exemplo n.º 60
0
    def calc_hillbodies(self, force, planet):
        # typecasting problem while crosscompiling
        foo = App.get_running_app().config.get('planetapp','showforcemode')
        if foo == u'0':
            return
        if ((force / self.mass) > (self.showforcelimit * 0.0002)):
            if not planet.fixed:
                if not planet in self.hillbodies: 
                    self.hillbodies.append(planet)
        else:
            if planet in self.hillbodies:
                self.hillbodies.remove(planet)

        for dude in self.canvas.children:
            if 'InstructionGroup' in  type(dude).__name__:
                self.canvas.remove(dude)
        shit = InstructionGroup()
        for body in self.hillbodies:
            shit.add(Line(points=(self.center_x,self.center_y,
                                  body.center_x,body.center_y),
                          width=1,
                          group=str(self.uid)))
        if len(self.hillbodies) > 0:
            self.canvas.add(shit)

        if self.drawtrajectory and not self.fixed:
            shit2 = InstructionGroup()
            sunpos = (self.parent.width/2,self.parent.height/2)
            trajectory = self.parent.calc_trajectory((self.center_x,self.center_y),
                                                     self.velocity, 
                                                     self.mass, sunpos, 
                                                     self.parent.sunmass, 1, 
                                                     1000)
            shit2.add(Line(points=trajectory, width=1, group=str(self.uid)))
            self.canvas.add(shit2)
        else:
            pass