示例#1
0
def paddle(name, canvas, pos, size, controller):
    # Handles the mouse input by updating the paddle's position. This is
    # run at 60 FPS, as long as the game is running (ie.: no
    # game-over).
    #
    # Since the animator expects each callback to return whether it
    # should continue running or not — by signaling with either True or
    # False — we just return the value of GAME_RUNNING here.
    def handle_input():
        screen = canvas.rect.move_by(10, 10).inflate(-20, -20)
        px, py = canvas.pointer_canvas_xy
        controller(pad, px, py)
        pad.rect = pad.rect.clamp(screen)

        return GAME_RUNNING

    pad = canvas.Rectangle(name=name, color=(238, 238, 236, 255))
    pad.resize(*size)
    pad.move(*pos)
    pad.show()

    # Adds the pad area as a solid area, so the ball collides with it.
    add_collision_object(pad)

    # Adds the input handler to the list of animator callbacks
    animator_add(handle_input)

    return pad
示例#2
0
    def force_move(self, from_value, to_value, interval):
        """Animate movement from one value to another in some interval.

        This function will try to calculate the correct speed for the animation
        to respect the interval.
        """
        if from_value == to_value:
            if self.state_change:
                self.state_change(False)
            return

        # Note that we invert things here because other functions usually
        # take the MOUSE GESTURE and move the other way around
        dv = from_value - to_value
        self.speed = dv / (interval * \
                               (1 - (0.5 * self.accel_constant * interval)))
        self.accel = -(self.speed * self.accel_constant)
        self.time = ecore.time_get()
        self.cancel_click = True

        self.forced_goal = abs(dv)
        self.forced = True

        if not self.animation:
            if self.state_change:
                self.state_change(True)
            self.animation = ecore.animator_add(self._animation)
示例#3
0
 def __mouse_down_cb(self, obj, event):
     self._desktop_scroller.scroll_hold_push()
     self._start_region = self._desktop_scroller.region_get()
     self._start = event.position.output.xy
     self._last = self._start
     self._move_animator = ecore.animator_add(self.__move_animator_do)
     self._modifier_control = event.modifier_is_set("Control")
     self._modifier_shift = event.modifier_is_set("Shift")
     self.down(*event.position.output)
     self.on_mouse_up_add(self.__mouse_up_cb)
示例#4
0
 def __mouse_down_cb(self, obj, event):
     self._desktop_scroller.scroll_hold_push()
     self._start_region = self._desktop_scroller.region_get()
     self._start = event.position.output.xy
     self._last = self._start
     self._move_animator = ecore.animator_add(self.__move_animator_do)
     self._modifier_control = event.modifier_is_set("Control")
     self._modifier_shift = event.modifier_is_set("Shift")
     self.down(*event.position.output)
     self.on_mouse_up_add(self.__mouse_up_cb)
示例#5
0
    def _run(self):
        def animate():
            t = ecore.time_get()
            progress = (t - self.time_start) / self.duration
            if progress >= 1.0:
                progress = 1.0
                self.anim = None
            self._exec(progress)
            return progress < 1.0

        self.anim = ecore.animator_add(animate)
示例#6
0
 def start(self, *args):
     if not self.animator:
         if self.repeat_timer:
             self.repeat_timer.delete()
             self.repeat_timer = None
         self._setup_start_pos()
         self.text1_times = 0
         self.text2_times = 0
         self.move_text1 = True
         self.move_text2 = False
         self.animator = ecore.animator_add(self._scroll_text)
示例#7
0
文件: animations.py 项目: Limsik/e17
    def _run(self):
        def animate():
            t = ecore.time_get()
            progress = (t - self.time_start) / self.duration
            if progress >= 1.0:
                progress = 1.0
                self.anim = None
            self._exec(progress)
            return progress < 1.0

        self.anim = ecore.animator_add(animate)
示例#8
0
文件: scroller.py 项目: Limsik/e17
 def start(self, *args):
     if not self.animator:
         if self.repeat_timer:
             self.repeat_timer.delete()
             self.repeat_timer = None
         self._setup_start_pos()
         self.text1_times = 0
         self.text2_times = 0
         self.move_text1 = True
         self.move_text2 = False
         self.animator = ecore.animator_add(self._scroll_text)
