mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
*** empty log message ***
This commit is contained in:
parent
88d5abcd22
commit
48e648eccf
@ -1,5 +1,4 @@
|
||||
from DirectFrame import *
|
||||
import GuiGlobals
|
||||
|
||||
class DirectButton(DirectFrame):
|
||||
"""
|
||||
@ -20,17 +19,17 @@ class DirectButton(DirectFrame):
|
||||
# Responds to click event and calls command if None
|
||||
optiondefs = (
|
||||
# Define type of DirectGuiWidget
|
||||
('pgFunc', PGButton, None),
|
||||
('numStates', 4, None),
|
||||
('invertedFrames', (1,), None),
|
||||
('pgFunc', PGButton, None),
|
||||
('numStates', 4, None),
|
||||
('invertedFrames', (1,), None),
|
||||
# Command to be called on button click
|
||||
('command', None, None),
|
||||
('extraArgs', [], None),
|
||||
('command', None, None),
|
||||
('extraArgs', [], None),
|
||||
# Which mouse buttons can be used to click the button
|
||||
('commandButtons', (LMB,), self.setCommandButtons),
|
||||
('commandButtons', (LMB,), self.setCommandButtons),
|
||||
# Sounds to be used for button events
|
||||
('rolloverSound', GuiGlobals.getDefaultRolloverSound(), self.setRolloverSound),
|
||||
('clickSound', GuiGlobals.getDefaultClickSound(), self.setClickSound),
|
||||
('rolloverSound', getDefaultRolloverSound(), self.setRolloverSound),
|
||||
('clickSound', getDefaultClickSound(), self.setClickSound),
|
||||
# Can only be specified at time of widget contruction
|
||||
# Do the text/graphics appear to move when the button is clicked
|
||||
('pressEffect', 1, INITOPT),
|
||||
|
||||
56
direct/src/gui/DirectEntry.py
Normal file
56
direct/src/gui/DirectEntry.py
Normal file
@ -0,0 +1,56 @@
|
||||
from DirectFrame import *
|
||||
|
||||
class DirectEntry(DirectFrame):
|
||||
"""
|
||||
DirectEntry(parent) - Create a DirectGuiWidget which responds
|
||||
to keyboard buttons
|
||||
"""
|
||||
def __init__(self, parent = guiTop, **kw):
|
||||
# Inherits from DirectFrame
|
||||
# A Direct Frame can have:
|
||||
# - A background texture (pass in path to image, or Texture Card)
|
||||
# - A midground geometry item (pass in geometry)
|
||||
# - A foreground text Node (pass in text string or Onscreen Text)
|
||||
# For a direct entry:
|
||||
# Each button has 3 states (focus, noFocus, disabled)
|
||||
# The same image/geom/text can be used for all three states or each
|
||||
# state can have a different text/geom/image
|
||||
# State transitions happen automatically based upon mouse interaction
|
||||
optiondefs = (
|
||||
# Define type of DirectGuiWidget
|
||||
('pgFunc', PGEntry, None),
|
||||
('numStates', 3, None),
|
||||
('font', getDefaultFont(), self.setFont),
|
||||
('width', 10, self.setup),
|
||||
('numLines', 5, self.setup),
|
||||
('contents', '', self.setContents),
|
||||
# Sounds to be used for button events
|
||||
('rolloverSound', getDefaultRolloverSound(), self.setRolloverSound),
|
||||
)
|
||||
# Merge keyword options with default options
|
||||
self.defineoptions(kw, optiondefs)
|
||||
|
||||
# Initialize superclasses
|
||||
DirectFrame.__init__(self, parent)
|
||||
|
||||
# Call option initialization functions
|
||||
self.initialiseoptions(DirectEntry)
|
||||
|
||||
def setup(self):
|
||||
self.node().setup(self['width'], self['numLines'])
|
||||
|
||||
def setFont(self):
|
||||
self.guiItem.getTextNode().setFont(self['font'])
|
||||
|
||||
def setContents(self):
|
||||
self.guiItem.setText(self['contents'])
|
||||
|
||||
def setRolloverSound(self):
|
||||
if base.wantSfx:
|
||||
rolloverSound = self['rolloverSound']
|
||||
if rolloverSound:
|
||||
self.guiItem.setSound(ENTER + self.guiId, rolloverSound)
|
||||
else:
|
||||
self.guiItem.clearSound(ENTER + self.guiId)
|
||||
|
||||
|
||||
@ -3,10 +3,14 @@ from DirectGuiGlobals import *
|
||||
# Initialize global variable guiTop
|
||||
import __builtin__
|
||||
__builtin__.guiTop = aspect2d.attachNewNode(PGTop('DirectGuiTop'))
|
||||
guiTop.node().setMouseWatcher(base.mouseWatcher.node())
|
||||
guiTop.node().setMouseWatcher(base.mouseWatcherNode)
|
||||
|
||||
# Set up default font
|
||||
PGItem.getTextNode().setFont(getDefaultFont())
|
||||
|
||||
# Direct Gui Classes
|
||||
from DirectFrame import *
|
||||
from DirectButton import *
|
||||
from DirectEntry import *
|
||||
from DirectLabel import *
|
||||
from DirectScrolledList import *
|
||||
|
||||
@ -748,7 +748,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
||||
self.bind(B2RELEASE, self.editStop)
|
||||
self.bind(PRINT, self.printConfig)
|
||||
mb = base.mouseWatcherNode.getModifierButtons()
|
||||
mb.addButton(KeyboardButton.alt())
|
||||
mb.addButton(KeyboardButton.control())
|
||||
base.mouseWatcherNode.setModifierButtons(mb)
|
||||
|
||||
def disableEdit(self):
|
||||
@ -756,7 +756,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
||||
self.unbind(B2RELEASE)
|
||||
self.unbind(PRINT)
|
||||
mb = base.mouseWatcherNode.getModifierButtons()
|
||||
mb.removeButton(KeyboardButton.alt())
|
||||
mb.removeButton(KeyboardButton.control())
|
||||
base.mouseWatcherNode.setModifierButtons(mb)
|
||||
|
||||
def editStart(self, event):
|
||||
@ -765,7 +765,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
||||
vMouse2render2d = Point3(event.getMouse()[0], 0, event.getMouse()[1])
|
||||
editVec = Vec3(vWidget2render2d - vMouse2render2d)
|
||||
if base.mouseWatcherNode.getModifierButtons().isDown(
|
||||
KeyboardButton.alt()):
|
||||
KeyboardButton.control()):
|
||||
t = taskMgr.spawnMethodNamed(self.guiScaleTask, 'guiEditTask')
|
||||
t.refPos = vWidget2render2d
|
||||
t.editVecLen = editVec.length()
|
||||
|
||||
@ -4,12 +4,6 @@ that can be used during widget construction
|
||||
"""
|
||||
|
||||
from PandaModules import *
|
||||
#from PGTop import *
|
||||
#from PGButton import *
|
||||
# Import these after PGButton to get actual class definitions
|
||||
#from PGItem import *
|
||||
#from PGFrameStyle import *
|
||||
# Helper classes used as components of Direct Gui Widgets
|
||||
import OnscreenText
|
||||
import OnscreenGeom
|
||||
import OnscreenImage
|
||||
@ -60,3 +54,34 @@ IMAGE_SORT_INDEX = 10
|
||||
GEOM_SORT_INDEX = 20
|
||||
TEXT_SORT_INDEX = 30
|
||||
|
||||
defaultFont = None
|
||||
defaultClickSound = None
|
||||
defaultRolloverSound = None
|
||||
|
||||
def getDefaultRolloverSound():
|
||||
global defaultRolloverSound
|
||||
if not base.wantSfx:
|
||||
return None
|
||||
if defaultRolloverSound == None:
|
||||
defaultRolloverSound = base.loadSfx(
|
||||
"phase_3/audio/sfx/GUI_rollover.mp3")
|
||||
return defaultRolloverSound
|
||||
|
||||
def getDefaultClickSound():
|
||||
global defaultClickSound
|
||||
if not base.wantSfx:
|
||||
return None
|
||||
if defaultClickSound == None:
|
||||
defaultClickSound = base.loadSfx(
|
||||
"phase_3/audio/sfx/GUI_create_toon_fwd.mp3")
|
||||
return defaultClickSound
|
||||
|
||||
def getDefaultFont():
|
||||
global defaultFont
|
||||
if defaultFont == None:
|
||||
defaultFont = loader.loadFont("models/fonts/Comic")
|
||||
return defaultFont
|
||||
|
||||
def setDefaultFont(newFont):
|
||||
global defaultFont
|
||||
defaultFont = newFont
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
from DirectGui import *
|
||||
from whrandom import *
|
||||
from GuiGlobals import getDefaultClickSound
|
||||
from GuiGlobals import getDefaultRolloverSound
|
||||
|
||||
# EXAMPLE CODE
|
||||
# Load a model
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user