示例#1
0
 def wheelEvent(self, event):
     ang = event.angleDelta().y()
     if ang > 0:
         self.inputDevice.buttonDown(MouseButton.wheelUp())
         self.inputDevice.buttonUp(MouseButton.wheelUp())
     else:
         self.inputDevice.buttonDown(MouseButton.wheelDown())
         self.inputDevice.buttonUp(MouseButton.wheelDown())
     QtWidgets.QWidget.wheelEvent(self, event)
示例#2
0
from direct.stdpy import pickle
import direct.gui.DirectGuiGlobals as DGG
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectFrame import DirectFrame
from direct.gui.DirectButton import DirectButton
from direct.gui.DirectScrolledFrame import DirectScrolledFrame

from runtime_data import game_settings
from sogal_form import SogalForm, SogalDialog
from gui.layout import HLayout, VLayout
import gui.color_themes as color_themes
from sogal_form import ConfirmDialog
import runtime_data

WHEELUP = PGButton.getReleasePrefix() + MouseButton.wheelUp().getName() + '-'
WHEELDOWN = PGButton.getReleasePrefix() + MouseButton.wheelDown().getName(
) + '-'
WHEELLEFT = PGButton.getReleasePrefix() + MouseButton.wheelLeft().getName(
) + '-'
WHEELRIGHT = PGButton.getReleasePrefix() + MouseButton.wheelRight().getName(
) + '-'