示例#9
0
    def __init__(self, *args, **kargs):
        evas.ClippedSmartObject.__init__(self, *args, **kargs)
        # It's recommended to use self.XXX to create member objects
        self.bg = self.Rectangle(color=(200, 200, 200, 255))
        self.bg.show()
        # But one can do the regular way, just remember to member_add()!
        # This is required by non-primitive objects, like Edje and other
        # SmartObjects
        self.child = evas.Rectangle(self.evas, color=(255, 0, 0, 255),
                                    size=(10, 10))
        self.member_add(self.child)
        self.child.show()

        self.vx, self.vy = 1, 2
        self.animator = ecore.animator_add(self._animator_cb)
示例#10
0
    def __init__(self, *args, **kargs):
        evas.ClippedSmartObject.__init__(self, *args, **kargs)
        # It's recommended to use self.XXX to create member objects
        self.bg = self.Rectangle(color=(200, 200, 200, 255))
        self.bg.show()
        # But one can do the regular way, just remember to member_add()!
        # This is required by non-primitive objects, like Edje and other
        # SmartObjects
        self.child = evas.Rectangle(self.evas,
                                    color=(255, 0, 0, 255),
                                    size=(10, 10))
        self.member_add(self.child)
        self.child.show()

        self.vx, self.vy = 1, 2
        self.animator = ecore.animator_add(self._animator_cb)
示例#11
0
    def mouse_up(self, value):
        """Feeds object with mouse up event at value.

        @return: True if a click happened, False otherwise.
        """
        # If it's just a small movement and click was not cancelled yet,
        # this is a click.
        delta_first = value - self.first_value
        if abs(delta_first) < self.threshold and not self.cancel_click:
            if self.state_change:
                self.state_change(False)
            self.cancel_click = False
            return True

        # A very slow drag cause the kinetic scroll to stop.
        if self.cancel_kinetic:
            if self.animation:
                self.animation.stop()
                self.animation = None
            if self.state_change:
                self.state_change(False)
            return False

        # Set the values and create the animation
        t = ecore.time_get()
        dt = t - self.time
        dv = value - self.base_value

        self.time = t
        self.speed = dv / dt
        self.accel = -(self.speed * self.accel_constant)
        self.forced = False

        if not self.animation:
            if self.state_change:
                self.state_change(True)
            self.animation = ecore.animator_add(self._animation)

        return False
示例#12
0
    def run(self, container, end_callback=None):
        ContainerEffect.run(self, container, end_callback)

        self.setup()
        self.anim = ecore.animator_add(self.__animate, ecore.time_get())
示例#13
0
    def _start(self, func, *a):
        if self.animator is not None or not self.running:
            return

        self.remaining = -1
        self.animator = ecore.animator_add(func, *a)
示例#14
0
文件: 03-animator.py 项目: Limsik/e17
#!/usr/bin/env python

import ecore

def cb_true(n, t, a):
    print "cb_true:", n, t, a
    return True

def cb_false(n, t, a):
    print "cb_false:", n, t, a
    return False

ecore.animator_frametime_set(1.0/24.0)
assert ecore.animator_frametime_get() == 1.0/24.0

a0 = ecore.animator_add(cb_true, 123, "teste", a=456)
a1 = ecore.Animator(cb_false, 789, "bla", a="something in a")
a2 = ecore.animator_add(ecore.main_loop_quit)
print "before: a0=", a0
print "before: a1=", a1
print "before: a2=", a2

ecore.main_loop_begin()
print "main loop stopped"

print "after:  a0=", a0
print "after:  a1=", a1
print "after:  a2=", a2

a0.delete()
del a0
示例#15
0
文件: transitions.py 项目: Limsik/e17
    def run(self, container, end_callback=None):
        ContainerEffect.run(self, container, end_callback)

        self.setup()
        self.anim = ecore.animator_add(self.__animate, ecore.time_get())
示例#16
0

def cb_true(n, t, a):
    print "cb_true:", n, t, a
    return True


def cb_false(n, t, a):
    print "cb_false:", n, t, a
    return False


ecore.animator_frametime_set(1.0 / 24.0)
assert ecore.animator_frametime_get() == 1.0 / 24.0

a0 = ecore.animator_add(cb_true, 123, "teste", a=456)
a1 = ecore.Animator(cb_false, 789, "bla", a="something in a")
a2 = ecore.animator_add(ecore.main_loop_quit)
print "before: a0=", a0
print "before: a1=", a1
print "before: a2=", a2

