*** empty log message ***

This commit is contained in:
Mark Mine 2001-08-22 00:11:54 +00:00
parent 501ee98985
commit f60b899fda
5 changed files with 85 additions and 15 deletions

View File

@ -1,5 +1,11 @@
from DirectFrame import *
# DirectButton States:
BUTTON_READY_STATE = PGButton.SReady # 0
BUTTON_DEPRESSED_STATE = PGButton.SDepressed # 1
BUTTON_ROLLOVER_STATE = PGButton.SRollover # 2
BUTTON_INACTIVE_STATE = PGButton.SInactive # 3
class DirectButton(DirectFrame):
"""
DirectButton(parent) - Create a DirectGuiWidget which responds

View File

@ -1,5 +1,10 @@
from DirectFrame import *
# DirectEntry States:
ENTRY_FOCUS_STATE = PGEntry.SFocus # 0
ENTRY_NO_FOCUS_STATE = PGEntry.SNoFocus # 1
ENTRY_INACTIVE_STATE = PGEntry.SInactive # 2
class DirectEntry(DirectFrame):
"""
DirectEntry(parent) - Create a DirectGuiWidget which responds
@ -18,12 +23,16 @@ class DirectEntry(DirectFrame):
# 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),
('pgFunc', PGEntry, None),
('numStates', 3, None),
('font', getDefaultFont(), self.setFont),
('width', 10, self.setup),
('numLines', 5, self.setup),
('focus', 0, self.setFocus),
('initialText', '', INITOPT),
# Command to be called on hitting Enter
('command', None, None),
('extraArgs', [], None),
# Sounds to be used for button events
('rolloverSound', getDefaultRolloverSound(), self.setRolloverSound),
)
@ -33,17 +42,24 @@ class DirectEntry(DirectFrame):
# Initialize superclasses
DirectFrame.__init__(self, parent)
# Bind command function
self.bind(ACCEPT, self.commandFunc)
# Call option initialization functions
self.initialiseoptions(DirectEntry)
# Update entry if init text specified
if self['initialText']:
self.guiItem.setText(self['initialText'])
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 setFocus(self):
PGEntry.setFocus(self.guiItem, self['focus'])
def setRolloverSound(self):
if base.wantSfx:
@ -53,4 +69,15 @@ class DirectEntry(DirectFrame):
else:
self.guiItem.clearSound(ENTER + self.guiId)
def commandFunc(self, event):
if self['command']:
# Pass any extra args to command
apply(self['command'], [self.get()] + self['extraArgs'])
def set(self, text):
self.guiItem.setText(text)
def get(self):
return self.guiItem.getText()

View File

@ -827,18 +827,23 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
# To force an update of the button
self.guiItem.getStateDef(0)
# Clear out frame before computing bounds
self.stateNodePath[0].calcTightBounds(self.ll, self.ur)
# Scale bounds to give a pad around graphics
self.bounds = (self.ll[0] - self['pad'][0],
self.ur[0] + self['pad'][0],
self.ll[2] - self['pad'][1],
self.ur[2] + self['pad'][1])
self.getBounds()
# Restore frame style if necessary
if (frameType != PGFrameStyle.TNone):
self.frameStyle[0].setType(frameType)
self.guiItem.setFrameStyle(0, self.frameStyle[0])
# Set frame to new dimensions
self.guiItem.setFrame(self.bounds[0], self.bounds[1],self.bounds[2], self.bounds[3])
self.guiItem.setFrame(self.bounds[0], self.bounds[1],
self.bounds[2], self.bounds[3])
def getBounds(self, state = 0):
self.stateNodePath[state].calcTightBounds(self.ll, self.ur)
# Scale bounds to give a pad around graphics
self.bounds = (self.ll[0] - self['pad'][0],
self.ur[0] + self['pad'][0],
self.ll[2] - self['pad'][1],
self.ur[2] + self['pad'][1])
return self.bounds
def getWidth(self):
return self.bounds[1] - self.bounds[0]
@ -846,6 +851,11 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
def getHeight(self):
return self.bounds[3] - self.bounds[2]
def getCenter(self):
x = self.bounds[0] + (self.bounds[1] - self.bounds[0])/2.0
y = self.bounds[2] + (self.bounds[3] - self.bounds[2])/2.0
return (x,y)
def updateFrameStyle(self):
if not self.fInit:
for i in range(self['numStates']):

View File

@ -48,6 +48,9 @@ B3PRESS = PGButton.getPressPrefix() + MouseButton.three().getName() + '-'
B1RELEASE = PGButton.getReleasePrefix() + MouseButton.one().getName() + '-'
B2RELEASE = PGButton.getReleasePrefix() + MouseButton.two().getName() + '-'
B3RELEASE = PGButton.getReleasePrefix() + MouseButton.three().getName() + '-'
# For DirectEntry widgets
OVERFLOW = PGEntry.getOverflowPrefix()
ACCEPT = PGEntry.getAcceptPrefix() + KeyboardButton.enter().getName() + '-'
# For setting the sorting order of a widget's visible components
IMAGE_SORT_INDEX = 10

View File

@ -80,3 +80,27 @@ for i in range(10):
# To get rid of button and clear out hooks call:
# db.destroy()
# DIRECT ENTRY EXAMPLE
def printEntryText(text):
print 'Text:', text
# Here we create an entry, and specify everything up front
# CALL de1.get() and de1.set('new text') to get and set entry contents
de1 = DirectEntry(initialText = 'Hello, how are you?',
image = 'phase_3/maps/hotel-room.jpg',
image_pos = (4.55, 0, -1.65),
image_scale = (5.5, 1, 2.55),
command = printEntryText,
pos = (-1.1875, 0, 0.879167),
scale = 0.0707855,
)
# NOTE: There are some utility functions which help you get size
# of a direct gui widget. These can be used to position and scale an
# image after you've created the entry. scale = (width/2, 1, height/2)
print 'BOUNDS:', de1.getBounds()
print 'WIDTH:', de1.getWidth()
print 'HEIGHT:', de1.getHeight()
print 'CENTER:', de1.getCenter()