#pos = (-0.57,0,0.67)
MAX_SAVE = 200
hspacing = 1.33
vspacing = 0.4
FRAMESIZE = (-1.35, 1.35, -0.95, 0.95)
LOAD_CANVAS_SIZE = (
    -0.05, 2.55,
    math.ceil(
        -vspacing *
        (MAX_SAVE + runtime_data.MAX_AUTOSAVE + runtime_data.MAX_QUICKSAVE) /
示例#3
0
class DialogMask(DirectButton):
    '''used to generate a full-screen mask to prevent button-clicking below the focused window/dialog
    Added some tricks to make panda3d mouse events still available
    '''
    B1PRESS = PGButton.getPressPrefix() + MouseButton.one().getName() + '-'
    B2PRESS = PGButton.getPressPrefix() + MouseButton.two().getName() + '-'
    B3PRESS = PGButton.getPressPrefix() + MouseButton.three().getName() + '-'
    B4PRESS = PGButton.getPressPrefix() + MouseButton.four().getName() + '-'
    B5PRESS = PGButton.getPressPrefix() + MouseButton.five().getName() + '-'
    WHEELUP = PGButton.getReleasePrefix() + MouseButton.wheelUp().getName(
    ) + '-'
    WHEELDOWN = PGButton.getReleasePrefix() + MouseButton.wheelDown().getName(
    ) + '-'
    WHEELLEFT = PGButton.getReleasePrefix() + MouseButton.wheelLeft().getName(
    ) + '-'
    WHEELRIGHT = PGButton.getReleasePrefix() + MouseButton.wheelRight(
    ).getName() + '-'
    B1RELEASE = PGButton.getReleasePrefix() + MouseButton.one().getName() + '-'
    B2RELEASE = PGButton.getReleasePrefix() + MouseButton.two().getName() + '-'
    B3RELEASE = PGButton.getReleasePrefix() + MouseButton.three().getName(
    ) + '-'
    B4RELEASE = PGButton.getReleasePrefix() + MouseButton.four().getName(
    ) + '-'
    B5RELEASE = PGButton.getReleasePrefix() + MouseButton.five().getName(
    ) + '-'

    def __init__(self):
        DirectButton.__init__(self,
                              parent=aspect2d,
                              frameColor=(1, 1, 1, 0),
                              relief=DGG.FLAT,
                              commandButtons=[])
        self.accept('window-event', self.windowResize)
        self.windowResize(None)
        #trick: make this re-throw mouse events
        self.bind(self.B1PRESS, self.rethrowEvent, ['mouse1'])
        self.bind(self.B2PRESS, self.rethrowEvent, ['mouse2'])
        self.bind(self.B3PRESS, self.rethrowEvent, ['mouse3'])
        self.bind(self.B4PRESS, self.rethrowEvent, ['mouse4'])
        self.bind(self.B5PRESS, self.rethrowEvent, ['mouse5'])

        self.bind(self.WHEELUP, self.rethrowEvent, ['wheel_up'])
        self.bind(self.WHEELDOWN, self.rethrowEvent, ['wheel_down'])
        self.bind(self.WHEELLEFT, self.rethrowEvent, ['wheel_left'])
        self.bind(self.WHEELRIGHT, self.rethrowEvent, ['wheel_right'])

        self.bind(self.B1RELEASE, self.rethrowEvent, ['mouse1-up'])
        self.bind(self.B2RELEASE, self.rethrowEvent, ['mouse2-up'])
        self.bind(self.B3RELEASE, self.rethrowEvent, ['mouse3-up'])
        self.bind(self.B4RELEASE, self.rethrowEvent, ['mouse4-up'])
        self.bind(self.B5RELEASE, self.rethrowEvent, ['mouse5-up'])

    def windowResize(self, arg):
        #fill the screen
        aspect = base.getAspectRatio()
        if aspect > 1:
            self['frameSize'] = (-aspect, aspect, -1, 1)
        elif aspect:
            hh = 1.0 / aspect
            self['frameSize'] = (-1, 1, -hh, hh)

    def setCommandButtons(self, *args, **kwargs):
        #inherited
        pass

    def rethrowEvent(self, sevent, event):
        messenger.send(sevent)

    def destroy(self):
        self.ignoreAll()
        DirectButton.destroy(self)
示例#4
0
    def __init__(self, name):
        NodePath.__init__(self, name)
        DirectObject.__init__(self)
        self.setPythonTag('Sprite', self)

        global SpriteCounter
        SpriteCounter += 1
        self.__id = int(SpriteCounter)

        #- Use PGItem to detect mouse and keyboard input via PGTop (eg, aspect2d, pixel2d, etc)
        self.__pgItem = PGItem(name)
        self.__pgItem.setActive(True)
        self.__pgItemNp = self.attachNewNode(self.__pgItem)

        #- Use TextNode to generate both text and cards for displaying background images
        self.__textNode = TextNode(name)
        self.__textNodeNp = None
        #self.__textNodeNp = self.attachNewNode(self.__textNode)
        #self.__textNode.setCardDecal(True) #- This is what we would do, should Sprite support being non-under PGTop

        self.accept(self.__pgItem.getPressEvent(MouseButton.one()),
                    self.__onMouse, [Sprite.MouseLeftDown])
        self.accept(self.__pgItem.getPressEvent(MouseButton.two()),
                    self.__onMouse, [Sprite.MouseCenterDown])
        self.accept(self.__pgItem.getPressEvent(MouseButton.three()),
                    self.__onMouse, [Sprite.MouseRightDown])
        self.accept(self.__pgItem.getPressEvent(MouseButton.four()),
                    self.__onMouse, [Sprite.MouseFourDown])
        self.accept(self.__pgItem.getPressEvent(MouseButton.five()),
                    self.__onMouse, [Sprite.MouseFiveDown])

        self.accept(self.__pgItem.getReleaseEvent(MouseButton.one()),
                    self.__onMouse, [Sprite.MouseLeftUp])
        self.accept(self.__pgItem.getReleaseEvent(MouseButton.two()),
                    self.__onMouse, [Sprite.MouseCenterUp])
        self.accept(self.__pgItem.getReleaseEvent(MouseButton.three()),
                    self.__onMouse, [Sprite.MouseRightUp])
        self.accept(self.__pgItem.getReleaseEvent(MouseButton.four()),
                    self.__onMouse, [Sprite.MouseFourUp])
        self.accept(self.__pgItem.getReleaseEvent(MouseButton.five()),
                    self.__onMouse, [Sprite.MouseFiveUp])

        self.accept(self.__pgItem.getPressEvent(MouseButton.wheelDown()),
                    self.__onMouse, [Sprite.MouseScrollDown])
        self.accept(self.__pgItem.getPressEvent(MouseButton.wheelUp()),
                    self.__onMouse, [Sprite.MouseScrollUp])

        self.accept(self.__pgItem.getEnterEvent(), self.__onMouse,
                    [Sprite.MouseEnter])
        self.accept(self.__pgItem.getExitEvent(), self.__onMouse,
                    [Sprite.MouseExit])
        self.accept(self.__pgItem.getWithinEvent(), self.__onMouse,
                    [Sprite.MouseWithin])
        self.accept(self.__pgItem.getWithoutEvent(), self.__onMouse,
                    [Sprite.MouseWithout])

        self.__beastDebug = ConfigVariableBool('beast-debug', False).getValue()

        self.__mouseInside = False
        self.__disabled = False

        #- Setup state configuration
        self.__lastStateOptions = None
        self.__state = None
        self.__states = {
            'default': SpriteOptions(),
            'hover': SpriteOptions(),
            'click': SpriteOptions(),
            'focus': SpriteOptions(),
            'disabled': SpriteOptions(),
        }
        self.updateToState('default')
示例#5
0
class _beastGlobals(DirectObject):
    enter = PGButton.getEnterPrefix()
    exit = PGButton.getExitPrefix()
    within = PGButton.getWithinPrefix()
    without = PGButton.getWithoutPrefix()
    leftPress = PGButton.getPressPrefix() + MouseButton.one().getName() + '-'
    centerPress = PGButton.getPressPrefix() + MouseButton.two().getName() + '-'
    rightPress = PGButton.getPressPrefix() + MouseButton.three().getName(
    ) + '-'
    leftClick = PGButton.getClickPrefix() + MouseButton.one().getName() + '-'
    centerClick = PGButton.getClickPrefix() + MouseButton.two().getName() + '-'
    rightClick = PGButton.getClickPrefix() + MouseButton.three().getName(
    ) + '-'
    leftRelease = PGButton.getReleasePrefix() + MouseButton.one().getName(
    ) + '-'
    centerRelease = PGButton.getReleasePrefix() + MouseButton.two().getName(
    ) + '-'
    rightRelease = PGButton.getReleasePrefix() + MouseButton.three().getName(
    ) + '-'
    wheelUp = PGButton.getPressPrefix() + MouseButton.wheelUp().getName() + '-'
    wheelDown = PGButton.getPressPrefix() + MouseButton.wheelDown().getName(
    ) + '-'

    def __init__(self, taskMgr, base):
        DirectObject.__init__(self)
        self.taskMgr = taskMgr
        self.base = base
        self.setupPoint2d()

        self.beastPointSize = ConfigVariableDouble('beast-point-size',
                                                   1.0).getValue()
        self.beastPointSizeAuto = ConfigVariableBool('beast-point-size-auto',
                                                     False).getValue()
        self.beastRenderBruteForce = ConfigVariableBool(
            'beast-render-brute-force', False).getValue()
        self.beastRenderDebug = ConfigVariableBool('beast-render-debug',
                                                   False).getValue()

        self.setPointSize(self.beastPointSize, update=False)
        self.setPointSizeAuto(self.beastPointSizeAuto, update=False)
        self.accept('window-event', self.windowEvent)
        self.originalResolution = (float(self.base.win.getXSize()),
                                   float(self.base.win.getYSize()))

        self.buffer = None
        #- If bruteForce == False then we will setup beast frame rendering system
        if self.beastRenderBruteForce == False:
            self._setupTextureBuffer()
            taskMgr.add(self.renderTask, 'beastRender', sort=-100000000)

        self.windowEvent()

    def _setupTextureBuffer(self):
        if self.buffer:
            self.card.remove()
            self.camera2d.remove()
            self.base.graphicsEngine.removeWindow(self.buffer)

        self.buffer = self.base.win.makeTextureBuffer("beastBuffer",
                                                      self.base.win.getXSize(),
                                                      self.base.win.getYSize())
        self.buffer.setActive(True)
        self.buffer.getTexture().setOrigFileSize(self.base.win.getXSize(),
                                                 self.base.win.getYSize())

        self.camera2d = self.base.makeCamera2d(self.buffer)
        self.camera2d.reparentTo(self.point2d.getParent())

        cm = CardMaker('beastDisplay')
        cm.setFrame(-1, 1, -1, 1)
        cm.setUvRange(self.buffer.getTexture())
        self.card = self.base.render2d.attachNewNode(cm.generate())
        self.card.setTransparency(TransparencyAttrib.MAlpha)
        self.card.setTexture(self.buffer.getTexture())

    def renderTask(self, task):
        if self.point2d.getRequiresUpdate():
            debug = self.beastRenderBruteForce == False and self.beastRenderDebug == True
            if debug:
                print ':beast::render'
            self.buffer.setActive(True)
            self.point2d.setRequiresUpdate(False)
        else:
            self.buffer.setActive(False)
        return task.cont

    def setupPoint2d(self):
        fakeRender2d = NodePath('render2d')
        fakeRender2d.setDepthTest(False)
        fakeRender2d.setDepthWrite(False)
        fakeRender2d.setMaterialOff(True)
        fakeRender2d.setTwoSided(True)

        self.point2d = beastNodePath(PGTop('point2d'))
        self.point2d.reparentTo(fakeRender2d)
        self.point2d.node().setMouseWatcher(self.base.mouseWatcherNode)

        self.p2dTopLeft = self.point2d.attachNewNode('p2dTopLeft')
        self.p2dTopRight = self.point2d.attachNewNode('p2dTopRight')
        self.p2dTopCenter = self.point2d.attachNewNode('p2dTopCenter')

        self.p2dCenterLeft = self.point2d.attachNewNode('p2dCenterLeft')
        self.p2dCenterRight = self.point2d.attachNewNode('p2dCenterRight')

        self.p2dBottomLeft = self.point2d.attachNewNode('p2dBottomLeft')
        self.p2dBottomRight = self.point2d.attachNewNode('p2dBottomRight')
        self.p2dBottomCenter = self.point2d.attachNewNode('p2dBottomCenter')

    def getMousePos(self):
        md = self.win.getPointer(0)
        x = md.getX()
        y = md.getY()
        p = self.point2d.getRelativePoint(self.pixel2d, (x, 0, -y))
        return p.getX(), p.getZ()

    def hasMouse(self):
        return self.mouseWatcherNode.hasMouse()

    def getAbsolutePointSize(self):
        fakePointSize = None
        if self.getPointSizeAuto():
            oldX, oldY = self.originalResolution
            newX, newY = float(self.win.getXSize()), float(self.win.getYSize())
            ratio = newY / oldY
            fakePointSize = ratio

        if self.getPointSizeAuto():
            ps = fakePointSize
        else:
            ps = self.getPointSize()
        return ps

    def windowEvent(self, win=None):
        ps = self.getAbsolutePointSize()
        x = self.base.win.getXSize()
        y = self.base.win.getYSize()

        xActual = (x / ps)
        yActual = (y / ps)
        self.point2d.setScale(2.0 / xActual, 1.0, 2.0 / yActual)

        #- Finish actuals
        self.p2dTopLeft.setPos(-xActual / 2.0, 1.0, yActual / 2.0)
        self.p2dTopRight.setPos(xActual / 2.0, 1.0, yActual / 2.0)
        self.p2dTopCenter.setPos(0, 1.0, yActual / 2.0)

        self.p2dCenterLeft.setPos(-xActual / 2.0, 1.0, 0.0)
        self.p2dCenterRight.setPos(xActual / 2.0, 1.0, 0.0)

        self.p2dBottomLeft.setPos(-xActual / 2.0, 1.0, -yActual / 2.0)
        self.p2dBottomRight.setPos(xActual / 2.0, 1.0, -yActual / 2.0)
        self.p2dBottomCenter.setPos(0, 1.0, -yActual / 2.0)

        if self.beastRenderBruteForce == False:
            debug = self.beastRenderBruteForce == False and self.beastRenderDebug == True
            bx = self.buffer.getTexture().getOrigFileXSize()
            by = self.buffer.getTexture().getOrigFileYSize()
            cx = self.base.win.getXSize()
            cy = self.base.win.getYSize()
            if bx != cx or by != by:
                if debug:
                    print ':beast::render::resolutionChanged from(%s, %s) to(%s, %s)' % (
                        bx, by, cx, cy)
                self._setupTextureBuffer()
        messenger.send('beast.windowEvent')

    ''' Point size '''

    def getPointSize(self):
        return self.pointSize

    def setPointSize(self, value, update=True):
        self.pointSize = float(value)
        if update:
            self.update()

    ''' Point size auto resolution '''

    def setPSAutoResolution(self, x, y):
        self.originalResolution = (float(base.win.getXSize()),
                                   float(base.win.getYSize()))

    def getPSAutoResolution(self):
        return self.originalResolution

    ''' Point size auto '''

    def setPointSizeAuto(self, value, update=True):
        self.pointSizeAuto = bool(value)
        if update:
            self.update()

    def getPointSizeAuto(self):
        return self.pointSizeAuto

    def togglePointSizeAuto(self):
        if self.getPointSizeAuto():
            self.setPointSizeAuto(False)
        else:
            self.setPointSizeAuto(True)

    ''' Data folder '''

    def getDataFolder(self):
        if sys.platform.startswith('win'):
            slash = '\\'
        else:
            slash = '/'
        point = __file__.rindex(slash)
        f = __file__[:point] + slash + 'data' + slash
        return Filename().fromOsSpecific(f).getFullpath()

    ''' Destroy beast now '''

    def destroy(self):
        self.ignoreAll()
示例#6
0
import direct.gui.DirectGuiGlobals as DGG
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectFrame import DirectFrame
from direct.gui.DirectButton import DirectButton
from direct.gui.DirectScrolledFrame import DirectScrolledFrame


from runtime_data import game_settings
from sogal_form import SogalForm,SogalDialog
from gui.layout import HLayout,VLayout
import gui.color_themes as color_themes
from sogal_form import ConfirmDialog
import runtime_data

WHEELUP = PGButton.getReleasePrefix() + MouseButton.wheelUp().getName() + '-'
WHEELDOWN = PGButton.getReleasePrefix() + MouseButton.wheelDown().getName() + '-'
WHEELLEFT = PGButton.getReleasePrefix() + MouseButton.wheelLeft().getName() + '-'
WHEELRIGHT = PGButton.getReleasePrefix() + MouseButton.wheelRight().getName() + '-'

#pos = (-0.57,0,0.67)
MAX_SAVE = 200
hspacing = 1.33
vspacing = 0.4
FRAMESIZE = (-1.35,1.35,-0.95,0.95)
LOAD_CANVAS_SIZE = (-0.05,2.55,math.ceil( -vspacing*(MAX_SAVE +runtime_data.MAX_AUTOSAVE + runtime_data.MAX_QUICKSAVE)/2.0 ) ,vspacing/2)
SAVE_CANVAS_SIZE = (-0.05,2.55,math.ceil(-vspacing*MAX_SAVE/2.0) ,vspacing/2)
LOAD_ROLL_SPEED = -LOAD_CANVAS_SIZE[2]/5100.0
SAVE_ROLL_SPEED = -SAVE_CANVAS_SIZE[2]/5100.0
AUTO_HIDE_SCROLLBARS = True