ecore.main_loop_begin()
print "main loop stopped"

print "after:  a0=", a0
print "after:  a1=", a1
print "after:  a2=", a2

a0.delete()
del a0
示例#17
0
    obj = ee.data["obj"]
    canvas = ee.evas
    bg.size = canvas.size
    obj.center = canvas.rect.center


if __name__ == "__main__":
    ee = ecore.evas.SoftwareX11(w=800, h=600)

    canvas = ee.evas
    bg = canvas.Rectangle(color=(255, 255, 255, 255))
    bg.size = canvas.size
    bg.show()

    obj = canvas.Image(file="icon.png")
    w, h = obj.image_size
    obj.size = (w, h)
    obj.fill = (0, 0, w, h)
    obj.center = canvas.rect.center
    obj.show()

    ee.data["bg"] = bg
    ee.data["obj"] = obj
    ee.callback_resize = resize_cb

    ecore.animator_add(animate_obj, ee, obj)

    ee.show()
    ecore.animator_frametime_set(1.0 / 60.0)
    ecore.main_loop_begin()
示例#18
0
#!/usr/bin/python

import etk
import ecore

c = etk.Canvas()


w = etk.Window(title="Button", size_request=(200, 200), child=c)
w.show_all()

evas = c.toplevel_evas_get()
r = evas.Rectangle(color="#ff0000", size=(50,50))
r.show()
bla = c.object_add(r)

print bla

def mover(obj):
    (x, y) = c.child_position_get(bla)
    c.move(bla, x + 1, y + 1)
    return True

ecore.animator_add(mover, r)

def quit(obj):
    etk.main_quit()
w.on_destroyed(quit)

etk.main()
示例#19
0
 def init_ball(ball):
     ball.resize(*BALL_SIZE)
     ball.move(*canvas.rect.center)
     ball.show()
     animator_add(input_handler)
     return ball
示例#20
0
    global step
    step = -10


def pulse_animation(bg):
    global step

    r, g, b, a = bg.color
    if not 0 <= r + step < 255:
        step = -step

    r = g = b = r + step
    bg.color = (r, g, b, a)
    return True

pulser = ecore.animator_add(pulse_animation, bg)

def img_preloaded(img):
    pulse_stop()
    img.show()

img = ee.evas.Image()
img.file_set(required_image)
img.fill_set(0, 0, 780, 460)
img.geometry = (10, 10, 780, 460)
img.on_image_preloaded_add(img_preloaded)
img.preload()

ee.fullscreen = False
ee.show()
示例#21
0
    obj = ee.data["obj"]
    canvas = ee.evas
    bg.size = canvas.size
    obj.center = canvas.rect.center


if __name__ == "__main__":
    ee = ecore.evas.SoftwareX11(w=800, h=600)

    canvas = ee.evas
    bg = canvas.Rectangle(color=(255, 255, 255, 255))
    bg.size = canvas.size
    bg.show()

    obj = canvas.Image(file="icon.png")
    w, h = obj.image_size
    obj.size = (w, h)
    obj.fill = (0, 0, w, h)
    obj.center = canvas.rect.center
    obj.show()

    ee.data["bg"] = bg
    ee.data["obj"] = obj
    ee.callback_resize = resize_cb

    ecore.animator_add(animate_obj, ee, obj)

    ee.show()
    ecore.animator_frametime_set(1.0 / 60.0)
    ecore.main_loop_begin()
示例#22
0
        return True


counter2 = 0
def animator_quit_program_after_10():
    global counter2
    counter2 += 1
    print "animator_quit_program_after_10: counter=", counter2
    if counter2 == 10:
        ecore.main_loop_quit()
        return False
    else:
        return True


if __name__ == "__main__":
    # animators will run in 60 frames per second
    ecore.animator_frametime_set(1.0 / 60.0)

    ecore.animator_add(animator1, "arg1", 1234, q=890, p=567)
    ecore.animator_add(animator_run_once)
    ecore.animator_add(animator_run_once2)
    ecore.animator_add(animator_quit_program_after_10)

    # keep animator object so we can stop it from the other animator
    o = ecore.animator_add(animator2)
    ecore.animator_add(animator3, o)

    # without a main loop, animators will not work!
    ecore.main_loop_begin()