Source code for peng3d.menu

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  menu.py
#  
#  Copyright 2016 notna <notna@apparat.org>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
#  

__all__ = ["BasicMenu","Menu"]

from .layer import Layer

[docs]class BasicMenu(object): """ Menu base class without layer support. Each menu is separated from the other menus and can be switched between at any time. .. seealso:: See :py:class:`Menu()` for more information. """ def __init__(self,name,window,peng): self.name = name self.window = window self.peng = peng self.eventHandlers = {} self.worlds = []
[docs] def draw(self): """ This method is called if it is time to render the menu. Override this method in subclasses to cutomize behaviour and actually draw stuff. """ pass
[docs] def addWorld(self,world): """ Adds the given world to the internal list. Worlds that are registered via this method will get all events that are given to this menu passed through. This mechanic is mainly used to implement actor controllers. """ self.worlds.append(world)
# Event handlers def handleEvent(self,event_type,args): if event_type in self.eventHandlers: for handler in self.eventHandlers[event_type]: handler(*args) for world in self.worlds: world.handle_event(event_type,args,self.window) def registerEventHandler(self,event_type,handler): if event_type not in self.eventHandlers: self.eventHandlers[event_type]=[] self.eventHandlers[event_type].append(handler)
[docs] def on_enter(self,old): """ This fake event handler will be called everytime this menu is entered via the :py:meth:`PengWindow.changeMenu()` method. This handler will not be called if this menu is already active. """ pass # Custom fake event handler for entering the menu
[docs] def on_exit(self,new): """ This fake event handler will be called everytime this menu is exited via the :py:meth:`PengWindow.changeMenu()` method. This handler will not be called if this menu is the same as the new menu. """ pass # Custom fake event handler for leaving the menu