Skip to content

Commit 847ebf6

Browse files
committed
Merge branch 'release/1.10.x'
2 parents 856754a + e6fc6c6 commit 847ebf6

File tree

5 files changed

+99
-11
lines changed

5 files changed

+99
-11
lines changed

direct/src/gui/DirectOptionMenu.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
__all__ = ['DirectOptionMenu']
88

99
from panda3d.core import *
10+
from direct.showbase import ShowBaseGlobal
1011
from . import DirectGuiGlobals as DGG
1112
from .DirectButton import *
1213
from .DirectLabel import *
1314
from .DirectFrame import *
1415

16+
1517
class DirectOptionMenu(DirectButton):
1618
"""
1719
DirectOptionMenu(parent) - Create a DirectButton which pops up a
@@ -72,6 +74,10 @@ def __init__(self, parent = None, **kw):
7274
self.popupMenu = None
7375
self.selectedIndex = None
7476
self.highlightedIndex = None
77+
if 'item_text_scale' in kw:
78+
self._prevItemTextScale = kw['item_text_scale']
79+
else:
80+
self._prevItemTextScale = (1,1)
7581
# A big screen encompassing frame to catch the cancel clicks
7682
self.cancelFrame = self.createcomponent(
7783
'cancelframe', (), None,
@@ -218,27 +224,27 @@ def showPopupMenu(self, event = None):
218224
self.popupMenu.setZ(
219225
self, self.minZ + (self.selectedIndex + 1)*self.maxHeight)
220226
# Make sure the whole popup menu is visible
221-
pos = self.popupMenu.getPos(render2d)
222-
scale = self.popupMenu.getScale(render2d)
227+
pos = self.popupMenu.getPos(ShowBaseGlobal.render2d)
228+
scale = self.popupMenu.getScale(ShowBaseGlobal.render2d)
223229
# How are we doing relative to the right side of the screen
224230
maxX = pos[0] + fb[1] * scale[0]
225231
if maxX > 1.0:
226232
# Need to move menu to the left
227-
self.popupMenu.setX(render2d, pos[0] + (1.0 - maxX))
233+
self.popupMenu.setX(ShowBaseGlobal.render2d, pos[0] + (1.0 - maxX))
228234
# How about up and down?
229235
minZ = pos[2] + fb[2] * scale[2]
230236
maxZ = pos[2] + fb[3] * scale[2]
231237
if minZ < -1.0:
232238
# Menu too low, move it up
233-
self.popupMenu.setZ(render2d, pos[2] + (-1.0 - minZ))
239+
self.popupMenu.setZ(ShowBaseGlobal.render2d, pos[2] + (-1.0 - minZ))
234240
elif maxZ > 1.0:
235241
# Menu too high, move it down
236-
self.popupMenu.setZ(render2d, pos[2] + (1.0 - maxZ))
242+
self.popupMenu.setZ(ShowBaseGlobal.render2d, pos[2] + (1.0 - maxZ))
237243
# Also display cancel frame to catch clicks outside of the popup
238244
self.cancelFrame.show()
239245
# Position and scale cancel frame to fill entire window
240-
self.cancelFrame.setPos(render2d, 0, 0, 0)
241-
self.cancelFrame.setScale(render2d, 1, 1, 1)
246+
self.cancelFrame.setPos(ShowBaseGlobal.render2d, 0, 0, 0)
247+
self.cancelFrame.setScale(ShowBaseGlobal.render2d, 1, 1, 1)
242248

243249
def hidePopupMenu(self, event = None):
244250
""" Put away popup and cancel frame """
@@ -247,6 +253,7 @@ def hidePopupMenu(self, event = None):
247253

248254
def _highlightItem(self, item, index):
249255
""" Set frame color of highlighted item, record index """
256+
self._prevItemTextScale = item['text_scale']
250257
item['frameColor'] = self['highlightColor']
251258
item['frameSize'] = (self['highlightScale'][0]*self.minX, self['highlightScale'][0]*self.maxX, self['highlightScale'][1]*self.minZ, self['highlightScale'][1]*self.maxZ)
252259
item['text_scale'] = self['highlightScale']
@@ -256,7 +263,7 @@ def _unhighlightItem(self, item, frameColor):
256263
""" Clear frame color, clear highlightedIndex """
257264
item['frameColor'] = frameColor
258265
item['frameSize'] = (self.minX, self.maxX, self.minZ, self.maxZ)
259-
item['text_scale'] = (1,1)
266+
item['text_scale'] = self._prevItemTextScale
260267
self.highlightedIndex = None
261268

262269
def selectHighlightedIndex(self, event = None):

direct/src/showbase/ShowBase.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ def destroy(self):
543543
del ShowBaseGlobal.base
544544

545545
self.aspect2d.node().removeAllChildren()
546+
self.render2d.node().removeAllChildren()
547+
self.aspect2d.reparent_to(self.render2d)
546548

547549
# [gjeon] restore sticky key settings
548550
if self.config.GetBool('disable-sticky-keys', 0):
@@ -1107,8 +1109,12 @@ def setupRender2d(self):
11071109
2-d objects and gui elements that are superimposed over the
11081110
3-d geometry in the window.
11091111
"""
1112+
# We've already created aspect2d in ShowBaseGlobal, for the
1113+
# benefit of creating DirectGui elements before ShowBase.
1114+
from . import ShowBaseGlobal
1115+
11101116
## This is the root of the 2-D scene graph.
1111-
self.render2d = NodePath('render2d')
1117+
self.render2d = ShowBaseGlobal.render2d
11121118

11131119
# Set up some overrides to turn off certain properties which
11141120
# we probably won't need for 2-d objects.
@@ -1139,7 +1145,6 @@ def setupRender2d(self):
11391145
## aspect2d, which scales things back to the right aspect
11401146
## ratio along the X axis (Z is still from -1 to 1)
11411147
self.aspect2d = ShowBaseGlobal.aspect2d
1142-
self.aspect2d.reparentTo(self.render2d)
11431148

11441149
aspectRatio = self.getAspectRatio()
11451150
self.aspect2d.setScale(1.0 / aspectRatio, 1.0, 1.0)

direct/src/showbase/ShowBaseGlobal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
pandaSystem = PandaSystem.getGlobalPtr()
2727

2828
# This is defined here so GUI elements can be instantiated before ShowBase.
29-
aspect2d = NodePath(PGTop("aspect2d"))
29+
render2d = NodePath("render2d")
30+
aspect2d = render2d.attachNewNode(PGTop("aspect2d"))
3031
hidden = NodePath("hidden")
3132

3233
# Set direct notify categories now that we have config

panda/src/gobj/preparedGraphicsObjects.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,8 @@ release_all_shader_buffers() {
13431343
++bci) {
13441344

13451345
BufferContext *bc = (BufferContext *)(*bci);
1346+
((ShaderBuffer *)bc->_object)->clear_prepared(this);
1347+
bc->_object = nullptr;
13461348
_released_shader_buffers.push_back(bc);
13471349
}
13481350

tests/gui/test_DirectOptionMenu.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from direct.gui.DirectOptionMenu import DirectOptionMenu
2+
import pytest
3+
4+
5+
def test_menu_destroy():
6+
menu = DirectOptionMenu(items=["item1", "item2"])
7+
menu.destroy()
8+
9+
10+
def test_showPopupMenu():
11+
menu = DirectOptionMenu()
12+
13+
# Showing an option menu without items will raise an exception
14+
with pytest.raises(Exception):
15+
menu.showPopupMenu()
16+
17+
menu["items"] = ["item1", "item2"]
18+
menu.showPopupMenu()
19+
assert not menu.popupMenu.isHidden()
20+
assert not menu.cancelFrame.isHidden()
21+
22+
menu.hidePopupMenu()
23+
assert menu.popupMenu.isHidden()
24+
assert menu.cancelFrame.isHidden()
25+
26+
27+
def test_index():
28+
menu = DirectOptionMenu(items=["item1", "item2"])
29+
assert menu.index("item1") == 0
30+
assert menu.index("item2") == 1
31+
32+
33+
def test_set_get():
34+
menu = DirectOptionMenu(items=["item1", "item2"])
35+
menu.set(1, False)
36+
assert menu.selectedIndex == 1
37+
assert menu.get() == "item2"
38+
assert menu["text"] == "item2"
39+
40+
41+
def test_initialitem():
42+
# initialitem by string
43+
menuByStr = DirectOptionMenu(items=["item1", "item2"], initialitem="item2")
44+
assert menuByStr.get() == "item2"
45+
assert menuByStr["text"] == "item2"
46+
47+
# initialitem by Index
48+
menuByIdx = DirectOptionMenu(items=["item1", "item2"], initialitem=1)
49+
assert menuByIdx.get() == "item2"
50+
assert menuByIdx["text"] == "item2"
51+
52+
53+
def test_item_text_scale():
54+
highlightScale = (2, 2)
55+
unhighlightScale = (0.5, 0.5)
56+
menu = DirectOptionMenu(
57+
items=["item1", "item2"],
58+
item_text_scale=unhighlightScale,
59+
highlightScale=highlightScale)
60+
61+
# initial scale
62+
item = menu.component("item0")
63+
64+
item_text_scale = 0.8
65+
assert item["text_scale"] == unhighlightScale
66+
67+
# highlight scale
68+
menu._highlightItem(item, 0)
69+
assert item["text_scale"] == highlightScale
70+
71+
# back to initial scale
72+
menu._unhighlightItem(item, item["frameColor"])
73+
assert item["text_scale"] == unhighlightScale

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy