Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>#!/usr/bin/python import pyglet from time import time, sleep class Window(pyglet.window.Window): def __init__(self, refreshrate): super(Window, self).__init__(vsync = False) self.frames = 0 self.framerate = pyglet.text.Label(text='Unknown', font_name='Verdana', font_size=8, x=10, y=10, color=(255,255,255,255)) self.last = time() self.alive = 1 self.refreshrate = refreshrate self.click = None self.drag = False def on_draw(self): self.render() def on_mouse_press(self, x, y, button, modifiers): self.click = x,y def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers): if self.click: self.drag = True print 'Drag offset:',(dx,dy) def on_mouse_release(self, x, y, button, modifiers): if not self.drag and self.click: print 'You clicked here', self.click, 'Relese point:',(x,y) else: print 'You draged from', self.click, 'to:',(x,y) self.click = None self.drag = False def render(self): self.clear() if time() - self.last &gt;= 1: self.framerate.text = str(self.frames) self.frames = 0 self.last = time() else: self.frames += 1 self.framerate.draw() self.flip() def on_close(self): self.alive = 0 def run(self): while self.alive: self.render() # ----&gt; Note: &lt;---- # Without self.dispatc_events() the screen will freeze # due to the fact that i don't call pyglet.app.run(), # because i like to have the control when and what locks # the application, since pyglet.app.run() is a locking call. event = self.dispatch_events() sleep(1.0/self.refreshrate) win = Window(23) # set the fps win.run() </code></pre> <p>Short description:</p> <ul> <li>Keep track of the current mouse state within the window</li> <li>Keep track of startpoint of mouse event</li> <li>At mouse release, do waht you want to do or update whatever it is within the drag.</li> </ul> <p>I know it's an old question, but it's under the "unanswered" so hoping to get it resolved and out of the list.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload