added pysdl2 setup.
|
@ -0,0 +1,17 @@
|
|||
This software packages was created and is maintained and improved by
|
||||
|
||||
* Marcus von Appen <marcus@sysfault.org>
|
||||
|
||||
with contributions from
|
||||
|
||||
* Steven Johnson
|
||||
* Marcel Rodrigues
|
||||
* Dan Gillett
|
||||
|
||||
Thanks to everyone else for their assistance, support, fixes and improvements:
|
||||
|
||||
Sven Eckelmann, Marcel Rodrigues, Michael McCandless, Andreas Schiefer,
|
||||
Franz Schrober, Roger Flores, otus, Mihail Latyshov, Todd Rovito, Bil Bas,
|
||||
Dan McCombs, William Manire, Radomir Dopieralski, Joe Polak, Jordan F, DR0ID,
|
||||
Filip M. Nowak, David Farler, Max Bareiss, Kenneth Long, Robert Winkler,
|
||||
Jones Romao, smea lum, Linus Heckemann, DBLobster
|
|
@ -0,0 +1 @@
|
|||
See doc/copying.rst
|
|
@ -0,0 +1,91 @@
|
|||
PYTHON ?= python
|
||||
top_srcdir := `pwd`
|
||||
PYTHONPATH ?= $(top_srcdir)
|
||||
SUBDIRS = \
|
||||
$(top_srcdir)/sdl2 \
|
||||
$(top_srcdir)/sdl2/ext \
|
||||
$(top_srcdir)/sdl2/test \
|
||||
$(top_srcdir)/sdl2/test/resources \
|
||||
$(top_srcdir)/sdl2/test/util \
|
||||
$(top_srcdir)/doc \
|
||||
$(top_srcdir)/doc/tutorial \
|
||||
$(top_srcdir)/doc/modules \
|
||||
$(top_srcdir)/examples
|
||||
|
||||
INTERPRETERS = python2.7 python3.2 python3.3 python3.4 python3.5 pypy
|
||||
|
||||
all: clean build
|
||||
|
||||
dist: clean docs
|
||||
@echo "Creating dist..."
|
||||
@$(PYTHON) setup.py sdist --format gztar
|
||||
@$(PYTHON) setup.py sdist --format zip
|
||||
|
||||
bdist: clean docs
|
||||
@echo "Creating bdist..."
|
||||
@$(PYTHON) setup.py bdist
|
||||
|
||||
build:
|
||||
@echo "Running build"
|
||||
@$(PYTHON) setup.py build
|
||||
@echo "Build finished, invoke 'make install' to install."
|
||||
|
||||
|
||||
install:
|
||||
@echo "Installing..."
|
||||
@$(PYTHON) setup.py install
|
||||
|
||||
clean:
|
||||
@echo "Cleaning up in $(top_srcdir)/ ..."
|
||||
@rm -f *.cache *.core *~ MANIFEST *.pyc *.orig *.rej
|
||||
@rm -rf __pycache__
|
||||
@rm -rf build dist doc/html
|
||||
|
||||
@for dir in $(SUBDIRS); do \
|
||||
echo "Cleaning up in $$dir ..."; \
|
||||
if test -f $$dir/Makefile; then \
|
||||
make -C $$dir clean; \
|
||||
fi; \
|
||||
cd $$dir && rm -f *.cache *.core *~ MANIFEST *.pyc *.orig *.rej; \
|
||||
done
|
||||
|
||||
docs:
|
||||
@echo "Creating docs package"
|
||||
@rm -rf doc/html
|
||||
@cd doc && PYTHONPATH=$(PYTHONPATH) make html
|
||||
@mv doc/_build/html doc/html
|
||||
@rm -rf doc/_build
|
||||
@cd doc && make clean
|
||||
|
||||
release: dist
|
||||
|
||||
runtest:
|
||||
@PYTHONPATH=$(PYTHONPATH) $(PYTHON) -B -m sdl2.test.util.runtests
|
||||
|
||||
testall:
|
||||
@for interp in $(INTERPRETERS); do \
|
||||
PYTHONPATH=$(PYTHONPATH) $$interp -B -m sdl2.test.util.runtests || true; \
|
||||
done
|
||||
|
||||
# Do not run these in production environments! They are for testing
|
||||
# purposes only!
|
||||
|
||||
buildall: clean
|
||||
@for interp in $(INTERPRETERS); do \
|
||||
$$interp setup.py build; \
|
||||
done
|
||||
|
||||
installall:
|
||||
@for interp in $(INTERPRETERS); do \
|
||||
$$interp setup.py install; \
|
||||
done
|
||||
|
||||
testpackage:
|
||||
@for interp in $(INTERPRETERS); do \
|
||||
$$interp -c "import sdl2.test; sdl2.test.run()" || true \
|
||||
done
|
||||
|
||||
purge_installs:
|
||||
@for interp in $(INTERPRETERS); do \
|
||||
rm -rf /usr/local/lib/$$interp/site-packages/sdl2*; \
|
||||
done
|
|
@ -0,0 +1,49 @@
|
|||
Metadata-Version: 1.1
|
||||
Name: PySDL2
|
||||
Version: 0.9.5
|
||||
Summary: Python SDL2 bindings
|
||||
Home-page: http://bitbucket.org/marcusva/py-sdl2
|
||||
Author: Marcus von Appen
|
||||
Author-email: marcus@sysfault.org
|
||||
License: Public Domain / zlib
|
||||
Download-URL: http://bitbucket.org/marcusva/py-sdl2/downloads
|
||||
Description: About PySDL2
|
||||
============
|
||||
PySDL2 is a wrapper around the SDL2 library and as such similar to the
|
||||
discontinued PySDL project. In contrast to PySDL, it has no licensing
|
||||
restrictions, nor does it rely on C code, but uses ctypes instead.
|
||||
|
||||
Installation
|
||||
============
|
||||
PySDL2 is easy to install and integrate within your own projects. Just
|
||||
follow Python's standard procedure of installing packages or look for a
|
||||
prebuilt package for your operating system or distribution.
|
||||
|
||||
Documentation
|
||||
=============
|
||||
If you just started with SDL and PySDL2, it is strongly recommended
|
||||
that you read through the tutorial of the documentation to learn the
|
||||
basics. You can find the documentation at *doc/html* or online at
|
||||
http://pysdl2.readthedocs.org.
|
||||
|
||||
License
|
||||
=======
|
||||
This library is given to the public domain. There are no licensing
|
||||
restrictions. Please see *doc/copying.rst* for further details.
|
||||
|
||||
Platform: UNKNOWN
|
||||
Classifier: Development Status :: 4 - Beta
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: License :: Public Domain
|
||||
Classifier: License :: OSI Approved :: zlib/libpng License
|
||||
Classifier: Operating System :: OS Independent
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Programming Language :: Python :: 2.7
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Programming Language :: Python :: 3.2
|
||||
Classifier: Programming Language :: Python :: 3.3
|
||||
Classifier: Programming Language :: Python :: 3.4
|
||||
Classifier: Programming Language :: Python :: 3.5
|
||||
Classifier: Programming Language :: Python :: Implementation :: CPython
|
||||
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
||||
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
@ -0,0 +1,23 @@
|
|||
About PySDL2
|
||||
============
|
||||
PySDL2 is a wrapper around the SDL2 library and as such similar to the
|
||||
discontinued PySDL project. In contrast to PySDL, it has no licensing
|
||||
restrictions, nor does it rely on C code, but uses ctypes instead.
|
||||
|
||||
Installation
|
||||
============
|
||||
PySDL2 is easy to install and integrate within your own projects. Just
|
||||
follow Python's standard procedure of installing packages or look for a
|
||||
prebuilt package for your operating system or distribution.
|
||||
|
||||
Documentation
|
||||
=============
|
||||
If you just started with SDL and PySDL2, it is strongly recommended
|
||||
that you read through the tutorial of the documentation to learn the
|
||||
basics. You can find the documentation at *doc/html* or online at
|
||||
http://pysdl2.readthedocs.org.
|
||||
|
||||
License
|
||||
=======
|
||||
This library is given to the public domain. There are no licensing
|
||||
restrictions. Please see *doc/copying.rst* for further details.
|
|
@ -0,0 +1,154 @@
|
|||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
# the i18n builder cannot share the environment and doctrees with the others
|
||||
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " texinfo to make Texinfo files"
|
||||
@echo " info to make Texinfo files and run them through makeinfo"
|
||||
@echo " gettext to make PO message catalogs"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
@rm -rf $(BUILDDIR)/*
|
||||
@rm -f modules/*~ tutorial/*~ *~
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PySDL2.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PySDL2.qhc"
|
||||
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/PyMule"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/PyMule"
|
||||
@echo "# devhelp"
|
||||
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
texinfo:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo
|
||||
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
|
||||
@echo "Run \`make' in that directory to run these through makeinfo" \
|
||||
"(use \`make info' here to do that automatically)."
|
||||
|
||||
info:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo "Running Texinfo files through makeinfo..."
|
||||
make -C $(BUILDDIR)/texinfo info
|
||||
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
|
||||
|
||||
gettext:
|
||||
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
|
||||
@echo
|
||||
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
|
@ -0,0 +1,253 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# PySDL2 documentation build configuration file, created by
|
||||
# sphinx-quickstart on Thu Mar 22 07:51:57 2012.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys, os
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
# sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration -----------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
# needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = ['sphinx.ext.intersphinx',
|
||||
'sphinx.ext.todo',
|
||||
'sphinx.ext.coverage',
|
||||
'sphinx.ext.inheritance_diagram'
|
||||
]
|
||||
|
||||
todo_include_todos = True
|
||||
graphviz_output_format = 'png'
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
# source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'PySDL2'
|
||||
copyright = u'2013-2016, Marcus von Appen'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '0.9'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '0.9.5'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
# language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
# today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
# today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ['_build']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all documents.
|
||||
# default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
# add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
# add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
# show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
# modindex_common_prefix = []
|
||||
|
||||
|
||||
# -- Options for HTML output ---------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = 'default'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
# html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
# html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
# html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
# html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
# html_logo = None
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
# html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
# html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
# html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
# html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
# html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
# html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
# html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
# html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
# html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
# html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
# html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
# html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
# html_file_suffix = None
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'PySDL2Doc'
|
||||
|
||||
|
||||
# -- Options for LaTeX output --------------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
# 'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
# 'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
# 'preamble': '',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||
latex_documents = [
|
||||
('index', 'PySDL2.tex', u'PySDL2 Documentation',
|
||||
u'Marcus von Appen', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
# latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
# latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
# latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
# latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
# latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
# latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output --------------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
('index', 'pysdl2', u'PySDL2 Documentation',
|
||||
[u'Marcus von Appen'], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
# man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output ------------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
('index', 'PySDL2', u'PySDL2 Documentation',
|
||||
u'Marcus von Appen', 'PySDL2', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
# texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
# texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
# texinfo_show_urls = 'footnote'
|
||||
|
||||
|
||||
# Example configuration for intersphinx: refer to the Python standard library.
|
||||
intersphinx_mapping = {'http://docs.python.org/': "python.inv"}
|
|
@ -0,0 +1,60 @@
|
|||
License
|
||||
=======
|
||||
|
||||
::
|
||||
|
||||
This software is distributed under the Public Domain. Since it is
|
||||
not enough anymore to tell people: 'hey, just do with it whatever
|
||||
you like to do', you can consider this software being distributed
|
||||
under the CC0 Public Domain Dedication
|
||||
(http://creativecommons.org/publicdomain/zero/1.0/legalcode.txt).
|
||||
|
||||
In cases, where the law prohibits the recognition of Public Domain
|
||||
software, this software can be licensed under the zlib license as
|
||||
stated below:
|
||||
|
||||
Copyright (C) 2012-2014 Marcus von Appen <marcus@sysfault.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgement in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Some files are **not** covered by the license above.
|
||||
|
||||
* For ``examples/resources/tuffy.ttf``,
|
||||
``examples/resources/tuffy.copy.ttf`` and
|
||||
``sdl2/test/resources/tuffy.ttf`` the following terms apply:
|
||||
|
||||
::
|
||||
|
||||
We, the copyright holders of this work, hereby release it into the
|
||||
public domain. This applies worldwide.
|
||||
|
||||
In case this is not legally possible,
|
||||
|
||||
We grant any entity the right to use this work for any purpose, without
|
||||
any conditions, unless such conditions are required by law.
|
||||
|
||||
Thatcher Ulrich <tu@tulrich.com> http://tulrich.com
|
||||
Karoly Barta bartakarcsi@gmail.com
|
||||
Michael Evans http://www.evertype.com
|
||||
|
||||
* doc/python.inv
|
||||
|
||||
An inventory index for linking to the proper places in the Python
|
||||
documentation, taken from http://docs.python.org/2/. Its copyright and
|
||||
license information can be found at
|
||||
http://docs.python.org/2/copyright.html and
|
||||
http://docs.python.org/2/license.html.
|
|
@ -0,0 +1,63 @@
|
|||
.. _faq:
|
||||
|
||||
PySDL2 FAQ
|
||||
==========
|
||||
This is a list of Frequently Asked Questions about PySDL2. If you think,
|
||||
something is missing, please suggest it!
|
||||
|
||||
On importing...
|
||||
---------------
|
||||
... my script fails and complains that a SDL2 library could not be found!
|
||||
|
||||
Do you have the libraries properly installed? Did you follow the operating
|
||||
system's way of installing or registering libraries? If you placed the
|
||||
libraries in some folder, make sure that the ``PYSDL2_DLL_PATH``
|
||||
environment variable points to the correct location.
|
||||
|
||||
... my script fails complaining that the *found* SDL2 library can't be used!
|
||||
|
||||
Do you use a 64-bit operating system? Please make sure, that the Python
|
||||
interpreter *and* that the SDL2 libraries are either 64-bit ones *or*
|
||||
32-bit ones. A 32-bit Python interpreter can't deal with a 64-bit library
|
||||
and vice versa.
|
||||
|
||||
Using...
|
||||
--------
|
||||
|
||||
... the sdl2 API is weird. Why do you use the SDL\_ prefix all the time?
|
||||
|
||||
The low-level APIs for SDL2, SDL2\_mixer, SDL2\_ttf, ... shall represent a
|
||||
clean wrapping around the original C API calls. Thus, if you have to search
|
||||
for documentation or want to make a Python to C conversion (or C to Python),
|
||||
most of the code cleanly maps to the original API naming and layout and you
|
||||
do not have to think about whether you had to use SDL\_ or TTF\_ or whatever
|
||||
as prefix or suffix.
|
||||
|
||||
... the sdl2 API is does not comply to PEP-8. Please make it PEP-8 compatible.
|
||||
|
||||
Most of the API is PEP-8 compatible. The low-level bindings to SDL2 and
|
||||
related libraries however use the exact naming (including capital letters)
|
||||
as the functions or structures, they map to. See the previous entry for
|
||||
the reason of that.
|
||||
|
||||
How do I...
|
||||
-----------
|
||||
|
||||
... save my surfaces as image files?
|
||||
|
||||
You can use :func:`sdl2.SDL_SaveBMP()` to save them as bitmap files. Other
|
||||
formats are currently unsupported, but might be added to
|
||||
the :mod:`sdl2.ext` package in the future.
|
||||
|
||||
|
||||
Font handling...
|
||||
----------------
|
||||
|
||||
... is too hard. Why can't it work the same way as pygame does?
|
||||
|
||||
The :mod:`sdl2.sdlttf` API does not know about platform-specific font
|
||||
locations and is unable to resolve font paths based on e.g. the font name
|
||||
or typeface. It's not its job and PySDL2 likewise does not provide such
|
||||
functionality. If you need improved font detection support, you might want
|
||||
to take a look at the sysfont module of the python-utils project, which can
|
||||
be found at https://bitbucket.org/marcusva/python-utils/.
|
|
@ -0,0 +1,4 @@
|
|||
# Sphinx build info version 1
|
||||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
|
||||
config: 066676e51cb391f44578bf4a12aa1d11
|
||||
tags: 645f666f9bcd5a90fca523b33c5a78b7
|
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 16 KiB |
|
@ -0,0 +1,60 @@
|
|||
License
|
||||
=======
|
||||
|
||||
::
|
||||
|
||||
This software is distributed under the Public Domain. Since it is
|
||||
not enough anymore to tell people: 'hey, just do with it whatever
|
||||
you like to do', you can consider this software being distributed
|
||||
under the CC0 Public Domain Dedication
|
||||
(http://creativecommons.org/publicdomain/zero/1.0/legalcode.txt).
|
||||
|
||||
In cases, where the law prohibits the recognition of Public Domain
|
||||
software, this software can be licensed under the zlib license as
|
||||
stated below:
|
||||
|
||||
Copyright (C) 2012-2014 Marcus von Appen <marcus@sysfault.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgement in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Some files are **not** covered by the license above.
|
||||
|
||||
* For ``examples/resources/tuffy.ttf``,
|
||||
``examples/resources/tuffy.copy.ttf`` and
|
||||
``sdl2/test/resources/tuffy.ttf`` the following terms apply:
|
||||
|
||||
::
|
||||
|
||||
We, the copyright holders of this work, hereby release it into the
|
||||
public domain. This applies worldwide.
|
||||
|
||||
In case this is not legally possible,
|
||||
|
||||
We grant any entity the right to use this work for any purpose, without
|
||||
any conditions, unless such conditions are required by law.
|
||||
|
||||
Thatcher Ulrich <tu@tulrich.com> http://tulrich.com
|
||||
Karoly Barta bartakarcsi@gmail.com
|
||||
Michael Evans http://www.evertype.com
|
||||
|
||||
* doc/python.inv
|
||||
|
||||
An inventory index for linking to the proper places in the Python
|
||||
documentation, taken from http://docs.python.org/2/. Its copyright and
|
||||
license information can be found at
|
||||
http://docs.python.org/2/copyright.html and
|
||||
http://docs.python.org/2/license.html.
|
|
@ -0,0 +1,63 @@
|
|||
.. _faq:
|
||||
|
||||
PySDL2 FAQ
|
||||
==========
|
||||
This is a list of Frequently Asked Questions about PySDL2. If you think,
|
||||
something is missing, please suggest it!
|
||||
|
||||
On importing...
|
||||
---------------
|
||||
... my script fails and complains that a SDL2 library could not be found!
|
||||
|
||||
Do you have the libraries properly installed? Did you follow the operating
|
||||
system's way of installing or registering libraries? If you placed the
|
||||
libraries in some folder, make sure that the ``PYSDL2_DLL_PATH``
|
||||
environment variable points to the correct location.
|
||||
|
||||
... my script fails complaining that the *found* SDL2 library can't be used!
|
||||
|
||||
Do you use a 64-bit operating system? Please make sure, that the Python
|
||||
interpreter *and* that the SDL2 libraries are either 64-bit ones *or*
|
||||
32-bit ones. A 32-bit Python interpreter can't deal with a 64-bit library
|
||||
and vice versa.
|
||||
|
||||
Using...
|
||||
--------
|
||||
|
||||
... the sdl2 API is weird. Why do you use the SDL\_ prefix all the time?
|
||||
|
||||
The low-level APIs for SDL2, SDL2\_mixer, SDL2\_ttf, ... shall represent a
|
||||
clean wrapping around the original C API calls. Thus, if you have to search
|
||||
for documentation or want to make a Python to C conversion (or C to Python),
|
||||
most of the code cleanly maps to the original API naming and layout and you
|
||||
do not have to think about whether you had to use SDL\_ or TTF\_ or whatever
|
||||
as prefix or suffix.
|
||||
|
||||
... the sdl2 API is does not comply to PEP-8. Please make it PEP-8 compatible.
|
||||
|
||||
Most of the API is PEP-8 compatible. The low-level bindings to SDL2 and
|
||||
related libraries however use the exact naming (including capital letters)
|
||||
as the functions or structures, they map to. See the previous entry for
|
||||
the reason of that.
|
||||
|
||||
How do I...
|
||||
-----------
|
||||
|
||||
... save my surfaces as image files?
|
||||
|
||||
You can use :func:`sdl2.SDL_SaveBMP()` to save them as bitmap files. Other
|
||||
formats are currently unsupported, but might be added to
|
||||
the :mod:`sdl2.ext` package in the future.
|
||||
|
||||
|
||||
Font handling...
|
||||
----------------
|
||||
|
||||
... is too hard. Why can't it work the same way as pygame does?
|
||||
|
||||
The :mod:`sdl2.sdlttf` API does not know about platform-specific font
|
||||
locations and is unable to resolve font paths based on e.g. the font name
|
||||
or typeface. It's not its job and PySDL2 likewise does not provide such
|
||||
functionality. If you need improved font detection support, you might want
|
||||
to take a look at the sysfont module of the python-utils project, which can
|
||||
be found at https://bitbucket.org/marcusva/python-utils/.
|
|
@ -0,0 +1,41 @@
|
|||
Welcome to PySDL2's documentation!
|
||||
==================================
|
||||
PySDL2 is a wrapper around the SDL2 library and as such similar to the
|
||||
discontinued PySDL project. In contrast to PySDL, it has no licensing
|
||||
restrictions, nor does it rely on C code, but uses :mod:`ctypes` instead.
|
||||
|
||||
Contents
|
||||
========
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
install.rst
|
||||
integration.rst
|
||||
tutorial/index.rst
|
||||
modules/index.rst
|
||||
faq.rst
|
||||
news.rst
|
||||
|
||||
Further readings:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
todos.rst
|
||||
copying.rst
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
||||
|
||||
Documentation TODOs
|
||||
===================
|
||||
|
||||
.. todolist::
|
||||
|
||||
Last generated on: |today|
|
|
@ -0,0 +1,95 @@
|
|||
Installing PySDL2
|
||||
=================
|
||||
This section provides an overview and guidance for installing PySDL2 on
|
||||
various target platforms.
|
||||
|
||||
Getting the sources
|
||||
-------------------
|
||||
You can download the official releases of PySDL2 from
|
||||
https://bitbucket.org/marcusva/py-sdl2/downloads. Download the most
|
||||
recent release, unpack it and make sure that you installed the relevant
|
||||
prerequisites before continuing with the installation.
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
PySDL2 relies on some 3rd party packages to be fully usable and to
|
||||
provide you full access to all of its features.
|
||||
|
||||
You must have at least one of the following Python versions installed:
|
||||
|
||||
* Python 2.7, 3.2+ (http://www.python.org)
|
||||
* PyPy 1.8.0+ (http://www.pypy.org)
|
||||
|
||||
Other Python versions or Python implementations might work, but are
|
||||
(currently) not officially tested or supported by the PySDL2
|
||||
distribution.
|
||||
|
||||
You need to have a working SDL2 library on your target system. You can obtain
|
||||
the source code (to build it yourself) or a prebuilt version at
|
||||
http://www.libsdl.org.
|
||||
|
||||
PySDL2 also offers support for the following SDL-related libraries:
|
||||
|
||||
* SDL2_image (http://www.libsdl.org/projects/SDL_image/)
|
||||
* SDL2_mixer (http://www.libsdl.org/projects/SDL_mixer/)
|
||||
* SDL2_ttf (http://www.libsdl.org/projects/SDL_ttf/)
|
||||
* SDL2_gfx (http://www.ferzkopp.net/Software/SDL_gfx-2.0/)
|
||||
|
||||
Those are optional though and only necessary, if you want to use
|
||||
:mod:`sdl2.sdlimage`, :mod:`sdl2.sdlmixer`, :mod:`sdl2.sdlttf` or
|
||||
:mod:`sdl2.sdlgfx`.
|
||||
|
||||
Installation
|
||||
------------
|
||||
You can either use the python way of installing the package or the make
|
||||
command using the Makefile on POSIX-compatible platforms, such as Linux
|
||||
or BSD, or the make.bat batch file on Windows platforms.
|
||||
|
||||
Simply type ::
|
||||
|
||||
python setup.py install
|
||||
|
||||
for the traditional python way or ::
|
||||
|
||||
make install
|
||||
|
||||
for using the Makefile or make.bat. Both will try to perform a default
|
||||
installation with as many features as possible.
|
||||
|
||||
Trying out
|
||||
^^^^^^^^^^
|
||||
You also can test out PySDL2 without actually installing it. You just
|
||||
need to set up your ``PYTHONPATH`` to point to the location of the
|
||||
source distribution package. On Windows-based platforms, you might use
|
||||
something like ::
|
||||
|
||||
set PYTHONPATH=C:\path\to\pysdl2\:%PYTHONPATH%
|
||||
|
||||
to define the ``PYTHONPATH`` on a command shell. On Linux/Unix, use ::
|
||||
|
||||
export PYTHONPATH=/path/to/pysdl2:$PYTHONPATH
|
||||
|
||||
for bourne shell compatibles or ::
|
||||
|
||||
setenv PYTHONPATH /path/to/pysdl2:$PYTHONPATH
|
||||
|
||||
for C shell compatibles. You can omit the `:$PYTHONPATH``, if you did not use
|
||||
it so far and if your environment settings do not define it.
|
||||
|
||||
.. note::
|
||||
|
||||
If you are using IronPython, use ``IRONPYTHONPATH`` instead of
|
||||
``PYTHONPATH``.
|
||||
|
||||
.. note::
|
||||
|
||||
If you did not install SDL2 using the preferred way for your operation
|
||||
system, please read the information about :ref:`importing-pysdl2` in the
|
||||
section :doc:`integration`.
|
||||
|
||||
Notes on Mercurial usage
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
The Mercurial version of PySDL2 is not intended to be used in a
|
||||
production environment. Interfaces may change from one checkin to
|
||||
another, methods, classes or modules can be broken and so on. If you
|
||||
want more reliable code, please refer to the official releases.
|
|
@ -0,0 +1,77 @@
|
|||
Integrating PySDL2
|
||||
==================
|
||||
PySDL2 consists of two packages, :mod:`sdl2`, which is a plain 1:1 API
|
||||
wrapper around the SDL2 API, and :mod:`sdl2.ext`, which offers enhanced
|
||||
functionality for :mod:`sdl2`.
|
||||
|
||||
The :mod:`sdl2` package is implemented in a way that shall make it easy for
|
||||
you to integrate and deploy it with your own software projects. You can rely
|
||||
on PySDL2 as third-party package, so that the user needs to install it
|
||||
before he can use your software. Alternatively, you can just copy the
|
||||
whole package into your project to ship it within your own project
|
||||
bundle.
|
||||
|
||||
.. _importing-pysdl2:
|
||||
|
||||
Importing
|
||||
---------
|
||||
The :mod:`sdl2` package relies on an external SDL2 library for creating the
|
||||
wrapper functions. This means that the user needs to have SDL2 installed or
|
||||
that you ship a SDL2 library with your project.
|
||||
|
||||
If the user has a SDL2 library installed on the target system, the
|
||||
:mod:`ctypes` hooks of :mod:`sdl2` try to find it in the OS-specific standard
|
||||
locations via :func:`ctypes.util.find_library`. If you are going to ship your
|
||||
own SDL2 library with the project or can not rely on the standard mechanism of
|
||||
:mod:`ctypes`, it is also possible to set the environment variable
|
||||
:envvar:`PYSDL2_DLL_PATH`, which shall point to the directory of the SDL2
|
||||
library or consist of a list of directories, in which the SDL2 libraries can
|
||||
be found.
|
||||
|
||||
.. note::
|
||||
|
||||
:envvar:`PYSDL2_DLL_PATH` is preferred over the standard
|
||||
mechanism. If the module finds a SDL2 library in :envvar:`PYSDL2_DLL_PATH`,
|
||||
it will try to use that one in the first place, before using any SDL2
|
||||
library installed on the target system.
|
||||
|
||||
Let's assume, you ship your own library *SDL2.dll* within your project
|
||||
location *fancy_project/third_party*. You can set the environment
|
||||
variable :envvar:`PYSDL2_DLL_PATH` before starting Python. ::
|
||||
|
||||
# Win32 platforms
|
||||
set PYSDL2_DLL_PATH=C:\path\to\fancy_project\third_party
|
||||
|
||||
# Unix/Posix-alike environments - bourne shells
|
||||
export PYSDL2_DLL_PATH=/path/to/fancy_project/third_party
|
||||
|
||||
# Unix/Posix-alike environments - C shells
|
||||
setenv PYSDL2_DLL_PATH /path/to/fancy_project/third_party
|
||||
|
||||
# Define multiple paths to search for the libraries - Win32
|
||||
set PYSDL2_DLL_PATH=C:\first\path;C:\second\path
|
||||
|
||||
You also can set the environment variable within Python using
|
||||
:data:`os.environ`. ::
|
||||
|
||||
os.environ["PYSDL2_DLL_PATH"] = "C:\\path\\to\\fancy_project\\third_party"
|
||||
os.environ["PYSDL2_DLL_PATH"] = "/path/to/fancy_project/third_party"
|
||||
|
||||
.. note::
|
||||
|
||||
If you aim to integrate :mod:`sdl` directly into your software and do
|
||||
not want or are not allowed to change the environment variables, you
|
||||
can also change the ``os.getenv("PYSDL2_DLL_PATH")`` query within the
|
||||
*sdl2/dll.py* (or *sdl2/sdlimage.py*, *sdl2/sdlttf.py*, *sdl2/sdlgfx.py*)
|
||||
file to point to the directory, in which you keep the DLL.
|
||||
|
||||
Using different SDL2 versions
|
||||
-----------------------------
|
||||
PySDL2 tries to provide interfaces to the most recent versions of the
|
||||
SDL2 libraries. Sometimes this means that PySDL2 tries to test for
|
||||
functions that might not be available for your very own project or that
|
||||
are not available on the target system due to a version of the specific
|
||||
library. To check, if the SDL2 libraries do not provide certain
|
||||
functions, you can enable the specific warnings for them.
|
||||
|
||||
>>> python -W"module"::ImportWarning:sdl2.dll yourfile.py
|
|
@ -0,0 +1,16 @@
|
|||
API reference
|
||||
=============
|
||||
This is the core documentation of the various modules, classes and functions
|
||||
PySDL2 offers. If you want to have a quick overview about the modules, use the
|
||||
:ref:`modindex`. If you just want to look up a specific class, method or
|
||||
function, use the :ref:`genindex` or :ref:`search`.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
sdl2.rst
|
||||
sdl2_sdlgfx.rst
|
||||
sdl2_sdlimage.rst
|
||||
sdl2_sdlmixer.rst
|
||||
sdl2_sdlttf.rst
|
||||
sdl2ext.rst
|
|
@ -0,0 +1,177 @@
|
|||
.. module:: sdl2
|
||||
:synopsis: SDL2 library wrapper
|
||||
|
||||
sdl2 - SDL2 library wrapper
|
||||
===========================
|
||||
The :mod:`sdl2` package is a :mod:`ctypes`-based wrapper around
|
||||
the SDL2 library. It wraps nearly all publicly accessible structures and
|
||||
functions of the SDL2 library to be accessible from Python code.
|
||||
|
||||
A detailed documentation about the behaviour of the different functions
|
||||
can found within the `SDL2 documentation
|
||||
<http://wiki.libsdl.org/moin.cgi/CategoryAPI>`_.
|
||||
|
||||
Usage
|
||||
-----
|
||||
You can use :mod:`sdl2` in nearly exactly the same way as you would do with
|
||||
the SDL library and C code.
|
||||
|
||||
.. highlight:: c
|
||||
|
||||
A brief example in C code::
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int running;
|
||||
SDL_Window *window;
|
||||
SDL_Surface *windowsurface;
|
||||
SDL_Surface *image;
|
||||
SDL_Event event;
|
||||
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
||||
window = SDL_CreateWindow("Hello World",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
592, 460, SDL_WINDOW_SHOWN);
|
||||
windowsurface = SDL_GetWindowSurface(window);
|
||||
|
||||
image = SDL_LoadBMP("exampleimage.bmp");
|
||||
SDL_BlitSurface(image, NULL, windowsurface, NULL);
|
||||
|
||||
SDL_UpdateWindowSurface(window);
|
||||
SDL_FreeSurface(image);
|
||||
|
||||
running = 1;
|
||||
while (running) {
|
||||
while (SDL_PollEvent(&event) != 0) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
running = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
.. highlight:: python
|
||||
|
||||
Doing the same in Python: ::
|
||||
|
||||
import sys
|
||||
import ctypes
|
||||
from sdl2 import *
|
||||
|
||||
def main():
|
||||
SDL_Init(SDL_INIT_VIDEO)
|
||||
window = SDL_CreateWindow(b"Hello World",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
592, 460, SDL_WINDOW_SHOWN)
|
||||
windowsurface = SDL_GetWindowSurface(window)
|
||||
|
||||
image = SDL_LoadBMP(b"exampleimage.bmp")
|
||||
SDL_BlitSurface(image, None, windowsurface, None)
|
||||
|
||||
SDL_UpdateWindowSurface(window)
|
||||
SDL_FreeSurface(image)
|
||||
|
||||
running = True
|
||||
event = SDL_Event()
|
||||
while running:
|
||||
while SDL_PollEvent(ctypes.byref(event)) != 0:
|
||||
if event.type == SDL_QUIT:
|
||||
running = False
|
||||
break
|
||||
|
||||
SDL_DestroyWindow(window)
|
||||
SDL_Quit()
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
You can port code in a straightforward manner from one language to the other,
|
||||
though it is important to know about the limitations and slight differences
|
||||
mentioned below. Also, PySDL2 offers advanced functionality, which also feels
|
||||
more *'pythonic'*, via the :mod:`sdl2.ext` package.
|
||||
|
||||
Missing interfaces
|
||||
------------------
|
||||
The following functions, classes, constants and macros of SDL2 are *not*
|
||||
available within :mod:`sdl2`.
|
||||
|
||||
* :c:data:`SDL_REVISION` and :c:data:`SDL_REVISION_NUMBER` from ``SDL_revision.h``
|
||||
* :c:data:`SDL_NAME()` from ``SDL_name.h``
|
||||
* :c:func:`SDL_MostSignificantBitIndex32` from ``SDL_bits.h``
|
||||
* Everything from ``SDL_main.h``
|
||||
* Everything from ``SDL_system.h``
|
||||
* Everything from ``SDL_assert.h``
|
||||
* Everything from ``SDL_thread.h``
|
||||
* Everything from ``SDL_atomic.h``
|
||||
* Everything from ``SDL_opengl.h``
|
||||
* Everything from ``SDL_mutex.h``
|
||||
|
||||
Additional interfaces
|
||||
---------------------
|
||||
The following functions, classes, constants and macros are are *not* part of
|
||||
SDL2, but were introduced by :mod:`sdl2`.
|
||||
|
||||
.. data:: ALL_PIXELFORMATS
|
||||
|
||||
Tuple containing all SDL2 pixel format constants (SDL_PIXELFORMAT_INDEX1LSB,
|
||||
..., SDL_PIXELFORMAT_RGB565, ...).
|
||||
|
||||
.. data:: AUDIO_FORMATS
|
||||
|
||||
Set containing all SDL2 audio format constants (AUDIO_U8, AUDIO_S8,
|
||||
... AUDIO_F32LSB, ... ).
|
||||
|
||||
.. function:: sdl2.rw_from_object(obj : object) -> SDL_RWops
|
||||
|
||||
Creates a SDL_RWops from any Python object. The Python object must at least
|
||||
support the following methods:
|
||||
|
||||
read(length) -> data
|
||||
|
||||
length is the size in bytes to be read. A call to len(data) must
|
||||
return the correct amount of bytes for the data, so that
|
||||
len(data) / [size in bytes for a single element from data] returns
|
||||
the amount of elements. Must raise an error on failure.
|
||||
|
||||
seek(offset, whence) -> int
|
||||
|
||||
offset denotes the offset to move the read/write pointer of the
|
||||
object to. whence indicates the movement behaviour and can be one
|
||||
of the following values:
|
||||
|
||||
* RW_SEEK_SET - move to offset from the start of the file
|
||||
* RW_SEEK_CUR - move by offset from the relative location
|
||||
* RW_SEEK_END - move to offset from the end of the file
|
||||
|
||||
If it could not move read/write pointer to the desired location,
|
||||
an error must be raised.
|
||||
|
||||
tell() -> int
|
||||
|
||||
Must return the current offset. This method must only be
|
||||
provided, if seek() does not return any value.
|
||||
|
||||
close() -> None
|
||||
|
||||
Closes the object(or its internal data access methods). Must raise
|
||||
an error on failure.
|
||||
|
||||
write(data) -> None
|
||||
|
||||
Writes the passed data(which is a string of bytes) to the object.
|
||||
Must raise an error on failure.
|
||||
|
||||
.. note::
|
||||
|
||||
The write() method is optional and only necessary, if the passed
|
||||
object should be able to write data.
|
||||
|
||||
The returned :class:`sdl2.SDL_RWops` is a pure Python object and
|
||||
**must not** be freed via :func:`sdl2.SDL_FreeRW()`.
|
|
@ -0,0 +1,13 @@
|
|||
.. module:: sdl2.sdlgfx
|
||||
:synopsis: SDL2_gfx library wrapper
|
||||
|
||||
sdl2.sdlgfx - SDL2_gfx library wrapper
|
||||
======================================
|
||||
The :mod:`sdl2.sdlgfx` module is a :mod:`ctypes`-based wrapper
|
||||
around the SDL2_gfx library. It wraps nearly all publicly accessible
|
||||
structures and functions of the SDL2_gfx library to be accessible from
|
||||
Python code.
|
||||
|
||||
A detailed documentation about the behaviour of the different functions
|
||||
can found on the `SDL2_gfx project website
|
||||
<http://www.ferzkopp.net/Software/SDL_gfx-2.0/>`_.
|
|
@ -0,0 +1,13 @@
|
|||
.. module:: sdl2.sdlimage
|
||||
:synopsis: SDL2_image library wrapper
|
||||
|
||||
sdl2.sdlimage - SDL2_image library wrapper
|
||||
==========================================
|
||||
The :mod:`sdl2.sdlimage` module is a :mod:`ctypes`-based wrapper
|
||||
around the SDL2_image library. It wraps nearly all publicly accessible
|
||||
structures and functions of the SDL2_image library to be accessible from
|
||||
Python code.
|
||||
|
||||
A detailed documentation about the behaviour of the different functions
|
||||
can found within the `SDL2_image documentation
|
||||
<http://www.libsdl.org/projects/SDL_image/docs/index.html>`_.
|
|
@ -0,0 +1,13 @@
|
|||
.. module:: sdl2.sdlmixer
|
||||
:synopsis: SDL2_mixer library wrapper
|
||||
|
||||
sd2.sdlmixer - SDL2_mixer library wrapper
|
||||
=========================================
|
||||
The :mod:`sdl2.sdlmixer` module is a :mod:`ctypes`-based wrapper around
|
||||
the SDL2_mixer library. It wraps nearly all publicly accessible
|
||||
structures and functions of the SDL2_mixer library to be accessible from
|
||||
Python code.
|
||||
|
||||
A detailed documentation about the behaviour of the different functions
|
||||
can found within the `SDL2_mixer documentation
|
||||
<http://www.libsdl.org/projects/SDL_mixer/docs/index.html>`_.
|
|
@ -0,0 +1,13 @@
|
|||
.. module:: sdl2.sdlttf
|
||||
:synopsis: SDL2_ttf library wrapper
|
||||
|
||||
sd2.sdlttf - SDL2_ttf library wrapper
|
||||
=====================================
|
||||
The :mod:`sdl2.sdlttf` module is a :mod:`ctypes`-based wrapper
|
||||
around the SDL2_ttf library. It wraps nearly all publicly accessible
|
||||
structures and functions of the SDL2_ttf library to be accessible from
|
||||
Python code.
|
||||
|
||||
A detailed documentation about the behaviour of the different functions
|
||||
can found within the `SDL2_ttf documentation
|
||||
<http://www.libsdl.org/projects/SDL_ttf/docs/index.html>`_.
|
|
@ -0,0 +1,33 @@
|
|||
.. module:: sdl2.ext
|
||||
:synopsis: Python extensions for SDL2
|
||||
|
||||
sdl2.ext - Python extensions for SDL2
|
||||
=====================================
|
||||
The :mod:`sdl2.ext` package provides advanced functionality for creating
|
||||
applications using SDL2 and Python. It offers a rich set of modules, classes
|
||||
and functions, such as easy image loading, basic user interface elements,
|
||||
resource management and sprite and (on-screen) scene systems.
|
||||
|
||||
Learn more about
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
sdl2ext_algorithms.rst
|
||||
sdl2ext_array.rst
|
||||
sdl2ext_color.rst
|
||||
sdl2ext_colorpalettes.rst
|
||||
sdl2ext_common.rst
|
||||
sdl2ext_compat.rst
|
||||
sdl2ext_draw.rst
|
||||
sdl2ext_ebs.rst
|
||||
sdl2ext_events.rst
|
||||
sdl2ext_font.rst
|
||||
sdl2ext_gui.rst
|
||||
sdl2ext_image.rst
|
||||
sdl2ext_particles.rst
|
||||
sdl2ext_pixelaccess.rst
|
||||
sdl2ext_resources.rst
|
||||
sdl2ext_sprite.rst
|
||||
sdl2ext_surface.rst
|
||||
sdl2ext_window.rst
|
|
@ -0,0 +1,42 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
Common algorithms
|
||||
=================
|
||||
|
||||
.. function:: cohensutherland(left : int, top : int, right : int, \
|
||||
bottom : int, x1 : int, y1 : int, x2 : int, y2 : int) -> int, int, int, int
|
||||
|
||||
This implements the Cohen-Sutherland line clipping
|
||||
algorithm. *left*, *top*, *right* and *bottom* denote the
|
||||
clipping area, into which the line defined by *x1*, *y1* (start
|
||||
point) and *x2*, *y2* (end point) will be clipped.
|
||||
|
||||
If the line does not intersect with the rectangular clipping area,
|
||||
four ``None`` values will be returned as tuple. Otherwise a tuple of
|
||||
the clipped line points will be returned in the form ``(cx1, cy1,
|
||||
cx2, cy2)``.
|
||||
|
||||
.. function:: liangbarsky(left : int, top : int, right : int, \
|
||||
bottom : int, x1 : int, y1 : int, x2 : int, y2 : int) -> int, int, int, int
|
||||
|
||||
This implements the Liang-Barsky line clipping algorithm. *left*,
|
||||
*top*, *right* and *bottom* denote the clipping area, into
|
||||
which the line defined by *x1*, *y1* (start point) and *x2*,
|
||||
*y2* (end point) will be clipped.
|
||||
|
||||
If the line does not intersect with the rectangular clipping area,
|
||||
four ``None`` values will be returned as tuple. Otherwise a tuple of
|
||||
the clipped line points will be returned in the form ``(cx1, cy1,
|
||||
cx2, cy2)``.
|
||||
|
||||
.. function:: clipline(left : int, top : int, right : int, \
|
||||
bottom : int, x1 : int, y1 : int, x2 : int, \
|
||||
y2 : int[,method=liangbarsky]) -> int, int, int, int
|
||||
|
||||
Clips a line to a rectangular area.
|
||||
|
||||
.. function:: point_on_line(p1 : iterable, p2 : iterable, point : iterable) -> bool
|
||||
|
||||
Checks, if *point*, a two-value tuple, is on the line segment defined by *p1*
|
||||
and *p2*.
|
||||
|
|
@ -0,0 +1,276 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
Converting sequences
|
||||
====================
|
||||
This module provides various functions and classes to access sequences and
|
||||
buffer-style objects in different ways. It also provides conversion routines
|
||||
to improve the interoperability of sequences with :mod:`ctypes` data types.
|
||||
|
||||
Providing read-write access for sequential data
|
||||
-----------------------------------------------
|
||||
Two classes allow you to access sequential data in different ways. The
|
||||
:class:`CTypesView` provides byte-wise access to iterable objects and allows
|
||||
you to convert the object representation to matching byte-widths for
|
||||
:mod:`ctypes` or other modules.
|
||||
|
||||
Depending on the the underlying object and the chosen size of each particular
|
||||
item of the object, the :class:`CTypesView` allows you to operate directly
|
||||
on different representations of the object's contents. ::
|
||||
|
||||
>>> text = bytearray("Hello, I am a simple ASCII string!")
|
||||
>>> ctview = CTypesView(text, itemsize=1)
|
||||
>>> ctview.view[0] = 0x61
|
||||
>>> print(text)
|
||||
aello, I am a simple ASCII string!"
|
||||
>>> ctview.to_uint16()[3] = 0x6554
|
||||
>>> print(text)
|
||||
aello,Te am a simple ASCII string!"
|
||||
|
||||
The snippet above provides a single-byte sized view on a :func:`bytearray`
|
||||
object. Afterwards, the first item of the view is changed, which causes a
|
||||
change on the :func:`bytearray`, on the first item as well, since both, the
|
||||
:class:`CTypesView` and the :func:`bytearray` provide a byte-wise access to
|
||||
the contents.
|
||||
|
||||
By using :meth:`CTypesView.to_uint16()`, we change the access representation to
|
||||
a 2-byte unsigned integer :mod:`ctypes` pointer and change the fourth 2-byte
|
||||
value, *I* to something else. ::
|
||||
|
||||
>>> text = bytearray("Hello, I am a simple ASCII string!")
|
||||
>>> ctview = CTypesView(text, itemsize=2)
|
||||
>>> ctview.view[0] = 0x61
|
||||
>>> print(text)
|
||||
aello, I am a simple ASCII string!"
|
||||
>>> ctview.to_uint16()[3] = 0x6554
|
||||
>>> print(text) aello,Te am a simple ASCII string!"
|
||||
|
||||
If the encapsuled object does not provide a (writable) :func:`buffer`
|
||||
interface, but is iterable, the :class:`CTypesView` will create an
|
||||
internal copy of the object data using Python's :mod:`array` module and
|
||||
perform all operations on that copy. ::
|
||||
|
||||
>>> mylist = [18, 52, 86, 120, 154, 188, 222, 240]
|
||||
>>> ctview = CTypesView(mylist, itemsize=1, docopy=True)
|
||||
>>> print(ctview.object)
|
||||
array('B', [18, 52, 86, 120, 154, 188, 222, 240])
|
||||
>>> ctview.view[3] = 0xFF
|
||||
>>> print(mylist)
|
||||
[18, 52, 86, 120, 154, 188, 222, 240]
|
||||
>>> print(ctview.object)
|
||||
array('B', [18, 52, 86, 255, 154, 188, 222, 240])
|
||||
|
||||
As for directly accessible objects, you can define your own itemsize to
|
||||
be used. If the iterable does not provide a direct byte access to their
|
||||
contents, this won't have any effect except for resizing the item
|
||||
widths. ::
|
||||
|
||||
>>> mylist = [18, 52, 86, 120, 154, 188, 222, 240]
|
||||
>>> ctview = CTypesView(mylist, itemsize=4, docopy=True)
|
||||
>>> print(ctview.object)
|
||||
array('I', [18L, 52L, 86L, 120L, 154L, 188L, 222L, 240L])
|
||||
|
||||
Accessing data over multiple dimensions
|
||||
---------------------------------------
|
||||
The second class, :class:`MemoryView` provides an interface to access
|
||||
data over multiple dimensions. You can layout and access a simple
|
||||
byte stream over e.g. two or more axes, providing a greater flexibility
|
||||
for functional operations and complex data.
|
||||
|
||||
Let's assume, we are reading image data from a file stream into some buffer
|
||||
object and want to access and manipulate the image data. Images feature two
|
||||
axes, one being the width, the other being the height, defining a rectangular
|
||||
graphics area.
|
||||
|
||||
When we read all data from the file, we have an one-dimensional view of the
|
||||
image graphics. The :class:`MemoryView` allows us to define a
|
||||
two-dimensional view over the image graphics, so that we can operate on
|
||||
both, rows and columns of the image. ::
|
||||
|
||||
>>> imagedata = bytearray("some 1-byte graphics data")
|
||||
>>> view = MemoryView(imagedata, 1, (5, 5))
|
||||
>>> print(view)
|
||||
[[s, o, m, e, ], [1, -, b, y, t], [e, , g, r, a], [p, h, i, c, s], [ , d, a, t, a]]
|
||||
>>> for row in view:
|
||||
... print(row)
|
||||
...
|
||||
[s, o, m, e, ]
|
||||
[1, -, b, y, t]
|
||||
[e, , g, r, a]
|
||||
[p, h, i, c, s]
|
||||
[ , d, a, t, a]
|
||||
>>> for row in view:
|
||||
... row[1] = "X"
|
||||
... print row
|
||||
...
|
||||
[s, X, m, e, ]
|
||||
[1, X, b, y, t]
|
||||
[e, X, g, r, a]
|
||||
[p, X, i, c, s]
|
||||
[ , X, a, t, a]
|
||||
>>> print(imagedata)
|
||||
sXme 1XbyteXgrapXics Xata
|
||||
|
||||
On accessing a particular dimension of a :class:`MemoryView`, a new
|
||||
:class:`MemoryView` is created, if it does not access a single
|
||||
element. ::
|
||||
|
||||
>>> firstrow = view[0]
|
||||
>>> type(firstrow)
|
||||
<class 'sdl2.ext.array.MemoryView'>
|
||||
>>> type(firstrow[0])
|
||||
<type 'bytearray'>
|
||||
|
||||
A :class:`MemoryView` features, similar to Python's builtin
|
||||
:class:`memoryview`, dimensions and strides, accessible via the
|
||||
:attr:`MemoryView.ndim` and :attr:`MemoryView.strides` attributes.
|
||||
|
||||
>>> view.ndim
|
||||
2
|
||||
>>> view.strides
|
||||
(5, 5)
|
||||
|
||||
The :attr:`MemoryView.strides`, which have to be passed on creating a
|
||||
new :class:`MemoryView`, define the layout of the data over different
|
||||
dimensions. In the example above, we created a 5x5 two-dimensional view
|
||||
to the image graphics. ::
|
||||
|
||||
>>> twobytes = MemoryView(imagedata, 2, (5, 1))
|
||||
>>> print(twobytes)
|
||||
[[sX, me, 1, Xb, yt], [eX, gr, ap, Xi, cs]]
|
||||
|
||||
|
||||
Array API
|
||||
---------
|
||||
|
||||
.. class:: CTypesView(obj : iterable[, itemsize=1[, docopy=False[, objsize=None]]])
|
||||
|
||||
A proxy class for byte-wise accessible data types to be used in
|
||||
ctypes bindings. The CTypesView provides a read-write access to
|
||||
arbitrary objects that are iterable.
|
||||
|
||||
In case the object does not provide a :func:`buffer()` interface for
|
||||
direct access, the CTypesView can copy the object's contents into an
|
||||
internal buffer, from which data can be retrieved, once the necessary
|
||||
operations have been performed.
|
||||
|
||||
Depending on the item type stored in the iterable object, you might
|
||||
need to provide a certain *itemsize*, which denotes the size per
|
||||
item in bytes. The *objsize* argument might be necessary of iterables,
|
||||
for which len() does not return the correct amount of objects or is not
|
||||
implemented.
|
||||
|
||||
.. attribute:: bytesize
|
||||
|
||||
Returns the length of the encapsuled object in bytes.
|
||||
|
||||
.. attribute:: is_shared
|
||||
|
||||
Indicates, if changes on the CTypesView data effect the encapsuled
|
||||
object directly. if not, this means that the object was copied
|
||||
internally and needs to be updated by the user code outside of the
|
||||
CTypesView.
|
||||
|
||||
.. attribute:: object
|
||||
|
||||
The encapsuled object.
|
||||
|
||||
.. attribute:: view
|
||||
|
||||
Provides a read-write aware view of the encapsuled object data
|
||||
that is suitable for usage from :mod:`ctypes`.
|
||||
|
||||
.. method:: to_bytes() -> ctypes.POINTER
|
||||
|
||||
Returns a byte representation of the encapsuled object. The return
|
||||
value allows a direct read-write access to the object data, if it
|
||||
is not copied. The :func:`ctypes.POINTER` points to an array of
|
||||
:class:`ctypes.c_ubyte`.
|
||||
|
||||
.. method:: to_uint16() -> ctypes.POINTER
|
||||
|
||||
Returns a 16-bit representation of the encapsuled object. The return
|
||||
value allows a direct read-write access to the object data, if it
|
||||
is not copied. The :func:`ctypes.POINTER` points to an array of
|
||||
:class:`ctypes.c_ushort`.
|
||||
|
||||
.. method:: to_uint32() -> ctypes.POINTER
|
||||
|
||||
Returns a 32-bit representation of the encapsuled object. The return
|
||||
value allows a direct read-write access to the object data, if it
|
||||
is not copied. The :func:`ctypes.POINTER` points to an array of
|
||||
:class:`ctypes.c_uint`.
|
||||
|
||||
.. method:: to_uint64() -> ctypes.POINTER
|
||||
|
||||
Returns a 64-bit representation of the encapsuled object. The return
|
||||
value allows a direct read-write access to the object data, if it
|
||||
is not copied. The :func:`ctypes.POINTER` points to an array of
|
||||
:class:`ctypes.c_ulonglong`.
|
||||
|
||||
.. class:: MemoryView(source : object, itemsize : int, strides : tuple[, getfunc=None[, setfunc=None[, srcsize=None]]])
|
||||
|
||||
The :class:`MemoryView` provides a read-write access to arbitrary
|
||||
data objects, which can be indexed.
|
||||
|
||||
*itemsize* denotes the size of a single item. *strides* defines
|
||||
the dimensions and the length (n items * *itemsize*) for each
|
||||
dimension. *getfunc* and *setfunc* are optional parameters to
|
||||
provide specialised read and write access to the underlying
|
||||
*source*. *srcsize* can be used to provide the correct source
|
||||
size, if ``len(source)`` does not return the absolute size of the
|
||||
source object in all dimensions.
|
||||
|
||||
.. note::
|
||||
|
||||
The MemoryView is a pure Python-based implementation and makes
|
||||
heavy use of recursion for multi-dimensional access. If you aim
|
||||
for speed on accessing a n-dimensional object, you want to
|
||||
consider using a specialised library such as numpy. If you need
|
||||
n-dimensional access support, where such a library is not
|
||||
supported, or if you need to provide access to objects, which do
|
||||
not fulfill the requirements of that particular libray,
|
||||
:class:`MemoryView` can act as solid fallback solution.
|
||||
|
||||
.. attribute:: itemsize
|
||||
|
||||
The size of a single item in bytes.
|
||||
|
||||
.. attribute:: ndim
|
||||
|
||||
The number of dimensions of the :class:`MemoryView`.
|
||||
|
||||
.. attribute:: size
|
||||
|
||||
The size in bytes of the underlying source object.
|
||||
|
||||
.. attribute:: source
|
||||
|
||||
The underlying data source.
|
||||
|
||||
.. attribute:: strides
|
||||
|
||||
A tuple defining the length in bytes for accessing all
|
||||
elements in each dimension of the :class:`MemoryView`.
|
||||
|
||||
.. function:: to_ctypes(dataseq : iterable, dtype[, mcount=0]) -> array, int
|
||||
|
||||
Converts an arbitrary sequence to a ctypes array of the specified
|
||||
*dtype* and returns the ctypes array and amount of items as
|
||||
two-value tuple.
|
||||
|
||||
Raises a :exc:`TypeError`, if one or more elements in the passed
|
||||
sequence do not match the passed *dtype*.
|
||||
|
||||
.. function:: to_list(dataseq : iterable) -> list
|
||||
|
||||
Converts a ctypes array to a list.
|
||||
|
||||
.. function:: to_tuple(dataseq : iterable) -> tuple
|
||||
|
||||
Converts a ctypes array to a tuple.
|
||||
|
||||
.. function:: create_array(obj : object, itemsize : int) -> array.array
|
||||
|
||||
Creates an :class:`array.array` based copy of the passed object.
|
||||
*itemsize* denotes the size in bytes for a single element within
|
||||
*obj*.
|
|
@ -0,0 +1,141 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
Color handling
|
||||
==============
|
||||
|
||||
.. class:: Color(r=255, g=255, b=255, a=255)
|
||||
|
||||
A simple RGBA-based color implementation. The Color class uses a
|
||||
byte-wise representation of the 4 channels red, green, blue and alpha
|
||||
transparency, so that the values range from 0 to 255. It allows basic
|
||||
arithmetic operations, e.g. color addition or subtraction and
|
||||
conversions to other color spaces such as HSV or CMY.
|
||||
|
||||
.. attribute:: r
|
||||
|
||||
The red channel value of the Color.
|
||||
|
||||
.. attribute:: g
|
||||
|
||||
The green channel value of the Color.
|
||||
|
||||
.. attribute:: b
|
||||
|
||||
The blue channel value of the Color.
|
||||
|
||||
.. attribute:: a
|
||||
|
||||
The alpha channel value of the Color.
|
||||
|
||||
.. attribute:: cmy
|
||||
|
||||
The CMY representation of the Color. The CMY components are in the
|
||||
ranges C = [0, 1], M = [0, 1], Y = [0, 1]. Note that this will not
|
||||
return the absolutely exact CMY values for the set RGB values in
|
||||
all cases. Due to the RGB mapping from 0-255 and the CMY mapping
|
||||
from 0-1 rounding errors may cause the CMY values to differ
|
||||
slightly from what you might expect.
|
||||
|
||||
.. attribute:: hsla
|
||||
|
||||
The HSLA representation of the Color. The HSLA components are in
|
||||
the ranges H = [0, 360], S = [0, 100], L = [0, 100], A = [0,
|
||||
100]. Note that this will not return the absolutely exact HSL
|
||||
values for the set RGB values in all cases. Due to the RGB mapping
|
||||
from 0-255 and the HSL mapping from 0-100 and 0-360 rounding
|
||||
errors may cause the HSL values to differ slightly from what you
|
||||
might expect.
|
||||
|
||||
.. attribute:: hsva
|
||||
|
||||
The HSVA representation of the Color. The HSVA components are in
|
||||
the ranges H = [0, 360], S = [0, 100], V = [0, 100], A = [0,
|
||||
100]. Note that this will not return the absolutely exact HSV
|
||||
values for the set RGB values in all cases. Due to the RGB mapping
|
||||
from 0-255 and the HSV mapping from 0-100 and 0-360 rounding
|
||||
errors may cause the HSV values to differ slightly from what you
|
||||
might expect.
|
||||
|
||||
.. attribute:: i1i2i3
|
||||
|
||||
The I1I2I3 representation of the Color. The I1I2I3 components are
|
||||
in the ranges I1 = [0, 1], I2 = [-0.5, 0.5], I3 = [-0.5,
|
||||
0.5]. Note that this will not return the absolutely exact I1I2I3
|
||||
values for the set RGB values in all cases. Due to the RGB mapping
|
||||
from 0-255 and the I1I2I3 from 0-1 rounding errors may cause the
|
||||
I1I2I3 values to differ slightly from what you might expect.
|
||||
|
||||
.. method:: normalize() -> (float, float, float, float)
|
||||
|
||||
Returns the normalised RGBA values of the Color as floating point
|
||||
values in the range [0, 1].
|
||||
|
||||
.. method:: __add__(self, color) -> Color
|
||||
__sub__(self, color) -> Color
|
||||
__mul__(self, color) -> Color
|
||||
__div__(self, color) -> Color
|
||||
__truediv__(self, color) -> Color
|
||||
__mod__(self, color) -> Color
|
||||
|
||||
Basic arithmetic functions for :class:`Color` values. The arithmetic
|
||||
operations ``+, -, *, /, %`` are supported by the :class:`Color` class
|
||||
and work on a per-channel basis. This means, that the operation ::
|
||||
|
||||
color = color1 + color2
|
||||
|
||||
is the same as ::
|
||||
|
||||
color = Color()
|
||||
color.r = min(color1.r + color2.r, 255)
|
||||
color.g = min(color1.g + color2.g, 255)
|
||||
...
|
||||
|
||||
The operations guarantee that the channel values stay in the allowed
|
||||
range of [0, 255].
|
||||
|
||||
.. function:: argb_to_color(v : int) -> Color
|
||||
ARGB(v : int) -> Color
|
||||
|
||||
Converts an integer value to a Color, assuming the integer represents
|
||||
a 32-bit ARGB value.
|
||||
|
||||
.. function:: convert_to_color(v : object) -> Color
|
||||
COLOR(v : object) -> Color
|
||||
|
||||
Tries to convert the passed value to a Color object. The value can be
|
||||
an arbitrary Python object, which is passed to the different other
|
||||
conversion functions. If one of them succeeds, the Color will be
|
||||
returned to the caller. If none succeeds, a :exc:`ValueError` will be
|
||||
raised.
|
||||
|
||||
If the color is an integer value, it is assumed to be in ARGB layout.
|
||||
|
||||
.. function:: rgba_to_color(v : int) -> Color
|
||||
RGBA(v : int) -> Color
|
||||
|
||||
Converts an integer value to a Color, assuming the integer represents
|
||||
a 32-bit RGBA value.
|
||||
|
||||
.. function:: is_rgb_color(v : object) -> bool
|
||||
|
||||
Checks, if the passed value is an item that could be converted to a
|
||||
RGB color.
|
||||
|
||||
.. function:: is_rgba_color(v : object) -> bool
|
||||
|
||||
Checks, if the passed value is an item that could be converted to a
|
||||
RGBA color.
|
||||
|
||||
.. function:: string_to_color(v : string) -> Color
|
||||
|
||||
Converts a hex color string or color name to a Color value. Supported
|
||||
hex values are:
|
||||
|
||||
* #RGB
|
||||
* #RGBA
|
||||
* #RRGGBB
|
||||
* #RRGGBBAA
|
||||
* 0xRGB
|
||||
* 0xRGBA
|
||||
* 0xRRGGBB
|
||||
* 0xRRGGBBAA
|
|
@ -0,0 +1,29 @@
|
|||
.. module:: sdl2.ext.colorpalettes
|
||||
:synopsis: Predefined sets of colors.
|
||||
|
||||
sdl2.ext.colorpalettes - predefined sets of colors
|
||||
==================================================
|
||||
Indexed color palettes. Each palette is a tuple of
|
||||
:class:`sdl2.ext.Color` objects.
|
||||
|
||||
The following palettes are currently available:
|
||||
|
||||
================== ===================================================
|
||||
Palette Identifier Description
|
||||
================== ===================================================
|
||||
MONOPALETTE 1-bit monochrome palette (black and white).
|
||||
|
||||
GRAY2PALETTE 2-bit grayscale palette with black, white and two
|
||||
shades of gray.
|
||||
GRAY4PALETTE 4-bit grayscale palette with black, white and 14
|
||||
shades shades of gray.
|
||||
GRAY8PALETTE 8-bit grayscale palette with black, white and 254
|
||||
shades shades of gray.
|
||||
RGB3PALETTE 3-bit RGB color palette with pure red, green and
|
||||
blue and their complementary colors as well as black
|
||||
and white.
|
||||
CGAPALETTE CGA color palette.
|
||||
EGAPALETTE EGA color palette.
|
||||
VGAPALETTE 8-bit VGA color palette.
|
||||
WEBPALETTE "Safe" web color palette with 225 colors.
|
||||
================== ===================================================
|
|
@ -0,0 +1,38 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
Initialization routines
|
||||
=======================
|
||||
TODO
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
.. exception:: SDLError(msg=None)
|
||||
|
||||
An SDL2 specific :class:`Exception` class. if no *msg* is provided,
|
||||
the message will be set to the value of :func:`sdl2.error.SDL_GetError()`
|
||||
|
||||
.. function:: init() -> None
|
||||
|
||||
Initialises the underlying SDL2 video subsystem. Raises a
|
||||
:exc:`SDLError`, if the SDL2 video subsystem could not be
|
||||
initialised.
|
||||
|
||||
.. function:: quit() -> None
|
||||
|
||||
Quits the underlying SDL2 video subysystem. If no other SDL2
|
||||
subsystems are active, this will also call :func:`quit()`,
|
||||
:func:`sdl2.sdlttf.TTF_Quit()` and :func:`sdl2.sdlimage.IMG_Quit()`.
|
||||
|
||||
.. function:: get_events() -> [SDL_Event, SDL_Event, ...]
|
||||
|
||||
Gets all SDL events that are currently on the event queue.
|
||||
|
||||
.. class:: TestEventProcessor()
|
||||
|
||||
A simple event processor for testing purposes.
|
||||
|
||||
.. method:: run(window : Window) -> None
|
||||
|
||||
Starts an event loop without actually processing any event. The method
|
||||
will run endlessly until a ``SDL_QUIT`` event occurs.
|
|
@ -0,0 +1,86 @@
|
|||
.. module:: sdl2.ext.compat
|
||||
:synopsis: Python compatibility helpers.
|
||||
|
||||
sdl2.ext.compat - Python compatibility helpers
|
||||
==============================================
|
||||
The :mod:`sdl2.ext.compat` module is for internal purposes of the :mod:`sdl2`
|
||||
package and should not be used outside of the package. Classes, methods and
|
||||
interfaces might change between versions and there is no guarantee of API
|
||||
compatibility on different platforms and python implementations or between
|
||||
releases.
|
||||
|
||||
.. data:: ISPYTHON2
|
||||
|
||||
``True``, if executed in a Python 2.x compatible interpreter, ``False``
|
||||
otherwise.
|
||||
|
||||
.. data:: ISPYTHON3
|
||||
|
||||
``True``, if executed in a Python 3.x compatible interpreter, ``False``
|
||||
otherwise.
|
||||
|
||||
.. function:: long([x[, base]])
|
||||
|
||||
.. note::
|
||||
|
||||
Only defined for Python 3.x, for which it is the same as :func:`int()`.
|
||||
|
||||
.. function:: unichr(i)
|
||||
|
||||
.. note::
|
||||
|
||||
Only defined for Python 3.x, for which it is the same as :func:`chr()`.
|
||||
|
||||
.. function:: unicode(string[, encoding[, errors]])
|
||||
|
||||
.. note::
|
||||
|
||||
Only defined for Python 3.x, for which it is the same as :func:`str()`.
|
||||
|
||||
.. function:: callable(x) -> bool
|
||||
|
||||
.. note::
|
||||
|
||||
Only defined for Python 3.x, for which it is the same as
|
||||
``isinstance(x, collections.Callable)``
|
||||
|
||||
.. function:: byteify(x : string, enc : string) -> bytes
|
||||
|
||||
Converts a string to a :func:`bytes` object.
|
||||
|
||||
.. function:: stringify(x : bytes, enc : string) -> string
|
||||
|
||||
Converts a :func:`bytes` to a string object.
|
||||
|
||||
.. function:: isiterable(x) -> bool
|
||||
|
||||
Shortcut for ``isinstance(x, collections.Iterable)``.
|
||||
|
||||
.. function:: platform_is_64bit() -> bool
|
||||
|
||||
Checks, if the interpreter is 64-bit capable.
|
||||
|
||||
.. decorator:: deprecated
|
||||
|
||||
A simple decorator to mark functions and methods as deprecated. This will
|
||||
print a deprecation message each time the function or method is invoked.
|
||||
|
||||
.. function:: deprecation(message : string) -> None
|
||||
|
||||
Prints a deprecation message using the :func:`warnings.warn()` function.
|
||||
|
||||
.. exception:: UnsupportedError(obj : object[, msg=None])
|
||||
|
||||
Indicates that a certain class, function or behaviour is not supported in
|
||||
the specific execution environment.
|
||||
|
||||
.. decorator:: experimental
|
||||
|
||||
A simple decorator to mark functions and methods as
|
||||
experimental. This will print a warning each time the function or
|
||||
method is invoked.
|
||||
|
||||
.. exception:: ExperimentalWarning(obj : object[, msg=None])
|
||||
|
||||
Indicates that a certain class, function or behaviour is in an
|
||||
experimental state.
|
|
@ -0,0 +1,44 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
2D drawing routines for software surfaces
|
||||
=========================================
|
||||
|
||||
.. note::
|
||||
|
||||
The drawing functions within this module are unoptimised and should not be
|
||||
considered fast. If you want improved drawing of 2D primitives, including
|
||||
hardware acceleration, you should use the methods of the
|
||||
:class:`Renderer` instead.
|
||||
|
||||
.. function:: prepare_color(color : object, target : object) -> int
|
||||
|
||||
Prepares the passed *color* for a specific *target*. *color* can be any
|
||||
object type that can be processed by
|
||||
:func:`convert_to_color()`. *target* can be any
|
||||
:class:`sdl2.SDL_PixelFormat`, :class:`sdl2.SDL_Surface` or
|
||||
:class:`SoftwareSprite` instance.
|
||||
|
||||
The returned integer will be a color value matching the target's pixel
|
||||
format.
|
||||
|
||||
.. function:: fill(target : object, color : object[, area=None]) -> None
|
||||
|
||||
Fills a certain area on the passed *target* with a *color*. If no *area* is
|
||||
provided, the entire target will be filled with the passed color. If an
|
||||
iterable item is provided as *area* (such as a list or tuple), it will be
|
||||
first checked, if the item denotes a single rectangular area
|
||||
(4 integer values) before assuming it to be a sequence of rectangular areas
|
||||
to fill with the color.
|
||||
|
||||
*target* can be any :class:`sdl2.SDL_Surface` or :class:`SoftwareSprite`
|
||||
instance.
|
||||
|
||||
.. function:: line(target : object, color : object[, width=1]) -> None
|
||||
|
||||
Draws one or multiple lines on the passed *target*. *line* can be a
|
||||
sequence of four integers for a single line in the form ``(x1, y1,
|
||||
x2, y2)`` or a sequence of a multiple of 4 for drawing multiple lines
|
||||
at once, e.g. ``(x1, y1, x2, y2, x3, y3, x4, y4, ...)``.
|
||||
|
||||
*target* can be any :class:`sdl2.SDL_Surface` or :class:`SoftwareSprite`
|
||||
instance.
|
|
@ -0,0 +1,419 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
.. _ref-ebs:
|
||||
|
||||
Working with component-based entities
|
||||
=====================================
|
||||
:mod:`sdl2.ext` supports a component oriented programming pattern to separate
|
||||
object instances, carried data and processing logic within applications
|
||||
or games. It uses an entity based approach, in which object instances are
|
||||
unique identifiers, while their data is managed within components, which
|
||||
are stored separately. For each individual component type a processing
|
||||
system will take care of all necessary updates on running the application.
|
||||
|
||||
Component-based patterns
|
||||
------------------------
|
||||
Component-based means that - instead of a traditional OOP approach - object
|
||||
information are split up into separate data bags for reusability and that those
|
||||
data bags are separated from any application logic.
|
||||
|
||||
Behavioural design
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
Imagine a car class in traditional OOP, which might look like ::
|
||||
|
||||
class Car:
|
||||
def __init__(self):
|
||||
self.color = "red"
|
||||
self.position = 0, 0
|
||||
self.velocity = 0, 0
|
||||
self.sprite = get_some_car_image()
|
||||
...
|
||||
def drive(self, timedelta):
|
||||
self.position[0] = self.velocity[0] * timedelta
|
||||
self.position[1] = self.velocity[1] * timedelta
|
||||
...
|
||||
def stop(self):
|
||||
self.velocity = 0, 0
|
||||
...
|
||||
def render(self, screen):
|
||||
screen.display(self.sprite)
|
||||
|
||||
mycar = new Car()
|
||||
mycar.color = "green"
|
||||
mycar.velocity = 10, 0
|
||||
|
||||
The car features information stored in attributes (``color``, ``position``,
|
||||
...) and behaviour (application logic, ``drive()``, ``stop()`` ...).
|
||||
|
||||
A component-based approach aims to split and reduce the car to a set of
|
||||
information and external systems providing the application logic. ::
|
||||
|
||||
class Car:
|
||||
def __init__(self):
|
||||
self.color = "red"
|
||||
self.position = 0, 0
|
||||
self.velocity = 0, 0
|
||||
self.sprite = get_some_car_image()
|
||||
|
||||
class CarMovement:
|
||||
def drive(self, car, timedelta):
|
||||
car.position[0] = car.velocity[0] * timedelta
|
||||
car.position[1] = car.velocity[1] * timedelta
|
||||
...
|
||||
def stop(self):
|
||||
car.velocity = 0, 0
|
||||
|
||||
class CarRenderer:
|
||||
def render(self, car, screen):
|
||||
screen.display(car.sprite)
|
||||
|
||||
At this point of time, there is no notable difference between both approaches,
|
||||
except that the latter one adds additional overhead.
|
||||
|
||||
The benefit comes in, when you
|
||||
|
||||
* use subclassing in your OOP design
|
||||
* want to change behavioural patterns on a global scale or based on states
|
||||
* want to refactor code logic in central locations
|
||||
* want to cascade application behaviours
|
||||
|
||||
The initial ``Car`` class from above defines, how it should be displayed
|
||||
on the screen. If you now want to add a feature for rescaling the screen
|
||||
size after the user activates the magnifier mode, you need to refactor
|
||||
the ``Car`` and all other classes that render things on the screen, have
|
||||
to consider all subclasses that override the method and so on.
|
||||
Refactoring the ``CarRenderer`` code by adding a check for the magnifier
|
||||
mode sounds quite simple in contrast to that, not?
|
||||
|
||||
The same applies to the movement logic - inverting the movement logic
|
||||
requires you to refactor all your classes instead of a single piece of
|
||||
application code.
|
||||
|
||||
Information design
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
Subclassing with traditional OOP for behavioural changes also might
|
||||
bloat your classes with unnecessary information, causing the memory
|
||||
footprint for your application to rise without any need. Let's assume
|
||||
you have a ``Truck`` class that inherits from ``Car``. Let's further
|
||||
assume that all trucks in your application look the same. Why should any
|
||||
of those carry a ``sprite`` or ``color`` attribute? You would need to
|
||||
refactor your ``Car`` class to get rid of those superfluous information,
|
||||
adding another level of subclassing. If at a later point of time you
|
||||
decide to give your trucks different colors, you need to refactor
|
||||
everything again.
|
||||
|
||||
Wouldn't it be easier to deal with colors, if they are available on the
|
||||
truck and leave them out, if they are not? We initially stated that the
|
||||
component-based approach aims to separate data (information) from code
|
||||
logic. That said, if the truck has a color, we can handle it easily, if
|
||||
it has not, we will do as usual.
|
||||
|
||||
Also, checking for the color of an object (regardless, if it is a truck,
|
||||
car, aeroplane or death star) allows us to apply the same or similar
|
||||
behaviour for every object. If the information is available, we will
|
||||
process it, if it is not, we will not do anything.
|
||||
|
||||
All in all
|
||||
^^^^^^^^^^
|
||||
Once we split up the previously OOP-style classes into pure data containers and
|
||||
some separate processing code for the behaviour, we are talking about components
|
||||
and (processing) systems. A component is a data container, ideally grouping
|
||||
related information on a granular level, so that it is easy to (re)use.
|
||||
When you combine different components to build your in-application objects and
|
||||
instantiate those, we are talking about entities.
|
||||
|
||||
.. image:: images/ebs.png
|
||||
|
||||
*Component*
|
||||
provides information (data bag)
|
||||
|
||||
*Entity*
|
||||
In-application instance that consists of *component* items
|
||||
|
||||
*System*
|
||||
Application logic for working with *Entity* items and their
|
||||
*component* data
|
||||
|
||||
*World*
|
||||
The environment that contains the different *System* instances and
|
||||
all *Entity* items with their *component* data
|
||||
|
||||
Within a strict COP design, the application logic (ideally) only knows about
|
||||
data to process. It does not know anything about entities or complex classes
|
||||
and only operates on the data.
|
||||
|
||||
.. image:: images/copprocessing.png
|
||||
|
||||
To keep things simple, modular and easy to maintain and change, you usually
|
||||
create small processing systems, which perform the necessary operations on the
|
||||
data they shall handle. That said, a ``MovementSystem`` for our car entity would
|
||||
only operate on the position and velocity component of the car entity. It does
|
||||
not know anything about the the car's sprite or sounds that the car makes,
|
||||
since *this is nothing it has to deal with*.
|
||||
|
||||
To display the car on the screen, a ``RenderingSystem`` might pick up the
|
||||
sprite component of the car, maybe along with the position information (so it
|
||||
knows, where to place the sprite) and render it on the screen.
|
||||
|
||||
If you want the car to play sounds, you would add an audio playback system,
|
||||
that can perform the task. Afterwards you can add the necessary audio
|
||||
information via a sound component to the car and it will make noise.
|
||||
|
||||
Component-based design with sdl2.ext
|
||||
------------------------------------
|
||||
|
||||
.. note::
|
||||
|
||||
This section will deal with the specialities of COP patterns and
|
||||
provide the bare minimum of information. If you are just starting with
|
||||
such a design, it is recommended to read through the :ref:`pong-tutorial`
|
||||
tutorial.
|
||||
|
||||
:mod:`sdl2.ext` provides a :class:`World` class in which all other objects
|
||||
will reside. The :class:`World` will maintain both, :class:`Entity` and
|
||||
component items, and allows you to set up the processing logic via
|
||||
the :class:`System` and :class:`Applicator` classes. ::
|
||||
|
||||
>>> appworld = World()
|
||||
|
||||
Components can be created from any class that inherits from the
|
||||
:class:`object` type and represent the data bag of information for the
|
||||
entity and application world. Ideally, they should avoid any
|
||||
application logic (except from getter and setter properties). ::
|
||||
|
||||
class Position2D(object):
|
||||
def __init__(self, x=0, y=0):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
:class:`Entity` objects define the in-application objects and only consist of
|
||||
component-based attributes. They also require a :class:`World` at
|
||||
object instantiation time. ::
|
||||
|
||||
class CarEntity(Entity):
|
||||
def __init__(self, world, x=0, y=0):
|
||||
self.position2d = Position2D(x, y)
|
||||
|
||||
.. note::
|
||||
|
||||
The *world* argument in ``__init__()`` is necessary. It will be
|
||||
passed to the internal ``__new__()`` constructor of the
|
||||
:class:`Entity` and stores a reference to the :class:`World` and also
|
||||
allows the :class:`Entity` to store its information in the
|
||||
:class:`World`.
|
||||
|
||||
The :class:`Entity` also requries its attributes to be named exactly as
|
||||
their component class name, but in lowercase letters. If you name a
|
||||
component ``MyAbsolutelyAwesomeDataContainer``, an :class:`Entity` will
|
||||
force you to write the following: ::
|
||||
|
||||
class SomeEntity(Entity):
|
||||
def __init__(self, world):
|
||||
self.myabsolutelyawesomedatacontainer = MyAbsolutelyAwesomeDataContainer()
|
||||
|
||||
.. note::
|
||||
|
||||
This is not entirely true. A reference of the object will be stored on a
|
||||
per-class-in-mro basis. This means that if ``MyAbsolutelyAwesomeDataContainer``
|
||||
inherits from ``ShortName``, you can also do: ::
|
||||
|
||||
class SomeEntity(Entity):
|
||||
def __init__(self, world):
|
||||
self.shortname = MyAbsolutelyAwesomeDataContainer()
|
||||
|
||||
Components should be as atomic as possible and avoid complex
|
||||
inheritance. Since each value of an :class:`Entity` is stored per class
|
||||
in its mro list, components inheriting from the same class(es) will
|
||||
overwrite each other on conflicting classes: ::
|
||||
|
||||
class Vector(Position2D):
|
||||
def __init__(self, x=0, y=0, z=0):
|
||||
super(Vector, self).__init__(x, y)
|
||||
|
||||
|
||||
class SomeEntity(Entity):
|
||||
def __init__(self, world):
|
||||
# This will associate self.position2d with the new Position2D
|
||||
# value, while the previous Vector association is overwritten
|
||||
self.position2d = Position2D(4, 4)
|
||||
|
||||
# self.vector will also associate a self.position2d attribute
|
||||
# with the Entity, since Vector inherits from Position2D. The
|
||||
# original association will vanish, and each call to
|
||||
# entity.position2d will effectively manipulate the vector!
|
||||
self.vector = Vector(1,2,3)
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
.. class:: Entity(world : World)
|
||||
|
||||
An entity is a specific object living in the application world. It
|
||||
does not carry any data or application logic, but merely acts as
|
||||
identifier label for data that is maintained in the application
|
||||
world itself.
|
||||
|
||||
As such, it is a composition of components, which would not exist
|
||||
without the entity identifier. The entity itself is non-existent to
|
||||
the application world as long as it does not carry any data that can
|
||||
be processed by a system within the application world.
|
||||
|
||||
.. attribute:: id
|
||||
|
||||
The id of the Entity. Every Entity has a unique id, that is
|
||||
represented by a :class:`uuid.UUID` instance.
|
||||
|
||||
.. attribute:: world
|
||||
|
||||
The :class:`World` the entity resides in.
|
||||
|
||||
.. method:: delete() -> None
|
||||
|
||||
Deletes the :class:`Entity` from its :class:`World`. This
|
||||
basically calls :meth:`World.delete()` with the :class:`Entity`.
|
||||
|
||||
.. class:: Applicator()
|
||||
|
||||
A processing system for combined data sets. The :class:`Applicator`
|
||||
is an enhanced :class:`System` that receives combined data sets based
|
||||
on its set :attr:`System.componenttypes`
|
||||
|
||||
.. attribute:: is_applicator
|
||||
|
||||
A boolean flag indicating that this class operates on combined data sets.
|
||||
|
||||
.. attribute:: componenttypes
|
||||
|
||||
A tuple of class identifiers that shall be processed by the
|
||||
:class:`Applicator`.
|
||||
|
||||
.. function:: process(world : World, componentsets : iterable)
|
||||
|
||||
Processes tuples of component items. *componentsets* will
|
||||
contain object tuples, that match the :attr:`componenttypes`
|
||||
of the :class:`Applicator`. If, for example, the :class:`Applicator`
|
||||
is defined as ::
|
||||
|
||||
class MyApplicator(Applicator):
|
||||
def __init__(self):
|
||||
self.componenttypes = (Foo, Bar)
|
||||
|
||||
its process method will receive ``(Foo, Bar)`` tuples ::
|
||||
|
||||
def process(self, world, componentsets):
|
||||
for foo_item, bar_item in componentsets:
|
||||
...
|
||||
|
||||
Additionally, the :class:`Applicator` will not process all possible
|
||||
combinations of valid components, but only those, which are associated
|
||||
with the same :class:`Entity`. That said, an :class:`Entity` *must*
|
||||
contain a ``Foo`` as well as a ``Bar`` component in order to
|
||||
have them both processed by the :class:`Applicator` (while a
|
||||
:class:`System` with the same ``componenttypes`` would pick either of
|
||||
them, depending on their availability).
|
||||
|
||||
.. class:: System()
|
||||
|
||||
A processing system within an application world consumes the
|
||||
components of all entities, for which it was set up. At time of
|
||||
processing, the system does not know about any other component type
|
||||
that might be bound to any entity.
|
||||
|
||||
Also, the processing system does not know about any specific entity,
|
||||
but only is aware of the data carried by all entities.
|
||||
|
||||
.. attribute:: componenttypes
|
||||
|
||||
A tuple of class identifiers that shall be processed by the
|
||||
:class:`System`
|
||||
|
||||
.. method:: process(world : World, components : iterable)
|
||||
|
||||
Processes component items.
|
||||
|
||||
This method has to be implemented by inheriting classes.
|
||||
|
||||
|
||||
.. class:: World()
|
||||
|
||||
An application world defines the combination of application data and
|
||||
processing logic and how the data will be processed. As such, it is a
|
||||
container object in which the application is defined.
|
||||
|
||||
The application world maintains a set of entities and their related
|
||||
components as well as a set of systems that process the data of the
|
||||
entities. Each processing system within the application world only
|
||||
operates on a certain set of components, but not all components of an
|
||||
entity at once.
|
||||
|
||||
The order in which data is processed depends on the order of the
|
||||
added systems.
|
||||
|
||||
.. attribute:: systems
|
||||
|
||||
The processing system objects bound to the world.
|
||||
|
||||
.. method:: add_system(system : object)
|
||||
|
||||
Adds a processing system to the world. The system will be
|
||||
added as last item in the processing order.
|
||||
|
||||
The passed system does not have to inherit from :class:`System`, but
|
||||
must feature a ``componenttypes`` attribute and a ``process()`` method,
|
||||
which match the signatures of the :class:`System` class ::
|
||||
|
||||
class MySystem(object):
|
||||
def __init__(self):
|
||||
# componenttypes can be any iterable as long as it
|
||||
# contains the classes the system should take care of
|
||||
self.componenttypes = [AClass, AnotherClass, ...]
|
||||
|
||||
def process(self, world, components):
|
||||
...
|
||||
|
||||
If the system shall operate on combined component sets as specified
|
||||
by the :class:`Applicator`, the class instance must contain a
|
||||
``is_applicator`` property, that evaluates to ``True`` ::
|
||||
|
||||
class MyApplicator(object):
|
||||
def __init__(self):
|
||||
self.is_applicator = True
|
||||
self.componenttypes = [...]
|
||||
|
||||
def process(self, world, components):
|
||||
pass
|
||||
|
||||
The behaviour can be changed at run-time. The ``is_applicator`` attribute
|
||||
is evaluated for every call to :meth:`World.process()`.
|
||||
|
||||
.. method:: delete(entity : Entity)
|
||||
|
||||
Removes an :class:`Entity` from the World, including all its
|
||||
component data.
|
||||
|
||||
.. method:: delete_entities(entities : iterable)
|
||||
|
||||
Removes a set of :class:`Entity` instances from the World,
|
||||
including all their component data.
|
||||
|
||||
.. method:: insert_system(index : int, system : System)
|
||||
|
||||
Adds a processing :class:`System` to the world. The system will be
|
||||
added at the specified position in the processing order.
|
||||
|
||||
.. method:: get_entities(component : object) -> [Entity, ...]
|
||||
|
||||
Gets the entities using the passed component.
|
||||
|
||||
.. note::
|
||||
|
||||
This will not perform an identity check on the component
|
||||
but rely on its ``__eq__`` implementation instead.
|
||||
|
||||
.. method:: process()
|
||||
|
||||
Processes all component items within their corresponding
|
||||
:class:`System` instances.
|
||||
|
||||
.. method:: remove_system(system : System)
|
||||
|
||||
Removes a processing :class:`System` from the world.
|
|
@ -0,0 +1,81 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
General purpose event handling routines
|
||||
=======================================
|
||||
|
||||
.. class:: EventHandler(sender)
|
||||
|
||||
A simple event handling class, which manages callbacks to be
|
||||
executed.
|
||||
|
||||
The EventHandler does not need to be kept as separate instance, but
|
||||
is mainly intended to be used as attribute in event-aware class
|
||||
objects. ::
|
||||
|
||||
>>> def myfunc(sender):
|
||||
... print("event triggered by %s" % sender)
|
||||
...
|
||||
>>> class MyClass(object):
|
||||
... def __init__(self):
|
||||
... self.anevent = EventHandler(self)
|
||||
...
|
||||
>>> myobj = MyClass()
|
||||
>>> myobj.anevent += myfunc
|
||||
>>> myobj.anevent()
|
||||
event triggered by <__main__.MyClass object at 0x801864e50>
|
||||
|
||||
.. attribute:: callbacks
|
||||
|
||||
A list of callbacks currently bound to the :class:`EventHandler`.
|
||||
|
||||
.. attribute:: sender
|
||||
|
||||
The responsible object that executes the :class:`EventHandler`.
|
||||
|
||||
.. method:: add(callback : Callable)
|
||||
|
||||
Adds a callback to the :class:`EventHandler`.
|
||||
|
||||
.. method:: remove(callback : Callable)
|
||||
|
||||
Removes a callback from the :class:`EventHandler`.
|
||||
|
||||
.. method:: __call__(*args) -> [ ... ]
|
||||
|
||||
Executes all connected callbacks in the order of addition,
|
||||
passing the :attr:`sender` of the :class:`EventHandler` as first
|
||||
argument and the optional args as second, third, ... argument to
|
||||
them.
|
||||
|
||||
This will return a list containing the return values of the callbacks
|
||||
in the order of their execution.
|
||||
|
||||
|
||||
.. class:: MPEventHandler(sender)
|
||||
|
||||
An asynchronous event handling class based on :class:`EventHandler`,
|
||||
in which callbacks are executed in parallel. It is the responsibility
|
||||
of the caller code to ensure that every object used maintains a
|
||||
consistent state. The :class:`MPEventHandler` class will not apply
|
||||
any locks, synchronous state changes or anything else to the
|
||||
arguments or callbacks being used. Consider it a "fire-and-forget" event
|
||||
handling strategy.
|
||||
|
||||
.. note::
|
||||
|
||||
The :class:`MPEventHandler` relies on the :mod:`multiprocessing`
|
||||
module. If the module is not available in the target environment,
|
||||
a :exc:`sdl2.ext.compat.UnsupportedError` is raised.
|
||||
|
||||
Also, please be aware of the restrictions that apply to the
|
||||
:mod:`multiprocessing` module; arguments and callback functions for
|
||||
example have to be pickable, etc.
|
||||
|
||||
.. method:: __call__(*args) -> AsyncResult
|
||||
|
||||
Executes all connected callbacks within a
|
||||
:class:`multiprocessing.pool.Pool`, passing the :attr:`sender` as first
|
||||
argument and the optional *args* as second, third, ... argument to them.
|
||||
|
||||
This will return a :class:`multiprocessing.pool.AsyncResult` containing
|
||||
the return values of the callbacks in the order of their execution.
|
|
@ -0,0 +1,114 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
Text rendering routines
|
||||
=======================
|
||||
|
||||
.. class:: BitmapFont(surface : Sprite, size : iterable[, mapping=None)
|
||||
|
||||
A bitmap graphics to character mapping. The :class:`BitmapFont` class
|
||||
uses an image *surface* to find and render font character glyphs for
|
||||
text. It requires a mapping table, which denotes the characters
|
||||
available on the image.
|
||||
|
||||
The mapping table is a list of strings, where each string reflects a
|
||||
*line* of characters on the image. Each character within each line
|
||||
has the same size as specified by the size argument.
|
||||
|
||||
A typical mapping table might look like ::
|
||||
|
||||
[ '0123456789',
|
||||
'ABCDEFGHIJ',
|
||||
'KLMNOPQRST',
|
||||
'UVWXYZ ',
|
||||
'abcdefghij',
|
||||
'klmnopqrst',
|
||||
'uvwxyz ',
|
||||
',;.:!?+-()' ]
|
||||
|
||||
.. attribute:: surface
|
||||
|
||||
The :class:`sdl2.SDL_Surface` containing the character bitmaps.
|
||||
|
||||
.. attribute:: offsets
|
||||
|
||||
A dict containing the character offsets on the :attr:`surface`.
|
||||
|
||||
.. attribute:: mapping
|
||||
|
||||
The character mapping table, a list of strings.
|
||||
|
||||
.. attribute:: size
|
||||
|
||||
The size of an individual glyph bitmap on the font.
|
||||
|
||||
.. method:: render(text : string[, bpp=None]) -> Sprite
|
||||
|
||||
Renders the passed text on a new :class:`Sprite` and returns it.
|
||||
If no explicit *bpp* are provided, the bpp settings of the
|
||||
:attr:`.surface` are used.
|
||||
|
||||
.. method:: render_on(surface : Sprite, text : string[, \
|
||||
offset=(0, 0)]) -> (int, int, int, int)
|
||||
|
||||
Renders a text on the passed sprite, starting at a specific
|
||||
offset. The top-left start position of the text will be the
|
||||
passed *offset* and a 4-value tuple with the changed area will be
|
||||
returned.
|
||||
|
||||
.. method:: contains(c : string) -> bool
|
||||
|
||||
Checks, whether a certain character exists in the font.
|
||||
|
||||
.. method:: can_render(text : string) -> bool
|
||||
|
||||
Checks, whether all characters in the passed *text* can be rendered.
|
||||
|
||||
.. class:: FontManager(font_path : str[, alias=None[, size=16[, color=Color(255, 255, 255)[, bg_color=Color(0, 0, 0)[, index=0]]]]])
|
||||
|
||||
Manage fonts and rendering of text.
|
||||
|
||||
One font path must be given to initialise the FontManager.
|
||||
:attr:`default_font` will be set to this font. *size* is the default
|
||||
font size in pixels. *color* and *bg_color* will give the FontManager
|
||||
a default color. *index* will select a specific font face from a file
|
||||
containing multiple font faces. The first face is always at index 0. It can
|
||||
be used for TTC (TrueType Font Collection) fonts.
|
||||
|
||||
.. attribute:: bg_color
|
||||
|
||||
The :class:`sdl2.ext.Color` to be used as background color.
|
||||
|
||||
.. attribute:: color
|
||||
|
||||
The :class:`sdl2.ext.Color` to be used for rendering text.
|
||||
|
||||
.. attribute:: default_font
|
||||
|
||||
Returns the name of the current default font being used by the
|
||||
:class:`FontManager`. On assigning :attr:`default_font`,
|
||||
the value must be a loaded font alias.
|
||||
|
||||
.. attribute:: size
|
||||
|
||||
The default font size in pixels.
|
||||
|
||||
.. method:: add(font_path : str[, alias=None[, size=None[, index=0]]])) -> sdl2.sdlttf.TTF_Font
|
||||
|
||||
Add a font to the :class:`FontManager`. *alias* is by default the
|
||||
font name, any other name can be passed, *size* is the font size
|
||||
in pixels and defaults to :attr:`size`. *index* selects a specific font
|
||||
face from a TTC (TrueType Font Collection) file. Returns the font pointer
|
||||
stored in :attr:`fonts`.
|
||||
|
||||
.. method:: close()
|
||||
|
||||
Closes all fonts used by the :class:`FontManager`.
|
||||
|
||||
.. method:: render(text : str[, alias=None[, size=None[, width=None[, color=None[, bg_color=None[, **kwargs]]]]]]) -> sdl2.SDL_Surface
|
||||
|
||||
Renders text to a surface. This method uses the font designated by
|
||||
the passed *alias* or, if *alias* is omitted, by the set
|
||||
:attr:`default_font`. A *size* can be passed even if the font was
|
||||
not loaded with this size. A *width* can be given for automatic line
|
||||
wrapping. If no *bg_color* or *color* are given, it will default to
|
||||
the FontManager's :attr:`bg_color` and :attr:`color`.
|
|
@ -0,0 +1,284 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
User interface elements
|
||||
=======================
|
||||
User interface elements within :mod:`sdl2.ext` are simple
|
||||
:class:`Sprite` objects, which are enhanced by certain input hooks; as such,
|
||||
they are not classes on their own, but implemented as mixins. The user input
|
||||
itself is handled by an :class:`UIProcessor` object, which takes care of
|
||||
delegating input events, such as mouse movements, clicks and keyboard input,
|
||||
to the correct UI element.
|
||||
|
||||
Depending on the event type (e.g. pressing a mouse button), the UIProcessor
|
||||
will execute its matching method (e.g. ``mousedown()``) with only those UI
|
||||
elements, which support the event type.
|
||||
|
||||
.. image:: images/uiprocessing.png
|
||||
|
||||
.. _ui-elem-types:
|
||||
|
||||
UI element types
|
||||
----------------
|
||||
Every :class:`sdl2.ext` UI element is a simple :class:`Sprite` object, to
|
||||
which additional attributes and methods are bound.
|
||||
|
||||
Every UI element features the following attributes
|
||||
|
||||
``element.uitype``
|
||||
|
||||
The ``uitype`` attribute can have one of the following values,
|
||||
identifying the UI element:
|
||||
|
||||
* ``BUTTON`` - a UI element, which can react on mouse input
|
||||
* ``CHECKBUTTON`` - as ``BUTTON``, but it retains its state on clicks
|
||||
* ``TEXTENTRY`` - a UI element that reacts on keyboard input
|
||||
|
||||
``element.events``
|
||||
|
||||
A dictionary containing the SDL2 event mappings. Each supported SDL2 event
|
||||
(e.g. ``SDL_MOUSEMOTION``) is associated with a bound
|
||||
:class:`EventHandler` acting as callback for user code
|
||||
(e.g. ``mousemotion()``).
|
||||
|
||||
Depending on the exact type of the element, it will feature additional methods
|
||||
and attributes explained below.
|
||||
|
||||
Button elements
|
||||
^^^^^^^^^^^^^^^
|
||||
``BUTTON`` UI elements feature a ``state`` attribute, which can be one of the
|
||||
following values.
|
||||
|
||||
======== =====================================================================
|
||||
state Description
|
||||
======== =====================================================================
|
||||
RELEASED Indicates that the UI element is not pressed.
|
||||
HOVERED Indicates that the mouse cursor is currently hovering the UI element.
|
||||
PRESSED Indicates that a mouse button is pressed on the UI element.
|
||||
======== =====================================================================
|
||||
|
||||
``BUTTON`` UI elements react with the following event handlers on events:
|
||||
|
||||
``button.motion(event : sdl2.events.SDL_Event)``
|
||||
|
||||
An :class:`EventHandler` that is invoked, if the mouse moves around while
|
||||
being over the ``BUTTON``.
|
||||
|
||||
``button.pressed(event : sdl2.events.SDL_Event)``
|
||||
|
||||
An :class:`EventHandler` that is invoked, if a mouse button is pressed on
|
||||
the ``BUTTON``.
|
||||
|
||||
``button.released(event : sdl2.events.SDL_Event)``
|
||||
|
||||
An :class:`EventHandler` that is invoked, if a mouse button is released on
|
||||
the ``BUTTON``.
|
||||
|
||||
``button.click(event : sdl2.events.SDL_Event)``
|
||||
|
||||
An :class:`EventHandler` that is invoked, if a mouse button is pressed and
|
||||
released on the ``BUTTON``.
|
||||
|
||||
Besides the ``BUTTON`` a special ``CHECKBUTTON`` UI element type exists,
|
||||
which enhances the ``BUTTON`` bindings by an additional ``checked`` attribute.
|
||||
The ``checked`` attribute switches its status (``False`` to ``True`` and
|
||||
``True`` to ``False``) every time the UI element is clicked.
|
||||
|
||||
Text input elements
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
``TEXTENTRY`` elements react on text input, once they are activated. Text being
|
||||
input, once a ``TEXTENTRY`` has been activated, is stored in its ``text``
|
||||
attribute.
|
||||
|
||||
The ``TEXTENTRY`` reacts with the following event handlers on events:
|
||||
|
||||
``textentry.motion(event : sdl2.events.SDL_Event)``
|
||||
|
||||
An :class:`EventHandler` that is invoked, if the mouse moves around while
|
||||
being over the ``TEXTENTRY``.
|
||||
|
||||
``textentry.pressed(event : sdl2.events.SDL_Event)``
|
||||
|
||||
An :class:`EventHandler` that is invoked, if a mouse button is pressed on
|
||||
the ``TEXTENTRY``.
|
||||
|
||||
``textentry.released(event : sdl2.events.SDL_Event)``
|
||||
|
||||
An :class:`EventHandler` that is invoked, if a mouse button is released on
|
||||
the ``TEXTENTRY``.
|
||||
|
||||
``textentry.keydown(event : sdl2.events.SDL_Event)``
|
||||
|
||||
An :class:`EventHandler` that is invoked on pressing a key.
|
||||
|
||||
``textentry.keyup(event : sdl2.events.SDL_Event)``
|
||||
|
||||
An :class:`EventHandler` that is invoked on releasing a key.
|
||||
|
||||
``textentry.input(event : sdl2.events.SDL_Event)``
|
||||
|
||||
An :class:`EventHandler` that is invoked on text input events.
|
||||
Text input events are automatically created, once the :class:`UIProcessor`
|
||||
activates a ``TEXTENTRY`` UI element.
|
||||
|
||||
``textentry.editing(event : sdl2.events.SDL_Event)``
|
||||
|
||||
An :class:`EventHandler` that is invoked on text editing events. Text
|
||||
editing events are automatically created, once the :class:`UIProcessor`
|
||||
activates a ``TEXTENTRY`` UI element.
|
||||
|
||||
Text editing events are however only raised, if an IME system is involved,
|
||||
which combines glyphs and symbols to characters or word fragments.
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
.. class:: UIFactory(spritefactory : SpriteFactory[, **kwargs])
|
||||
|
||||
A factory class for creating UI elements. The :class:`UIFactory`
|
||||
allows you to create UI elements based on the
|
||||
:class:`Sprite` class. To do this, it requires a :class:`SpriteFactory`,
|
||||
which will create the sprites, to which the :class:`UIFactory` then binds
|
||||
the additional methods and attributes.
|
||||
|
||||
The additional *kwargs* are used as default arguments for creating
|
||||
**sprites** within the factory methods.
|
||||
|
||||
.. attribute:: default_args
|
||||
|
||||
A dictionary containing the default arguments to be passed to the
|
||||
sprite creation methods of the bound :class:`SpriteFactory`.
|
||||
|
||||
.. attribute:: spritefactory
|
||||
|
||||
The :class:`SpriteFactory` being used for creating new :class:`Sprite`
|
||||
objects.
|
||||
|
||||
.. method:: create_button(**kwargs) -> Sprite
|
||||
|
||||
Creates a new button UI element.
|
||||
|
||||
*kwargs* are the arguments to be passed for the sprite
|
||||
construction and can vary depending on the sprite type.
|
||||
See :meth:`SpriteFactory.create_sprite()` for further details.
|
||||
|
||||
.. method:: create_check_button(**kwargs) -> Sprite
|
||||
|
||||
Creates a new checkbutton UI element.
|
||||
|
||||
*kwargs* are the arguments to be passed for the sprite
|
||||
construction and can vary depending on the sprite type.
|
||||
See :meth:`SpriteFactory.create_sprite()` for further details.
|
||||
|
||||
.. method:: create_text_entry(**kwargs) -> Sprite
|
||||
|
||||
Creates a new textentry UI element.
|
||||
|
||||
*kwargs* are the arguments to be passed for the sprite
|
||||
construction and can vary depending on the sprite type.
|
||||
See :meth:`SpriteFactory.create_sprite()` for further details.
|
||||
|
||||
.. method:: from_color(color : object , size) -> Sprite
|
||||
|
||||
Creates a UI element with a specific color.
|
||||
|
||||
*uitype* must be one of the supported :ref:`ui-elem-types` classifying
|
||||
the type of UI element to be created.
|
||||
|
||||
.. method:: from_image(uitype : int, fname : str) -> Sprite
|
||||
|
||||
Creates a UI element from an image file. The image must be
|
||||
loadable via :func:`load_image()`.
|
||||
|
||||
*uitype* must be one of the supported :ref:`ui-elem-types` classifying
|
||||
the type of UI element to be created.
|
||||
|
||||
.. method:: from_object(uitype : int, obj: object) -> Sprite
|
||||
|
||||
Creates a UI element from an object. The object will be passed through
|
||||
:func:`sdl2.rwops_from_object()` in order to try to load image data from
|
||||
it.
|
||||
|
||||
*uitype* must be one of the supported :ref:`ui-elem-types` classifying
|
||||
the type of UI element to be created.
|
||||
|
||||
.. method:: from_surface(uitype : int, surface : SDL_Surface[, free=False]) -> Sprite
|
||||
|
||||
Creates a UI element from the passed
|
||||
:class:`sdl2.surface.SDL_Surface`. If *free* is set to
|
||||
``True``, the passed *surface* will be freed automatically.
|
||||
|
||||
*uitype* must be one of the supported :ref:`ui-elem-types` classifying
|
||||
the type of UI element to be created.
|
||||
|
||||
.. class:: UIProcessor()
|
||||
|
||||
A processing system for user interface elements and events.
|
||||
|
||||
.. attribute:: handlers
|
||||
|
||||
A dict containing the mapping of SDL2 events to the available
|
||||
:class:`EventHandler` bindings of the :class:`UIProcessor`.
|
||||
|
||||
.. method:: activate(component : object) -> None
|
||||
|
||||
Activates a UI control to receive text input.
|
||||
|
||||
.. method:: deactivate(component : object) -> None
|
||||
|
||||
Deactivate the currently active UI control.
|
||||
|
||||
.. method:: passevent(component : object, event : SDL_Event) -> None
|
||||
|
||||
Passes the *event* to a *component* without any additional checks or
|
||||
restrictions.
|
||||
|
||||
.. method:: mousemotion(component : object, event : SDL_Event) -> None
|
||||
|
||||
Checks, if the event's motion position is on the *component* and
|
||||
executes the component's event handlers on demand. If the motion event
|
||||
position is not within the area of the *component*, nothing will be
|
||||
done. In case the component is a ``BUTTON``, its :attr:`state` will be
|
||||
adjusted to reflect, if it is currently hovered or not.
|
||||
|
||||
.. method:: mousedown(component : object, event : SDL_Event) -> None
|
||||
|
||||
Checks, if the event's button press position is on the *component* and
|
||||
executes the component's event handlers on demand. If the button press
|
||||
position is not within the area of the component, nothing will be done.
|
||||
|
||||
In case the component is a ``BUTTON``, its :attr:`state`
|
||||
will be adjusted to reflect, if it is currently pressed or not.
|
||||
|
||||
In case the component is a ``TEXTENTRY`` and the pressed button is
|
||||
the primary mouse button, the component will be marked as the next
|
||||
control to activate for text input.
|
||||
|
||||
.. method:: mouseup(self, component, event) -> None
|
||||
|
||||
Checks, if the event's button release position is on the *component* and
|
||||
executes the component's event handlers on demand. If the button release
|
||||
position is not within the area of the component, nothing will be done.
|
||||
|
||||
In case the component is a ``BUTTON``, its :attr:`state`
|
||||
will be adjusted to reflect, whether it is hovered or not.
|
||||
|
||||
If the button release followed a button press on the same component and
|
||||
if the button is the primary button, the ``click()`` event handler is
|
||||
invoked, if the component is a ``BUTTON``.
|
||||
|
||||
.. method:: dispatch(obj : object, event : SDL_Event) -> None
|
||||
|
||||
Passes an event to the given object. If *obj* is a
|
||||
:class:`World` object, UI relevant components will receive
|
||||
the event, if they support the event type. If *obj* is a single object,
|
||||
``obj.events`` **must** be a dict consisting of SDL event type
|
||||
identifiers and :class:`EventHandler` instances bound
|
||||
to the object. If *obj* is a iterable, such as a list or set, every
|
||||
item within *obj* **must** feature an ``events`` attribute as
|
||||
described above.
|
||||
|
||||
.. method:: process(world : World, components : iterable) -> None
|
||||
|
||||
The :class:`UIProcessor` class does not implement the `process()`
|
||||
method by default. Instead it uses :meth:`dispatch()` to send events
|
||||
around to components. :meth:`process()` does nothing.
|
|
@ -0,0 +1,27 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
Image loaders
|
||||
=============
|
||||
|
||||
.. function:: get_image_formats() -> (str, str, ...)
|
||||
|
||||
Gets the formats supported by PySDL2 in the default installation.
|
||||
|
||||
.. function:: load_image(fname : str[, enforce=None]) -> sdl2.SDL_Surface
|
||||
|
||||
Creates a :class:`sdl2.SDL_Surface` from an image file.
|
||||
|
||||
This function makes use of the `Python Imaging Library
|
||||
<http://www.pythonware.com/products/pil/>`_, if it is available on the
|
||||
target execution environment. The function will try to load the file via
|
||||
:mod:`sdl2` first. If the file could not be loaded, it will try to load it
|
||||
via :mod:`sdl2.sdlimage` and PIL.
|
||||
|
||||
You can force the function to use only one of them, by passing the
|
||||
*enforce* as either ``"PIL"`` or ``"SDL"``.
|
||||
|
||||
.. note::
|
||||
|
||||
This will call :func:`sdl2.sdlimage.IMG_Init()` implicitly with the
|
||||
default arguments, if the module is available and if
|
||||
:func:`sdl2.SDL_LoadBMP()` failed to load the image.
|
|
@ -0,0 +1,96 @@
|
|||
.. module:: sdl2.ext.particles
|
||||
:synopsis: A simple particle system.
|
||||
|
||||
sdl2.ext.particles - A simple particle system
|
||||
=============================================
|
||||
|
||||
.. class:: ParticleEngine()
|
||||
|
||||
A simple particle processing system. The :class:`ParticleEngine`
|
||||
takes care of creating, updating and deleting particles via callback
|
||||
functions. It only decreases the life of the particles by itself and
|
||||
marks them as dead, once the particle's life attribute has reached 0
|
||||
or below.
|
||||
|
||||
.. attribute:: createfunc
|
||||
|
||||
Function for creating new particles. The function needs to take
|
||||
two arguments, the ``world`` argument passed to :meth:`process()`
|
||||
and a list of the particles considered dead (:attr:`Particle.life`
|
||||
<= 0). ::
|
||||
|
||||
def creation_func(world, deadparticles):
|
||||
...
|
||||
|
||||
.. attribute:: updatefunc
|
||||
|
||||
Function for updating existing, living particles. The function
|
||||
needs to take two arguments, the ``world`` argument passed to
|
||||
:meth:`process()` and a :class:`set` of the still living
|
||||
particles. ::
|
||||
|
||||
def update_func(world, livingparticles):
|
||||
...
|
||||
|
||||
.. attribute:: deletefunc
|
||||
|
||||
Function for deleting dead particles. The function needs to take
|
||||
two arguments, the ``world`` argument passed to :meth:`process()`
|
||||
and a list of the particles considered dead (:attr:`Particle.life`
|
||||
<= 0). ::
|
||||
|
||||
def deletion_func(world, deadparticles):
|
||||
...
|
||||
|
||||
.. method:: process(world : World, components : iterable) -> None
|
||||
|
||||
Processes all particle components, decreasing their life by 1.
|
||||
|
||||
Once the life of all particle components has been decreased
|
||||
properly and the particles considered dead (life <= 0) are
|
||||
identified, the creation, update and deletion callbacks are
|
||||
invoked.
|
||||
|
||||
The creation callback takes the passed world as first and the
|
||||
list of dead particles as second argument. ::
|
||||
|
||||
def particle_createfunc(world, list_of_dead_ones):
|
||||
...
|
||||
|
||||
Afterwards the still living particles are passed to the update
|
||||
callback, which also take the passed world as first and the
|
||||
living particles as set as second argument. ::
|
||||
|
||||
def particle_updatefunc(world, set_of_living_ones):
|
||||
...
|
||||
|
||||
Finally, the dead particles need to be deleted in some way or
|
||||
another, which is done by the deletion callback, taking the
|
||||
passed world as first and the list of dead particles as second
|
||||
argument. ::
|
||||
|
||||
def particle_deletefunc(world, list_of_dead_ones):
|
||||
...
|
||||
|
||||
.. class:: Particle(x, y, life : int)
|
||||
|
||||
A simple particle component type. It only contains information about
|
||||
a x- and y-coordinate and its current life time. The life time will
|
||||
be decreased by 1, every time the particle is processed by the
|
||||
:class:`ParticleEngine`.
|
||||
|
||||
.. attribute:: x
|
||||
|
||||
The x coordinate of the particle.
|
||||
|
||||
.. attribute:: y
|
||||
|
||||
The y coordinate of the particle.
|
||||
|
||||
.. attribute:: life
|
||||
|
||||
The remaining life time of the particle.
|
||||
|
||||
.. attribute:: position
|
||||
|
||||
The x- and y-coordinate of the particle as tuple.
|
|
@ -0,0 +1,56 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
2D and 3D direct pixel access
|
||||
=============================
|
||||
|
||||
.. class:: PixelView(source : object)
|
||||
|
||||
2D :class:`MemoryView` for :class:`SoftwareSprite` and
|
||||
:class:`sdl2.SDL_surface` pixel access.
|
||||
|
||||
.. note::
|
||||
|
||||
If necessary, the *source* surface will be locked for accessing its
|
||||
pixel data. The lock will be removed once the :class:`PixelView` is
|
||||
garbage-collected or deleted.
|
||||
|
||||
The :class:`PixelView` uses a y/x-layout. Accessing ``view[N]`` will
|
||||
operate on the Nth row of the underlying surface. To access a specific
|
||||
column within that row, ``view[N][C]`` has to be used.
|
||||
|
||||
.. note::
|
||||
|
||||
:class:`PixelView` is implemented on top of the :class:`MemoryView`
|
||||
class. As such it makes heavy use of recursion to access rows and
|
||||
columns and can be considered as slow in contrast to optimised
|
||||
ndim-array solutions such as :mod:`numpy`.
|
||||
|
||||
.. function:: pixels2d(source : object)
|
||||
|
||||
Creates a 2D pixel array, based on ``numpy.ndarray``, from the passed
|
||||
*source*. *source* can be a :class:`SoftwareSprite` or
|
||||
:class:`sdl2.SDL_Surface`. The ``SDL_Surface`` of the *source* will be
|
||||
locked and unlocked automatically.
|
||||
|
||||
The *source* pixels will be accessed and manipulated directly.
|
||||
|
||||
.. note::
|
||||
|
||||
:func:`pixels2d` is only usable, if the numpy package is available
|
||||
within the target environment. If numpy could not be imported, a
|
||||
:exc:`sdl2.ext.compat.UnsupportedError` will be raised.
|
||||
|
||||
.. function:: pixels3d(source : object)
|
||||
|
||||
Creates a 3D pixel array, based on ``numpy.ndarray``, from the passed
|
||||
*source*. *source* can be a :class:`SoftwareSprite`
|
||||
or :class:`sdl2.SDL_Surface`. The ``SDL_Surface`` of the *source*
|
||||
will be locked and unlocked automatically.
|
||||
|
||||
The *source* pixels will be accessed and manipulated directly.
|
||||
|
||||
.. note::
|
||||
|
||||
:func:`pixels3d` is only usable, if the numpy package is available
|
||||
within the target environment. If numpy could not be imported, a
|
||||
:exc:`sdl2.ext.compat.UnsupportedError` will be raised.
|
|
@ -0,0 +1,180 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
Resource management
|
||||
===================
|
||||
Every application usually ships with various resources, such as image and data
|
||||
files, configuration files and so on. Accessing those files in the folder
|
||||
hierarchy or in a bundled format for various platforms can become a complex
|
||||
task. The :class:`Resources` class allows you to manage different application
|
||||
data in a certain directory, providing a dictionary-style access functionality
|
||||
for your in-application resources.
|
||||
|
||||
Let's assume, your application has the following installation layout ::
|
||||
|
||||
Application Directory
|
||||
Application.exe
|
||||
Application.conf
|
||||
data/
|
||||
background.jpg
|
||||
button1.jpg
|
||||
button2.jpg
|
||||
info.dat
|
||||
|
||||
Within the ``Application.exe`` code, you can - completely system-agnostic -
|
||||
define a new resource that keeps track of all ``data`` items. ::
|
||||
|
||||
apppath = os.path.dirname(os.path.abspath(__file__))
|
||||
appresources = Resources(os.path.join(apppath, "data"))
|
||||
# Access some images
|
||||
bgimage = appresources.get("background.jpg")
|
||||
btn1image = appresources.get("button1.jpg")
|
||||
...
|
||||
|
||||
To access individual files, you do not need to concat paths the whole
|
||||
time and regardless of the current directory, your application operates
|
||||
on, you can access your resource files at any time through the
|
||||
:class:`Resources` instance, you created initially.
|
||||
|
||||
The :class:`Resources` class is also able to scan an index archived files,
|
||||
compressed via ZIP or TAR (gzip or bzip2 compression), and subdiectories
|
||||
automatically. ::
|
||||
|
||||
Application Directory
|
||||
Application.exe
|
||||
Application.conf
|
||||
data/
|
||||
audio/
|
||||
example.wav
|
||||
background.jpg
|
||||
button1.jpg
|
||||
button2.jpg
|
||||
graphics.zip
|
||||
[tileset1.bmp
|
||||
tileset2.bmp
|
||||
tileset3.bmp
|
||||
]
|
||||
info.dat
|
||||
|
||||
tilesimage = appresources.get("tileset1.bmp")
|
||||
audiofile = appresources.get("example.wav")
|
||||
|
||||
If you request an indexed file via :meth:`Resources.get`, you will receive
|
||||
a :class:`io.BytesIO` stream, containing the file data, for further processing.
|
||||
|
||||
.. note::
|
||||
|
||||
The scanned files act as keys within the :class:`Resources` class. This
|
||||
means that two files, that have the same name, but are located in different
|
||||
directories, will not be indexed. Only one of them will be accessible
|
||||
through the :class:`Resources` class.
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
.. class:: Resources([path=None[, subdir=None[, excludepattern=None]]])
|
||||
|
||||
The Resources class manages a set of file resources and eases
|
||||
accessing them by using relative paths, scanning archives
|
||||
automatically and so on.
|
||||
|
||||
.. method:: add(filename : string)
|
||||
|
||||
Adds a file to the resource container. Depending on the
|
||||
file type (determined by the file suffix or name) the file will be
|
||||
automatically scanned (if it is an archive) or checked for
|
||||
availability (if it is a stream or network resource).
|
||||
|
||||
.. method:: add_archive(filename : string[, typehint="zip"])
|
||||
|
||||
Adds an archive file to the resource container. This will scan the
|
||||
passed archive and add its contents to the list of available and
|
||||
accessible resources.
|
||||
|
||||
.. method:: add_file(filename : string)
|
||||
|
||||
Adds a file to the resource container. This will only add the
|
||||
passed file and do not scan an archive or check the file for
|
||||
availability.
|
||||
|
||||
.. method:: get(filename : string) -> BytesIO
|
||||
|
||||
Gets a specific file from the resource container.
|
||||
|
||||
Raises a :exc:`KeyError`, if the *filename* could not be found.
|
||||
|
||||
.. method:: get_filelike(filename : string) -> file object
|
||||
|
||||
Similar to :meth:`get()`, but tries to return the original file
|
||||
handle, if possible. If the found file is only available within an
|
||||
archive, a :class:`io.BytesIO` instance will be returned.
|
||||
|
||||
Raises a :exc:`KeyError`, if the *filename* could not be found.
|
||||
|
||||
.. method:: get_path(filename : string) -> string
|
||||
|
||||
Gets the path of the passed *filename*. If *filename* is only
|
||||
available within an archive, a string in the form
|
||||
``filename@archivename`` will be returned.
|
||||
|
||||
Raises a :exc:`KeyError`, if the *filename* could not be found.
|
||||
|
||||
.. method:: scan(path : string[, subdir=None[, excludepattern=None])
|
||||
|
||||
Scans a path and adds all found files to the resource
|
||||
container. If a file within the path is a supported archive (ZIP
|
||||
or TAR), its contents will be indexed aut added automatically.
|
||||
|
||||
The method will consider the directory part (``os.path.dirname``)
|
||||
of the provided *path* as path to scan, if the path is not a
|
||||
directory. If *subdir* is provided, it will be appended to the
|
||||
path and used as starting point for adding files to the resource
|
||||
container.
|
||||
|
||||
*excludepattern* can be a regular expression to skip
|
||||
directories, which match the pattern.
|
||||
|
||||
.. function:: open_tarfile(archive : string, filename : string \
|
||||
[, directory=None[, ftype=None]]) -> BytesIO
|
||||
|
||||
Opens and reads a certain file from a TAR archive. The result is
|
||||
returned as :class:`BytesIO` stream. *filename* can be a relative
|
||||
or absolute path within the TAR archive. The optional *directory*
|
||||
argument can be used to supply a relative directory path, under which
|
||||
*filename* will be searched.
|
||||
|
||||
*ftype* is used to supply additional compression information, in
|
||||
case the system cannot determine the compression type itself, and can
|
||||
be either **"gz"** for gzip compression or **"bz2"** for bzip2
|
||||
compression.
|
||||
|
||||
If the filename could not be found or an error occurred on reading it,
|
||||
``None`` will be returned.
|
||||
|
||||
Raises a :exc:`TypeError`, if *archive* is not a valid TAR archive or
|
||||
if *ftype* is not a valid value of ("gz", "bz2").
|
||||
|
||||
.. note::
|
||||
|
||||
If *ftype* is supplied, the compression mode will be enforced for
|
||||
opening and reading.
|
||||
|
||||
.. function:: open_url(filename : string[, basepath=None]) -> file object
|
||||
|
||||
Opens and reads a certain file from a web or remote location. This
|
||||
function utilizes the :mod:`urllib2` module for Python 2.7 and
|
||||
:mod:`urllib` for Python 3.x, which means that it is restricted to
|
||||
the types of remote locations supported by the module.
|
||||
|
||||
*basepath* can be used to supply an additional location prefix.
|
||||
|
||||
.. function:: open_zipfile(archive : string, filename : string \
|
||||
[, directory : string]) -> BytesIO
|
||||
|
||||
Opens and reads a certain file from a ZIP archive. The result is
|
||||
returned as :class:`BytesIO` stream. *filename* can be a relative
|
||||
or absolute path within the ZIP archive. The optional *directory*
|
||||
argument can be used to supply a relative directory path, under which
|
||||
*filename* will be searched.
|
||||
|
||||
If the filename could not be found, a :exc:`KeyError` will be raised.
|
||||
Raises a :exc:`TypeError`, if *archive* is not a valid ZIP archive.
|
|
@ -0,0 +1,383 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
Sprite, texture and pixel surface routines
|
||||
==========================================
|
||||
|
||||
.. data:: TEXTURE
|
||||
|
||||
Indicates that texture-based rendering or sprite creation is wanted.
|
||||
|
||||
.. data:: SOFTWARE
|
||||
|
||||
Indicates that software-based rendering or sprite creation is wanted.
|
||||
|
||||
.. class:: Sprite()
|
||||
|
||||
A simple 2D object, implemented as abstract base class.
|
||||
|
||||
.. attribute:: x
|
||||
|
||||
The top-left horizontal offset at which the :class:`Sprite`
|
||||
resides.
|
||||
|
||||
.. attribute:: y
|
||||
|
||||
The top-left vertical offset at which the :class:`Sprite`
|
||||
resides.
|
||||
|
||||
.. attribute:: position
|
||||
|
||||
The top-left position (:attr:`x` and :attr:`y`) as tuple.
|
||||
|
||||
.. attribute:: size
|
||||
|
||||
The width and height of the :class:`Sprite` as tuple.
|
||||
|
||||
.. note::
|
||||
|
||||
This is an abstract property and needs to be implemented by inheriting
|
||||
classes.
|
||||
|
||||
.. attribute:: area
|
||||
|
||||
The rectangular area occupied by the :class:`Sprite`.
|
||||
|
||||
.. attribute:: depth
|
||||
|
||||
The layer depth on which to draw the :class:`Sprite`.
|
||||
:class:`Sprite` objects with higher :attr:`depth` values will be
|
||||
drawn on top of other :class:`Sprite` values by the
|
||||
:class:`SpriteRenderSystem`.
|
||||
|
||||
.. class:: SoftwareSprite()
|
||||
|
||||
A simple, visible, pixel-based 2D object, implemented on top of
|
||||
SDL2 software surfaces.
|
||||
|
||||
.. attribute:: surface
|
||||
|
||||
The :class:`sdl2.SDL_Surface` containing the pixel data.
|
||||
|
||||
.. attribute:: size
|
||||
|
||||
The size of the :class:`SoftwareSprite` as tuple.
|
||||
|
||||
.. method:: subsprite(area : (int, int, int, int)) -> SoftwareSprite
|
||||
|
||||
Creates another :class:`SoftwareSprite` from a part of the
|
||||
:class:`SoftwareSprite`. The two sprites share pixel data, so if the
|
||||
parent sprite's surface is not managed by the sprite (``free`` is False),
|
||||
you will need to keep it alive while the subsprite exists.
|
||||
|
||||
.. class:: TextureSprite()
|
||||
|
||||
A simple, visible, pixel-based 2D object, implemented on top of SDL2
|
||||
textures.
|
||||
|
||||
.. attribute:: angle
|
||||
|
||||
The rotation angle for the :class:`TextureSprite`.
|
||||
|
||||
.. attribute:: center
|
||||
|
||||
The center to use for rotating the :class:`TextureSprite`. `None` will
|
||||
reset the center to the default center of the :class:`TextureSprite`.
|
||||
|
||||
.. attribute:: flip
|
||||
|
||||
Allows the :class:`TextureSprite` to be flipped over its horizontal or
|
||||
vertical axis via the appropriate SDL_FLIP_* value.
|
||||
|
||||
.. attribute:: size
|
||||
|
||||
The size of the :class:`TextureSprite` as tuple.
|
||||
|
||||
.. attribute:: texture
|
||||
|
||||
The :class:`sdl2.SDL_Texture` containing the texture data.
|
||||
|
||||
.. class:: SpriteRenderSystem()
|
||||
|
||||
A rendering system for :class:`Sprite` components. This is a base class for
|
||||
rendering systems capable of drawing and displaying :class:`Sprite` based
|
||||
objects. Inheriting classes need to implement the rendering capability by
|
||||
overriding the render() method.
|
||||
|
||||
.. attribute:: sortfunc
|
||||
|
||||
Sort function for the component processing order. The default sort order
|
||||
is based on the depth attribute of every sprite. Lower depth values will
|
||||
cause sprites to be drawn below sprites with higher depth values. If
|
||||
:attr:`sortfunc` shall be overridden, it must match the callback
|
||||
requirements for :func:`sorted()`.
|
||||
|
||||
.. method:: process(world : World, components : iterable) -> None
|
||||
|
||||
Renders the passed :class:`Sprite` objects via the
|
||||
:meth:`render()` method. The :class:`Sprite` objects are sorted
|
||||
via :attr:`sortfunc` before they are passed to :meth:`render()`.
|
||||
|
||||
.. method:: render(sprite : iterable) -> None
|
||||
|
||||
Renders the :class:`Sprite` objects.
|
||||
|
||||
.. note::
|
||||
|
||||
This is a no-op function and needs to be implemented by inheriting
|
||||
classes.
|
||||
|
||||
.. class:: SoftwareSpriteRenderSystem(window : object)
|
||||
|
||||
A rendering system for :class:`SoftwareSprite` components. The
|
||||
:class:`SoftwareSpriteRenderSystem` class uses a :class:`sdl2.SDL_Window` as
|
||||
drawing device to display :class:`SoftwareSprite` surfaces. It uses the
|
||||
internal SDL surface of the *window* as drawing context, so that GL
|
||||
operations, such as texture handling or the usage of SDL renderers is not
|
||||
possible.
|
||||
|
||||
*window* can be either a :class:`sdl2.ext.Window` or
|
||||
:class:`sdl2.SDL_Window` instance.
|
||||
|
||||
.. attribute:: window
|
||||
|
||||
The :class:`sdl2.SDL_Window` that is used as drawing device.
|
||||
|
||||
.. attribute:: surface
|
||||
|
||||
The :class:`sdl2.SDL_Surface` that acts as drawing context for
|
||||
:attr:`window`.
|
||||
|
||||
.. method:: render(sprites : object[, x=None[, y=None]]) -> None
|
||||
|
||||
Draws the passed *sprites* on the :class:`sdl2.ext.Window` surface. *x*
|
||||
and *y* are optional arguments that can be used as relative drawing
|
||||
location for *sprites*. If set to ``None``, the location information of
|
||||
the *sprites* are used. If set and *sprites* is an iterable, such as a
|
||||
list of :class:`SoftwareSprite` objects, *x* and *y* are relative
|
||||
location values that will be added to each individual sprite's
|
||||
position. If *sprites* is a single :class:`SoftwareSprite`, *x* and *y*
|
||||
denote the absolute position of the :class:`SoftwareSprite`, if set.
|
||||
|
||||
.. class:: TextureSpriteRenderSystem(target : object)
|
||||
|
||||
A rendering system for :class:`TextureSprite` components. The
|
||||
:class:`TextureSpriteRenderSystem` class uses a :class:`sdl2.SDL_Renderer` as
|
||||
drawing device to display :class:`Sprite` surfaces.
|
||||
|
||||
*target* can be a :class:`sdl2.ext.Window`, :class:`sdl2.SDL_Window`,
|
||||
a:class:`sdl2.ext.Renderer` or a :class:`sdl2.SDL_Renderer`. If it is a
|
||||
:class:`sdl2.ext.Window` or :class:`sdl2.SDL_Window` instance, it will try
|
||||
to create a :class:`sdl2.SDL_Renderer` with hardware acceleration for it.
|
||||
|
||||
.. attribute:: sdlrenderer
|
||||
|
||||
The :class:`sdl2.SDL_Renderer` that is used as drawing context.
|
||||
|
||||
.. attribute:: rendertarget
|
||||
|
||||
The target for which the :attr:`renderer` was created, if any.
|
||||
|
||||
.. method:: render(sprites : object[, x=None[, y=None]]) -> None
|
||||
|
||||
Renders the passed *sprites* via the :attr:`renderer`. *x* and
|
||||
*y* are optional arguments that can be used as relative drawing
|
||||
location for *sprites*. If set to ``None``, the location
|
||||
information of the *sprites* are used. If set and *sprites* is an
|
||||
iterable, such as a list of :class:`TextureSprite` objects, *x*
|
||||
and *y* are relative location values that will be added to each
|
||||
individual sprite's position. If *sprites* is a single
|
||||
:class:`TextureSprite`, *x* and *y* denote the absolute position of the
|
||||
:class:`TextureSprite`, if set.
|
||||
|
||||
.. class:: SpriteFactory(sprite_type=TEXTURE, **kwargs)
|
||||
|
||||
A factory class for creating :class:`Sprite` objects. The
|
||||
:class:`SpriteFactory` can create :class:`TextureSprite` or
|
||||
:class:`SoftwareSprite` instances, depending on the *sprite_type*
|
||||
being passed to it, which can be ``SOFTWARE`` or ``TEXTURE``. The
|
||||
additional *kwargs* are used as default arguments for creating
|
||||
sprites within the factory methods.
|
||||
|
||||
.. attribute:: sprite_type
|
||||
|
||||
The sprite type created by the factory. This will be either
|
||||
``SOFTWARE`` for :class:`SoftwareSprite` or ``TEXTURE`` for
|
||||
:class:`TextureSprite` objects.
|
||||
|
||||
.. attribute:: default_args
|
||||
|
||||
The default arguments to use for creating new sprites.
|
||||
|
||||
.. method:: create_software_sprite(size, bpp=32, masks=None) -> SoftwareSprite
|
||||
|
||||
Creates a software sprite. A *size* tuple containing the width and
|
||||
height of the sprite and a *bpp* value, indicating the bits per
|
||||
pixel to be used, need to be provided.
|
||||
|
||||
.. method:: create_sprite(**kwargs) -> Sprite
|
||||
|
||||
Creates a :class:`Sprite`. Depending on the :attr:`sprite_type`,
|
||||
this will return a :class:`SoftwareSprite` or
|
||||
:class:`TextureSprite`.
|
||||
|
||||
*kwargs* are the arguments to be passed for the sprite
|
||||
construction and can vary depending on the sprite type. Usually
|
||||
they have to follow the :meth:`create_software_sprite()` and
|
||||
:meth:`create_texture_sprite()` method signatures. *kwargs*
|
||||
however will be mixed with the set :attr:`default_args` so that
|
||||
one does not necessarily have to provide all arguments, if they
|
||||
are set within the :attr:`default_args`. If *kwargs* and
|
||||
:attr:`default_args` contain the same keys, the key-value pair of
|
||||
*kwargs* is chosen.
|
||||
|
||||
.. method:: create_sprite_render_system(*args, **kwargs) -> SpriteRenderSystem
|
||||
|
||||
Creates a new :class:`SpriteRenderSystem`, based on the set
|
||||
:attr:`sprite_type`. If :attr:`sprite_type` is ``TEXTURE``, a
|
||||
:class:`TextureSpriteRenderSystem` is created with the the
|
||||
``renderer`` from the :attr:`default_args`. Other keyword
|
||||
arguments are ignored in that case.
|
||||
|
||||
Otherwise a :class:`SoftwareSpriteRenderSystem` is created and *args*
|
||||
and *kwargs* are passed to it.
|
||||
|
||||
.. method:: create_texture_sprite(renderer : object, size, pformat=sdl2.SDL_PIXELFORMAT_RGBA8888, access=sdl2.SDL_TEXTUREACCESS_STATIC) -> TextureSprite
|
||||
|
||||
Creates a texture sprite. A *size* tuple containing the width and
|
||||
height of the sprite needs to be provided.
|
||||
|
||||
:class:`TextureSprite` objects are assumed to be static by
|
||||
default, making it impossible to access their pixel buffer in
|
||||
favour for faster copy operations. If you need to update the pixel
|
||||
data frequently or want to use the texture as target for rendering
|
||||
operations, *access* can be set to the relevant
|
||||
SDL_TEXTUREACCESS_* flag.
|
||||
|
||||
.. method:: from_color(color : object , size, bpp=32, masks=None) -> Sprite
|
||||
|
||||
Creates a :class:`Sprite` with a certain color.
|
||||
|
||||
.. method:: from_image(fname : str) -> Sprite
|
||||
|
||||
Creates a :class:`Sprite` from an image file. The image must be
|
||||
loadable via :func:`sdl2.ext.load_image()`.
|
||||
|
||||
.. method:: from_object(obj: object) -> Sprite
|
||||
|
||||
Creates a :class:`Sprite` from an object. The object will be
|
||||
passed through :func:`sdl2.rwops_from_object()` in
|
||||
order to try to load image data from it.
|
||||
|
||||
.. method:: from_surface(surface : SDL_Surface[, free=False]) -> Sprite
|
||||
|
||||
Creates a :class:`Sprite` from the passed
|
||||
:class:`sdl2.SDL_Surface`. If *free* is set to
|
||||
``True``, the passed *surface* will be freed automatically.
|
||||
|
||||
.. method:: from_text(text : str[, **kwargs]) -> Sprite
|
||||
|
||||
Creates a :class:`Sprite` from a string of text. This method
|
||||
requires a :class:`sdl2.ext.FontManager` to be in *kwargs* or
|
||||
:attr:`default_args`.
|
||||
|
||||
.. class:: Renderer(target : obj[, logical_size=None[, index=-1[, flags=sdl2.SDL_RENDERER_ACCELERATED]])
|
||||
|
||||
A rendering context for windows and sprites that can use hardware or
|
||||
software-accelerated graphics drivers.
|
||||
|
||||
If target is a :class:`sdl2.ext.Window` or :class:`sdl2.SDL_Window`,
|
||||
*index* and *flags* are passed to the relevant
|
||||
:class:`sdl2.SDL_CreateRenderer()` call. If *target* is a
|
||||
:class:`SoftwareSprite` or :class:`sdl2.SDL_Surface`, the *index*
|
||||
and *flags* arguments are ignored.
|
||||
|
||||
.. attribute:: sdlrenderer
|
||||
|
||||
The underlying :class:`sdl2.SDL_Renderer`.
|
||||
|
||||
.. attribute:: rendertarget
|
||||
|
||||
The target for which the :class:`Renderer` was created.
|
||||
|
||||
.. attribute:: logical_size
|
||||
|
||||
The logical size of the renderer.
|
||||
|
||||
Setting this allows you to draw as if your renderer had this size, even
|
||||
though the target may be larger or smaller. When drawing, the renderer will
|
||||
automatically scale your contents to the target, creating letter-boxing or
|
||||
sidebars if necessary.
|
||||
|
||||
To reset your logical size back to the target's, set it to ``(0, 0)``.
|
||||
|
||||
Setting this to a lower value may be useful for low-resolution effects.
|
||||
|
||||
Setting this to a larger value may be useful for antialiasing.
|
||||
|
||||
.. attribute:: color
|
||||
|
||||
The :class:`sdl2.ext.Color` to use for draw and fill operations.
|
||||
|
||||
.. attribute:: blendmode
|
||||
|
||||
The blend mode used for drawing operations (fill and line). This
|
||||
can be a value of
|
||||
|
||||
* ``SDL_BLENDMODE_NONE`` for no blending
|
||||
* ``SDL_BLENDMODE_BLEND`` for alpha blending
|
||||
* ``SDL_BLENDMODE_ADD`` for additive color blending
|
||||
* ``SDL_BLENDMODE_MOD`` for multiplied color blending
|
||||
|
||||
.. attribute:: scale
|
||||
|
||||
The horizontal and vertical drawing scale as two-value tuple.
|
||||
|
||||
.. method:: clear([color=None])
|
||||
|
||||
Clears the rendering context with the currently set or passed
|
||||
*color*.
|
||||
|
||||
.. method:: copy(src : obj[, srcrect=None[, dstrect=None[, angle=0[, center=None[, flip=render.SDL_FLIP_NONE]]]]]) -> None
|
||||
|
||||
Copies (blits) the passed *src*, which can be a :class:`TextureSprite` or
|
||||
:class:`sdl2.SDL_Texture`, to the target of the
|
||||
:class:`Renderer`. *srcrect* is the source rectangle to be used for
|
||||
clipping portions of *src*. *dstrect* is the destination rectangle.
|
||||
*angle* will cause the texture to be rotated around *center* by the given
|
||||
degrees. *flip* can be one of the SDL_FLIP_* constants and will flip the
|
||||
texture over its horizontal or vertical middle axis. If *src* is a
|
||||
:class:`TextureSprite`, *angle*, *center* and *flip* will be set from
|
||||
*src*'s attributes, if not provided.
|
||||
|
||||
.. method:: draw_line(points : iterable[, color=None]) -> None
|
||||
|
||||
Draws one or multiple lines on the rendering context. If *line* consists
|
||||
of four values ``(x1, y1, x2, y2)`` only, a single line is drawn. If
|
||||
*line* contains more than four values, a series of connected lines is
|
||||
drawn.
|
||||
|
||||
.. method:: draw_point(points : iterable[, color=None]) -> None
|
||||
|
||||
Draws one or multiple points on the rendering context. The *points*
|
||||
argument contains the x and y values of the points as simple sequence in
|
||||
the form ``(point1_x, point1_y, point2_x, point2_y, ...)``.
|
||||
|
||||
.. method:: draw_rect(rects : iterable[, color=None]) -> None
|
||||
|
||||
Draws one or multiple rectangles on the rendering context. *rects*
|
||||
contains sequences of four values denoting the x and y offset and width
|
||||
and height of each individual rectangle in the form ``((x1, y1, w1, h1),
|
||||
(x2, y2, w2, h2), ...)``.
|
||||
|
||||
.. method:: fill(rects : iterable[, color=None]) -> None
|
||||
|
||||
Fills one or multiple rectangular areas on the rendering context with
|
||||
the current set or passed *color*. *rects* contains sequences of four
|
||||
values denoting the x and y offset and width and height of each
|
||||
individual rectangle in the form ``((x1, y1, w1, h1), (x2, y2, w2, h2),
|
||||
...)``.
|
||||
|
||||
.. method:: present() -> None
|
||||
|
||||
Refreshes the rendering context, causing changes to the render buffers
|
||||
to be shown.
|
|
@ -0,0 +1,14 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
Software Surface manipulation
|
||||
=============================
|
||||
|
||||
.. function:: subsurface(surface : SDL_Surface, area : (int, int, int, int)) -> SDL_Surface
|
||||
|
||||
Creates a surface from a part of another surface. The two surfaces share
|
||||
pixel data.
|
||||
|
||||
.. note::
|
||||
|
||||
The newly created surface *must not* be used after its parent has been
|
||||
freed!
|
|
@ -0,0 +1,71 @@
|
|||
.. currentmodule:: sdl2.ext
|
||||
|
||||
Window routines to manage on-screen windows
|
||||
===========================================
|
||||
|
||||
.. class:: Window(title : string, size : iterable[, position=None[, flags=None]])
|
||||
|
||||
The Window class represents a visible on-screen object with an optional
|
||||
border and *title* text. It represents an area on the screen that can be
|
||||
accessed by the application for displaying graphics and receive and
|
||||
process user input.
|
||||
|
||||
The position to show the Window at is undefined by default, letting
|
||||
the operating system or window manager pick the best location. The
|
||||
behaviour can be adjusted through the ``DEFAULTPOS`` class variable. ::
|
||||
|
||||
Window.DEFAULTPOS = (10, 10)
|
||||
|
||||
The created Window is hidden by default, which can be overridden at
|
||||
the time of creation by providing other SDL window flags through the
|
||||
*flags* parameter. The default flags for creating Window instances
|
||||
can be adjusted through the ``DEFAULTFLAGS`` class variable. ::
|
||||
|
||||
Window.DEFAULTFLAGS = sdl2.SDL_WINDOW_SHOWN
|
||||
|
||||
.. attribute:: window
|
||||
|
||||
The used :class:`sdl2.SDL_Window`.
|
||||
|
||||
.. attribute:: title
|
||||
|
||||
The title of the :class:`Window`.
|
||||
|
||||
.. attribute:: size
|
||||
|
||||
The size of the :class:`Window`.
|
||||
|
||||
.. method:: show() -> None
|
||||
|
||||
Show the :class:`Window` on the display.
|
||||
|
||||
.. method:: hide() -> None
|
||||
|
||||
Hide the :class:`Window`.
|
||||
|
||||
.. method:: maximize() -> None
|
||||
|
||||
Maximizes the :class:`Window` to the display's dimensions.
|
||||
|
||||
.. method:: minimize() -> None
|
||||
|
||||
Minimizes the :class:`Window` to an iconified state in the system tray.
|
||||
|
||||
.. method:: refresh() -> None
|
||||
|
||||
Refreshes the entire :class:`Window` surface.
|
||||
|
||||
.. note::
|
||||
|
||||
This only needs to be called, if a SDL_Surface was acquired via
|
||||
:meth:`get_surface()` and is used to display contents.
|
||||
|
||||
.. method:: get_surface() -> SDL_Surface
|
||||
|
||||
Gets the :class:`sdl2.SDL_Surface` used by the :class:`Window` to
|
||||
display 2D pixel data.
|
||||
|
||||
.. note::
|
||||
|
||||
Using this method will make the usage of GL operations, such as
|
||||
texture handling or the usage of SDL renderers impossible.
|
|
@ -0,0 +1,277 @@
|
|||
Release News
|
||||
============
|
||||
This describes the latest changes between the PySDL2 releases.
|
||||
|
||||
0.9.5
|
||||
-----
|
||||
Released on 2016-10-20.
|
||||
|
||||
* updated :mod:`sdl2` to include the latest changes of SDL2 (release 2.0.5)
|
||||
* fixed issue #94: added support for TrueType font collection (TTC) files
|
||||
* fixed issue #80: added flip and rotation support for TextureSprite objects
|
||||
* renamed :attr:`sdl2.ext.Renderer.renderer` attribute to
|
||||
:attr:`sdl2.ext.Renderer.sdlrenderer`. The `renderer` attribute is
|
||||
deprecated and will be removed in a later version.
|
||||
|
||||
0.9.4
|
||||
-----
|
||||
Released on 2016-07-07.
|
||||
|
||||
* updated :mod:`sdl2` to include the latest changes of SDL2 (release 2.0.4)
|
||||
* updated :mod:`sdl2.sdlttf` to include the latest changes of SDL_ttf (release 2.0.14)
|
||||
* new :attr:`sdl2.ext.Renderer.logical_size` attribute to set or retrieve the logical
|
||||
pixel size of a renderer
|
||||
* fixed issue #48: be more noisy about DLL loading issues
|
||||
* fixed issue #65: misleading documentation for :meth:`sdl2.ext.Renderer.draw_line()`
|
||||
* fixed issue #67: Return a proper error code, when unittests running as subprocesses fail
|
||||
* fixed issue #72: :func:`sdl2.video.SDL_GL_DrawableSize()` not available on import
|
||||
* fixed issue #76: define missing SDL_PRESSED and SDL_RELEASED constants
|
||||
* fixed issue #82: examples/gui.py fails due to an attribute error
|
||||
* fixed issue #83: fix compatibility with newer PIL versions in
|
||||
:func:`sdl2.ext.image.load_image()`
|
||||
* fixed issue #84: The setter of :attr:`sdl2.ext.Renderer.scale` works properly now
|
||||
* fixed issue #85: fix environment-dependent unit tests
|
||||
* fixed issue #87: fix incorrect MIX_INIT_* constants in :mod:`sdl2.sdlmixer`
|
||||
* fixed issue #88: use PILs `Image.tobyte()instead of the deprecated `Image.tostring()`
|
||||
* fixed horizontical and vertical line drawing in :func:`sdl2.ext.line()`
|
||||
* fixed a bug in :meth:`sdl2.ext.Renderer.draw_line()` for odd numbers of points
|
||||
* dropped IronPython support
|
||||
|
||||
0.9.3
|
||||
-----
|
||||
Released on 2014-07-08.
|
||||
|
||||
* updated :mod:`sdl2` to include the latest changes of SDL2 (HG)
|
||||
* new :attr:`sdl2.ext.Renderer.scale` attribute, which denotes the horizontal
|
||||
and vertical drawing scale
|
||||
* new :func:`sdl2.ext.point_on_line()` function to test, if a point lies on a
|
||||
line segment
|
||||
* PYSDL2_DLL_PATH can contain multiple paths separated by :attr:`os.pathsep`
|
||||
to search for the libraries now
|
||||
* :func:`sdl2.ext.get_image_formats()` only returns BMP image support now, if
|
||||
SDL2_image and PIL are not found
|
||||
* :func:`sdl2.ext.load_image()` tries to use :func:`sdl2.SDL_LoadBMP()` now,
|
||||
if SDL2_image and PIL are not found
|
||||
* fixed issue #55: :meth:`sdl2.SDL_GameControllerAddMappingsFromFile()` does
|
||||
not raise a TypeError for Python 3.x anymore
|
||||
* fixed issue #56: :meth:`sdl2.ext.Renderer.draw_line()` and
|
||||
:func:`sdl2.ext.Renderer.draw_point()` handle multiple lines (or points) as
|
||||
arguments properly now
|
||||
* fixed issue #57: if SDL2_image is not installed and PIL is used, the loaded
|
||||
pixel buffer of the image file is not referenced anymore after returning
|
||||
from :func:`sdl2.ext.load_image()`, causing random segmentation faults
|
||||
* fixed issue #58: raise a proper error,
|
||||
if :meth:`sdl2.ext.FontManager.render()` could not render a text surface
|
||||
* fixed issue #59: The :attr:`sdl2.ext.TextureSpriteRenderSystem.sdlrenderer`
|
||||
attribute is correctly documented now
|
||||
* fixed a local variable and module name collision in
|
||||
:meth:`sdl2.ext.FontManager.render()`
|
||||
|
||||
Thanks to Filip M. Nowak for the PYSDL2_DLL_PATH improvement.
|
||||
|
||||
0.9.2
|
||||
-----
|
||||
Released on 2014-04-13.
|
||||
|
||||
* fixed issue #32: the line clipping algorithms do not run into precision
|
||||
errors anymore
|
||||
* fixed issue #53 (again): :func:`sdl2.video.SDL_GL_ResetAttributes()`
|
||||
is properly wrapped now to retain backwards compatibility with previous
|
||||
SDL2 releases
|
||||
* fixed issue #54: text input is correctly converted for the text entry
|
||||
component
|
||||
* updated the example BMP files, which could not be loaded properly on
|
||||
some systems with SDL2_image and PIL
|
||||
|
||||
0.9.1
|
||||
-----
|
||||
Released on 2014-04-05.
|
||||
|
||||
* fixed issue #50: corrected the :func:`sdl2.ext.load_image()`
|
||||
documentation
|
||||
* fixed issue #52: :meth:`sdl2.ext.Renderer.fill()`,
|
||||
:meth:`sdl2.ext.Renderer.draw_rect()` and
|
||||
:meth:`sdl2.ext.Renderer.draw_point()` convert sequences
|
||||
correctly now
|
||||
* fixed issue #53: provide backwards compatibility for previous
|
||||
SDL2 releases by adding a wrapper func for
|
||||
:func:`sdl2.cpuinfo.SDL_HasAVX()`
|
||||
|
||||
0.9.0
|
||||
-----
|
||||
Released on 2014-03-23.
|
||||
|
||||
**IMPORTANT: This release breaks backwards-compatibility. See the notes
|
||||
for the issues #36 and #39.**
|
||||
|
||||
* updated :mod:`sdl2` to include the latest changes of SDL2 (release 2.0.3)
|
||||
* new :func:`sdl2.ext.subsurface()` function to create subsurfaces from
|
||||
:class:`sdl2.SDL_Surface` objects
|
||||
* new :func:`sdl2.ext.SoftwareSprite.subsprite()` method to create
|
||||
:class:`sdl2.ext.SoftwarSprite` objects sharing pixel data
|
||||
* the unit test runner features a `--logfile` argument now to
|
||||
safe the unit test output to a file
|
||||
* issues #36, #39: the different render classes of sdl2.ext.sprite were renamed
|
||||
|
||||
* the ``sdl2.ext.RenderContext`` class was renamed to
|
||||
:class:`sdl2.ext.Renderer` to be consistent with with SDL2's naming scheme
|
||||
* ``sdl2.ext.SpriteRenderer`` was renamed to
|
||||
:class:`sdl2.ext.SpriteRenderSystem`
|
||||
* ``sdl2.ext.SoftwareSpriteRenderer`` was renamed to
|
||||
:class:`sdl2.ext.SoftwareSpriteRenderSystem`
|
||||
* ``sdl2.ext.TextureSpriteRenderer`` was renamed to
|
||||
:class:`sdl2.ext.TextureSpriteRenderSystem`
|
||||
* ``sdl2.ext.SpriteFactory.create_sprite_renderer()`` was renamed to
|
||||
:meth:`sdl2.ext.SpriteFactory.create_sprite_render_system()`
|
||||
|
||||
* fixed :func:`sdl2.audio.SDL_LoadWAV()` macro to provide the correct arguments
|
||||
* fixed issue #44: use a slightly less confusing ``ValueError``, if a renderer
|
||||
argument for the :class:`sdl2.ext.SpriteFactory` is not provided
|
||||
* fixed issue #43: improved the code reference for the improved bouncing
|
||||
section in the docs
|
||||
* fixed issue #40: typo in a ``RuntimeWarning`` message on loading the SDL2
|
||||
libraries
|
||||
* fixed issue #38: the points arguments of
|
||||
:meth:`sdl2.ext.Renderer.draw_points()` are properly documented now
|
||||
* fixed issue #37: :func:`sdl2.SDL_GetRendererOutputSize()` is now acccessible
|
||||
via a wildcard import
|
||||
* fixed issue #35: download location is now mentioned in the docs
|
||||
* fixed issue #12: remove confusing try/except on import in the examples
|
||||
|
||||
|
||||
0.8.0
|
||||
-----
|
||||
Released on 2013-12-30.
|
||||
|
||||
* updated PD information to include the CC0 dedication, since giving
|
||||
software away is not enough anymore
|
||||
* updated :mod:`sdl2` to include the latest changes of SDL2 (HG)
|
||||
* fixed a wrong C mapping of :func:`sdl2.rwops.SDL_FreeRW()`
|
||||
* fixed various issues within the :class:`sdl2.ext.BitmapFont` class
|
||||
* issue #26: :attr:`sdl2.SDL_AudioSpec.callback` is a :func:`SDL_AudioCallBack`
|
||||
now
|
||||
* issue #30: the SDL_Add/DelHintCallback() unittest works with PyPy now
|
||||
* issue #31: :func:`sdl2.sdlmixer.SDL_MIXER_VERSION()` returns the proper
|
||||
version now
|
||||
|
||||
Thanks to Sven Eckelmann, Marcel Rodrigues, Michael McCandless,
|
||||
Andreas Schiefer and Franz Schrober for providing fixes and
|
||||
improvements.
|
||||
|
||||
0.7.0
|
||||
-----
|
||||
Released on 2013-10-27.
|
||||
|
||||
* updated :mod:`sdl2` to include the latest changes of SDL2 (release 2.0.1)
|
||||
* fixed a bug in :meth:`sdl2.ext.FontManager.render()`, which did not apply
|
||||
the text color correctly
|
||||
* issue #14: improved the error messages on failing DLL imports
|
||||
* issue #19: the :meth:`sdl2.ext.TextureSpriteRenderer.render()` and
|
||||
:meth:`sdl2.ext.SoftwareSpriteRenderer.render()` methods do not
|
||||
misinterpret x and y arguments anymore, if set to 0
|
||||
* issue #21: :func:`sdl2.ext.load_image()` raises a proper
|
||||
:exc:`UnsupportedError`, if neither SDL_image nor PIL are usable
|
||||
|
||||
Thanks to Marcel Rodrigues, Roger Flores and otus for providing fixes
|
||||
and improvement ideas.
|
||||
|
||||
0.6.0
|
||||
-----
|
||||
Released on 2013-09-01.
|
||||
|
||||
* new :attr:`sdl2.ext.FontManager.size` attribute, which gives a default size
|
||||
to be used for adding fonts or rendering text
|
||||
* updated :mod:`sdl2` to include the latest changes of SDL2
|
||||
* :meth:`sdl2.ext.RenderContext.copy()` accepts any 4-value sequence as source
|
||||
or destination rectangle now
|
||||
* issue #11: throw an :exc:`ImportError` instead of a
|
||||
:exc:`RuntimeError`, if a third-party DLL could not be imported
|
||||
properly
|
||||
* fixed a bug in the installation code, which caused :mod:`sdl2.examples` not
|
||||
to install the required resources
|
||||
|
||||
Thanks to Steven Johnson for his enhancements to the FontManager class.
|
||||
Thanks to Marcel Rodrigues for the improvements to RenderContext.copy().
|
||||
|
||||
0.5.0
|
||||
-----
|
||||
Released on 2013-08-14.
|
||||
|
||||
* new :class:`sdl2.ext.FontManager` class, which provides simple TTF font
|
||||
rendering.
|
||||
* new :meth:`sdl2.ext.SpriteFactory.from_text()` method, which creates
|
||||
text sprites
|
||||
* put the SDL2 dll path at the beginning of PATH, if a PYSDL2_DLL_PATH
|
||||
is provided to avoid loading issues for third party DLLs on Win32
|
||||
platforms
|
||||
* minor documentation fixes
|
||||
|
||||
Thanks to Dan Gillett for providing the FontManager and from_text()
|
||||
enhancements and his patience regarding all the small change requests.
|
||||
Thanks to Mihail Latyshov for providing fixes to the documentation.
|
||||
|
||||
|
||||
0.4.1
|
||||
-----
|
||||
Released on 2013-07-26.
|
||||
|
||||
* updated :mod:`sdl2` to include the latest changes of SDL2
|
||||
* improved DLL detection for DLLs not being in a library path
|
||||
* fixed a bug in :meth:`sdl2.ext.RenderContext.draw_rect()` for drawing
|
||||
a single rect
|
||||
* fixed a bug in the :func:`repr` call for :class:`sdl2.ext.SoftwareSprite`
|
||||
* issue #4: fixed a bug in :meth:`sdl2.ext.RenderContext.fill()` for filling
|
||||
a single rect
|
||||
* issue #5: fixed pip installation support
|
||||
* issue #6: fixed a bug in :func:`sdl2.ext.get_events()`, which did not handle
|
||||
more than 10 events in the queue correctly
|
||||
* issue #8: :meth:`sdl2.ext.SpriteFactory.create_texture_sprite` can
|
||||
create sprites to be used as rendering targets now
|
||||
* issue #9: improved error messages on trying to bind non-existent library
|
||||
functions via ctypes
|
||||
* minor documentation fixes
|
||||
|
||||
Thanks to Steven Johnson, Todd Rovito, Bil Bas and Dan McCombs for
|
||||
providing fixes and improvements.
|
||||
|
||||
0.4.0
|
||||
-----
|
||||
Released on 2013-06-08.
|
||||
|
||||
* new :mod:`sdl2.sdlmixer` module, which provides access to the
|
||||
SDL2_mixer library
|
||||
* issue #1: fixed libc loading for cases where libc.so is a ld script
|
||||
* updated :mod:`sdl2` and :mod:`sdl2.sdlimage` to include the latest
|
||||
changes of the libraries, they wrap
|
||||
|
||||
0.3.0
|
||||
-----
|
||||
Released on 2013-05-07.
|
||||
|
||||
* new :mod:`sdl2.sdlgfx` module, which provides access to the SDL2_gfx library
|
||||
* new :mod:`sdl2.ext.UIFactory.from_color` method; it creates UI-supportive
|
||||
sprites from a color
|
||||
* fixed color argument bugs in :class:`sdl2.ext.RenderContext` methods
|
||||
* fixed a module namespace issues in :mod:`sdl2.ext.pixelaccess`
|
||||
* :mod:`sdl2.ext.SpriteFactory` methods do not use a default ``size`` argument
|
||||
anymore; it has to provided by the caller
|
||||
|
||||
0.2.0
|
||||
-----
|
||||
Released on 2013-05-03.
|
||||
|
||||
* removed sdl2.ext.scene; it now lives in python-utils
|
||||
* fixed :mod:`sdl2.haptic` module usage for Python 3
|
||||
* fixed :func:`sdl2.SDL_WindowGetData` and :func:`sdl2.SDL_WindowSetData`
|
||||
wrappers
|
||||
* fixed :meth:`sdl2.ext.RenderContext.copy`
|
||||
* fixed :mod:`sdl2.ext.font` module usage for Python 3
|
||||
* fixed :func:`sdl2.ext.line`
|
||||
* :mod:`sdl2` imports all submodules now
|
||||
* improved documentation
|
||||
|
||||
0.1.0
|
||||
-----
|
||||
Released on 2013-04-23.
|
||||
|
||||
* Initial Release
|
|
@ -0,0 +1,11 @@
|
|||
Todo list for PySDL2
|
||||
====================
|
||||
|
||||
General
|
||||
-------
|
||||
* more unit tests
|
||||
|
||||
Windows
|
||||
-------
|
||||
* Add support for SDL_SetWindowsMessageHook()
|
||||
* Add SDL_TOUCH_MOUSEID constant
|
|
@ -0,0 +1,128 @@
|
|||
.. _hello_world:
|
||||
|
||||
Hello World
|
||||
===========
|
||||
Ahhh, the great tradition of saying "Hello World" in a programming
|
||||
language. To whet your appetite, we will do this with a most simple
|
||||
application, which will display an image. It is not important to understand
|
||||
everything at once, which will be used by the example. Nearly all parts used
|
||||
now are explained in later chapters, so do not hesitate, if the one or other
|
||||
explanation is missing.
|
||||
|
||||
Importing
|
||||
---------
|
||||
Let's start with importing some basic modules, which are necessary to
|
||||
display a small nice window and to do some basic drawing within that
|
||||
window. ::
|
||||
|
||||
import sys
|
||||
import sdl2.ext
|
||||
|
||||
RESOURCES = sdl2.ext.Resources(__file__, "resources")
|
||||
|
||||
We need some resources from the ``resources`` folder, so that we have a test
|
||||
image around to display on the window later on. In your own applications, it is
|
||||
unlikely that you will ever need to import them, but we need them here, so we
|
||||
use the :mod:`sdl2.ext.Resources` class to have them available.
|
||||
|
||||
Window creation and image loading
|
||||
---------------------------------
|
||||
Any graphical application requires access to the screen, mostly in form
|
||||
of a window, which basically represents a portion of the screen, the
|
||||
application has access to and the application can manipulate. In most cases
|
||||
that portion has a border and title bar around it, allowing the user to move
|
||||
it around on the screen and reorganise everything in a way to fit his needs.
|
||||
|
||||
Once we have imported all necessary parts, let's create a window to have
|
||||
access to the screen, so we can display the logo and thus represent it
|
||||
to the user. ::
|
||||
|
||||
sdl2.ext.init()
|
||||
|
||||
window = sdl2.ext.Window("Hello World!", size=(640, 480))
|
||||
window.show()
|
||||
|
||||
factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
|
||||
sprite = factory.from_image(RESOURCES.get_path("hello.bmp"))
|
||||
|
||||
spriterenderer = factory.create_sprite_render_system(window)
|
||||
spriterenderer.render(sprite)
|
||||
|
||||
First, we initialise the :mod:`sdl2.ext` internals to gain access to the
|
||||
screen and to be able to create windows on top of it. Once done with that,
|
||||
:class:`sdl2.ext.Window` will create the window for us and we
|
||||
supply a title to be shown on the window's border along with its initial size.
|
||||
Since :class:`sdl2.ext.Window` instances are not shown by default,
|
||||
we have to tell the operating system and window manager that there is a new
|
||||
window to display by calling :meth:`sdl2.ext.Window.show()`.
|
||||
|
||||
Afterwards, we get an image from the resources folder and create a
|
||||
:class:`sdl2.ext.Sprite` from it, which can be easily shown later
|
||||
on. This is done via a :class:`sdl2.ext.SpriteFactory`, since the
|
||||
factory allows us to switch between texture-based, hardware-accelerated, and
|
||||
software-based sprites easily.
|
||||
|
||||
To display the image, we will use a :class:`sdl2.ext.SpriteRenderSystem`,
|
||||
which supports the sprite type (texture- or software-based) and can copy the
|
||||
image to the window for display. The :class:`sdl2.ext.SpriteRenderSystem`
|
||||
needs to know, where to copy to, thus we have to supply the window as target
|
||||
for copy and display operations.
|
||||
|
||||
All left to do is to initiate the copy process by calling
|
||||
:class:`sdl2.ext.SpriteRenderSystem.render()` with the image we
|
||||
created earlier.
|
||||
|
||||
.. tip::
|
||||
|
||||
You will notice that the sprite used above will always be drawn at the
|
||||
top-left corner of the :class:`sdl2.ext.Window`. You can change
|
||||
the position of where to draw it by changing its
|
||||
:attr:`sdl2.ext.Sprite.position` value. ::
|
||||
|
||||
# will cause the renderer to draw the sprite 10px to the right and
|
||||
# 20 px to the bottom
|
||||
sprite.position = 10, 20
|
||||
|
||||
# will cause the renderer to draw the sprite 55px to the right and
|
||||
# 10 px to the bottom
|
||||
sprite.position = 55, 10
|
||||
|
||||
Experiment with different values to see their effect. Do not forget to do
|
||||
this *before* ``spriterenderer.render(sprite)`` is called.
|
||||
|
||||
Making the application responsive
|
||||
---------------------------------
|
||||
We are nearly done now. We have an image to display, we have a window, where
|
||||
the image should be displayed on, so we can execute the written code, not?
|
||||
|
||||
Well, yes, but the only thing that will happen is that we will notice a
|
||||
short flickering before the application exits. Maybe we can even see
|
||||
the window with the image for a short moment, but that's not what we
|
||||
want, do we?
|
||||
|
||||
To keep the window on the screen and to make it responsive to user
|
||||
input, such as closing the window, react upon the mouse cursor or key
|
||||
presses, we have to add a so-called event loop. The event loop will deal
|
||||
with certain types of actions happening on the window or while the
|
||||
window is focused by the user and - as long as the event loop is
|
||||
running - will keep the window shown on the screen. ::
|
||||
|
||||
processor = sdl2.ext.TestEventProcessor()
|
||||
processor.run(window)
|
||||
|
||||
Since this is a very first tutorial, we keep things simple here and use a
|
||||
dummy class for testing without actually dealing with the event loop magic.
|
||||
By calling :meth:`sdl2.ext.TestEventProcessor.run()`, we implicitly start an
|
||||
event loop, which takes care of the most important parts for us.
|
||||
|
||||
And here it ends...
|
||||
-------------------
|
||||
The window is shown, the image is shown, great! All left to do is to clean up
|
||||
everything, once the application finishes. Luckily the
|
||||
:class:`sdl2.ext.TestEventProcessor` knows when the window is closed, so
|
||||
it will exit from the event loop. Once it exits, we should clean up the
|
||||
video internals, we initialised at the beginning. Thus, a final call to ::
|
||||
|
||||
sdl2.ext.quit()
|
||||
|
||||
should be made.
|
|
@ -0,0 +1,17 @@
|
|||
Learn to fly - the tutorials
|
||||
============================
|
||||
PySDL2 is easy to learn and a powerful multimedia programming framework. It
|
||||
features efficient high- and low-level structures and an excellent
|
||||
object-oriented programming layout.
|
||||
|
||||
The following tutorials will guide you through your first applications
|
||||
written with PySDL2 and introduces certain parts of the PySDL2 packages to
|
||||
you. They will most likely *not* cover each single part of PySDL2, but
|
||||
instead show you the most noteworthy features.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
helloworld.rst
|
||||
pong.rst
|
||||
pygamers.rst
|
|
@ -0,0 +1,590 @@
|
|||
.. _pong-tutorial:
|
||||
|
||||
The Pong Game
|
||||
=============
|
||||
The following tutorial will show you some capabilities of the component-based
|
||||
approach, PySDL2 features. We will create the basics of a simple Pong game
|
||||
implementation here. The basics of creating a event loop, dealing with
|
||||
user input, moving images around and creating a rendering function are
|
||||
covered in this tutorial.
|
||||
|
||||
Getting started
|
||||
---------------
|
||||
We start with creating the window and add a small event loop, so we are able
|
||||
to close the window and exit the game. ::
|
||||
|
||||
import sys
|
||||
import sdl2
|
||||
import sdl2.ext
|
||||
|
||||
|
||||
def run():
|
||||
sdl2.ext.init()
|
||||
window = sdl2.ext.Window("The Pong Game", size=(800, 600))
|
||||
window.show()
|
||||
running = True
|
||||
while running:
|
||||
events = sdl2.ext.get_events()
|
||||
for event in events:
|
||||
if event.type == sdl2.SDL_QUIT:
|
||||
running = False
|
||||
break
|
||||
window.refresh()
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run())
|
||||
|
||||
The import statements, video initialisation and window creation were
|
||||
discussed previously in the :ref:`hello_world` tutorial. We import everything
|
||||
from the :mod:`sdl2` package here, too, to have all SDL2 functions available.
|
||||
|
||||
Instead of some integrated event processor, a new code fragment is
|
||||
introduced, though. ::
|
||||
|
||||
running = True
|
||||
while running:
|
||||
events = sdl2.ext.get_events()
|
||||
for event in events:
|
||||
if event.type == sdl2.SDL_QUIT:
|
||||
running = False
|
||||
break
|
||||
window.refresh()
|
||||
|
||||
The while loop above is the main event loop of our application. It deals with
|
||||
all kinds of input events that can occur when working with the window, such as
|
||||
mouse movements, key strokes, resizing operations and so on. SDL handles a lot
|
||||
for us when it comes to events, so all we need to do is to check, if there are
|
||||
any events, retrieve each event one by one, and handle it, if necessary. For
|
||||
now, we will just handle the ``sdl2.SDL_QUIT`` event, which is raised when the
|
||||
window is about to be closed.
|
||||
|
||||
In any other case we will just refresh the window's graphics buffer, so
|
||||
it is updated and visible on-screen.
|
||||
|
||||
Adding the game world
|
||||
---------------------
|
||||
The window is available and working. Now let's take care of creating the
|
||||
game world, which will manage the player paddles, ball, visible elements
|
||||
and everything else. We are going to use an implementation layout loosely
|
||||
based on a COP [#f1]_ pattern, which separates data structures and
|
||||
functionality from each other. This allows us to change or enhance functional
|
||||
parts easily without having to refactor all classes we are implementing.
|
||||
|
||||
We start with creating the two player paddles and the rendering engine
|
||||
that will display them. ::
|
||||
|
||||
[...]
|
||||
|
||||
WHITE = sdl2.ext.Color(255, 255, 255)
|
||||
|
||||
class SoftwareRenderer(sdl2.ext.SoftwareSpriteRenderSystem):
|
||||
def __init__(self, window):
|
||||
super(SoftwareRenderer, self).__init__(window)
|
||||
|
||||
def render(self, components):
|
||||
sdl2.ext.fill(self.surface, sdl2.ext.Color(0, 0, 0))
|
||||
super(SoftwareRenderer, self).render(components)
|
||||
|
||||
|
||||
class Player(sdl2.ext.Entity):
|
||||
def __init__(self, world, sprite, posx=0, posy=0):
|
||||
self.sprite = sprite
|
||||
self.sprite.position = posx, posy
|
||||
|
||||
|
||||
def run():
|
||||
...
|
||||
|
||||
world = sdl2.ext.World()
|
||||
|
||||
spriterenderer = SoftwareRenderer(window)
|
||||
world.add_system(spriterenderer)
|
||||
|
||||
factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
|
||||
sp_paddle1 = factory.from_color(WHITE, size=(20, 100))
|
||||
sp_paddle2 = factory.from_color(WHITE, size=(20, 100))
|
||||
|
||||
player1 = Player(world, sp_paddle1, 0, 250)
|
||||
player2 = Player(world, sp_paddle2, 780, 250)
|
||||
|
||||
running = True
|
||||
while running:
|
||||
events = sdl2.ext.get_events()
|
||||
for event in events:
|
||||
if event.type == sdl2.SDL_QUIT:
|
||||
running = False
|
||||
break
|
||||
world.process()
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run())
|
||||
|
||||
The first thing to do is to enhance the
|
||||
:class:`sdl2.ext.SoftwareSpriteRenderSystem` so that it will paint
|
||||
the whole window screen black on every drawing cycle, before drawing all
|
||||
sprites on the window.
|
||||
|
||||
Afterwards, the player paddles will be implemented, based on an
|
||||
:class:`sdl2.ext.Entity` data container. The player paddles are
|
||||
simple rectangular sprites that can be positioned anywhere on the
|
||||
window.
|
||||
|
||||
In the main program function, we put those things together by creating a
|
||||
:class:`sdl2.ext.World`, in which the player paddles and the renderer
|
||||
can live and operate.
|
||||
|
||||
Within the main event loop, we allow the world to process all attached
|
||||
systems, which causes it to invoke the ``process()`` methods for all
|
||||
:class:`sdl2.ext.System` instances added to it.
|
||||
|
||||
Moving the ball
|
||||
---------------
|
||||
We have two static paddles centred vertically on the left and right of
|
||||
our window. The next thing to do is to add a ball that can move around
|
||||
within the window boundaries. ::
|
||||
|
||||
[...]
|
||||
class MovementSystem(sdl2.ext.Applicator):
|
||||
def __init__(self, minx, miny, maxx, maxy):
|
||||
super(MovementSystem, self).__init__()
|
||||
self.componenttypes = Velocity, sdl2.ext.Sprite
|
||||
self.minx = minx
|
||||
self.miny = miny
|
||||
self.maxx = maxx
|
||||
self.maxy = maxy
|
||||
|
||||
def process(self, world, componentsets):
|
||||
for velocity, sprite in componentsets:
|
||||
swidth, sheight = sprite.size
|
||||
sprite.x += velocity.vx
|
||||
sprite.y += velocity.vy
|
||||
|
||||
sprite.x = max(self.minx, sprite.x)
|
||||
sprite.y = max(self.miny, sprite.y)
|
||||
|
||||
pmaxx = sprite.x + swidth
|
||||
pmaxy = sprite.y + sheight
|
||||
if pmaxx > self.maxx:
|
||||
sprite.x = self.maxx - swidth
|
||||
if pmaxy > self.maxy:
|
||||
sprite.y = self.maxy - sheight
|
||||
|
||||
|
||||
class Velocity(object):
|
||||
def __init__(self):
|
||||
super(Velocity, self).__init__()
|
||||
self.vx = 0
|
||||
self.vy = 0
|
||||
|
||||
|
||||
class Player(sdl2.ext.Entity):
|
||||
def __init__(self, world, posx=0, posy=0):
|
||||
[...]
|
||||
self.velocity = Velocity()
|
||||
|
||||
|
||||
class Ball(sdl2.ext.Entity):
|
||||
def __init__(self, world, sprite, posx=0, posy=0):
|
||||
self.sprite = sprite
|
||||
self.sprite.position = posx, posy
|
||||
self.velocity = Velocity()
|
||||
|
||||
|
||||
def run():
|
||||
[...]
|
||||
sp_ball = factory.from_color(WHITE, size=(20, 20))
|
||||
[...]
|
||||
movement = MovementSystem(0, 0, 800, 600)
|
||||
spriterenderer = SoftwareRenderer(window)
|
||||
|
||||
world.add_system(movement)
|
||||
world.add_system(spriterenderer)
|
||||
|
||||
[...]
|
||||
|
||||
ball = Ball(world, sp_ball, 390, 290)
|
||||
ball.velocity.vx = -3
|
||||
|
||||
[...]
|
||||
|
||||
Two new classes are introduced here, ``Velocity`` and
|
||||
``MovementSystem``. The ``Velocity`` class is a simple data bag. It
|
||||
does not contain any application logic, but consists of the relevant
|
||||
information to represent the movement in a certain direction. This
|
||||
allows us to mark in-game items as being able to move around.
|
||||
|
||||
The ``MovementSystem`` in turn takes care of moving the in-game items around
|
||||
by applying the velocity to their current position. Thus, we can simply enable
|
||||
any ``Player`` instance to be movable or not by adding or removing a
|
||||
velocity attribute to them, which is a ``Velocity`` component instance.
|
||||
|
||||
.. note::
|
||||
|
||||
The naming is important here. The EBS implementation as described in
|
||||
:ref:`ref-ebs` requires every in-application or in-game item attribute
|
||||
bound to a :class:`sdl2.ext.Entity` to be the lowercase class name of its
|
||||
related component. ::
|
||||
|
||||
Player.vel = Velocity(10, 10)
|
||||
|
||||
for example would raise an exception, since the system expects
|
||||
``Player.vel`` to be an instance of a ``Vel`` component.
|
||||
|
||||
The ``MovementSystem`` is a specialised :class:`sdl2.ext.System`, a
|
||||
:class:`sdl2.ext.Applicator`, which can operate on combined sets of
|
||||
data. When the :meth:`sdl2.ext.Applicator.process()` method is
|
||||
called, the passed ``componentsets`` iterable will contain tuples of
|
||||
objects that belong to an instance and feature a certain type. The
|
||||
``MovementSystem``'s ``process()`` implementation hence will loop over
|
||||
sets of ``Velocity`` and ``Sprite`` instances that belong to the same
|
||||
:class:`sdl2.ext.Entity`. Since we have a ball and two players
|
||||
currently available, it typically would loop over three tuples, two for
|
||||
the individual players and one for the ball.
|
||||
|
||||
The :class:`sdl2.ext.Applicator` thus enables us to process combined
|
||||
data of our in-game items, without creating complex data structures.
|
||||
|
||||
.. note::
|
||||
|
||||
Only entities that contain *all* attributes (components) are taken
|
||||
into account. If e.g. the ``Ball`` class would not contain a
|
||||
``Velocity`` component, it would not be processed by the
|
||||
``MovementSystem``.
|
||||
|
||||
Why do we use this approach? The :class:`sdl2.ext.Sprite` objects carry a
|
||||
position, which defines the location at which they should be rendered, when
|
||||
processed by the ``SoftwareRenderer``. If they should move around (which is
|
||||
a change in the position), we need to apply the velocity to them.
|
||||
|
||||
We also define some more things within the ``MovementSystem``, such as a
|
||||
simple boundary check, so that the players and ball cannot leave the
|
||||
visible window area on moving around.
|
||||
|
||||
Bouncing
|
||||
--------
|
||||
We have a ball that can move around as well as the general game logic
|
||||
for moving things around. In contrast to a classic OO approach we do not
|
||||
need to implement the movement logic within the ``Ball`` and ``Player``
|
||||
class individually, since the basic movement is the same for all (yes,
|
||||
you could have solved that with inheriting ``Ball`` and ``Player`` from
|
||||
a ``MovableObject`` class in OO).
|
||||
|
||||
The ball now moves and stays within the bounds, but once it hits the
|
||||
left side, it will stay there. To make it *bouncy*, we need to add a
|
||||
simple collision system, which causes the ball to change its direction
|
||||
on colliding with the walls or the player paddles. ::
|
||||
|
||||
[...]
|
||||
class CollisionSystem(sdl2.ext.Applicator):
|
||||
def __init__(self, minx, miny, maxx, maxy):
|
||||
super(CollisionSystem, self).__init__()
|
||||
self.componenttypes = Velocity, sdl2.ext.Sprite
|
||||
self.ball = None
|
||||
self.minx = minx
|
||||
self.miny = miny
|
||||
self.maxx = maxx
|
||||
self.maxy = maxy
|
||||
|
||||
def _overlap(self, item):
|
||||
pos, sprite = item
|
||||
if sprite == self.ball.sprite:
|
||||
return False
|
||||
|
||||
left, top, right, bottom = sprite.area
|
||||
bleft, btop, bright, bbottom = self.ball.sprite.area
|
||||
|
||||
return (bleft < right and bright > left and
|
||||
btop < bottom and bbottom > top)
|
||||
|
||||
def process(self, world, componentsets):
|
||||
collitems = [comp for comp in componentsets if self._overlap(comp)]
|
||||
if collitems:
|
||||
self.ball.velocity.vx = -self.ball.velocity.vx
|
||||
|
||||
|
||||
def run():
|
||||
[...]
|
||||
world = World()
|
||||
|
||||
movement = MovementSystem(0, 0, 800, 600)
|
||||
collision = CollisionSystem(0, 0, 800, 600)
|
||||
spriterenderer = SoftwareRenderer(window)
|
||||
|
||||
world.add_system(movement)
|
||||
world.add_system(collision)
|
||||
world.add_system(spriterenderer)
|
||||
|
||||
[...]
|
||||
collision.ball = ball
|
||||
|
||||
running = True
|
||||
while running:
|
||||
events = sdl2.ext.get_events()
|
||||
for event in events:
|
||||
if event.type == sdl2.SDL_QUIT:
|
||||
running = False
|
||||
break
|
||||
sdl2.SDL_Delay(10)
|
||||
world.process()
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run())
|
||||
|
||||
The ``CollisionSystem`` only needs to take care of the ball and objects
|
||||
it collides with, since the ball is the only unpredictable object within our
|
||||
game world. The player paddles will only be able to move up and down
|
||||
within the visible window area and we already dealt with that within the
|
||||
``MovementSystem`` code.
|
||||
|
||||
Whenever the ball collides with one of the paddles, its movement
|
||||
direction (velocity) should be inverted, so that it *bounces* back.
|
||||
|
||||
Additionally, we won't run at the full processor speed anymore in the
|
||||
main loop, but instead add a short delay, using the
|
||||
:func:`sdl2.SDL_Delay` function. This reduces the overall load on the
|
||||
CPU and makes the game a bit slower.
|
||||
|
||||
Reacting on player input
|
||||
------------------------
|
||||
We have a moving ball that bounces from side to side. The next step
|
||||
would be to allow moving one of the paddles around, if the player presses a
|
||||
key. The SDL event routines allow us to deal with a huge variety of user and
|
||||
system events that could occur for our application, but right now we are only
|
||||
interested in key strokes for the Up and Down keys to move one of the player
|
||||
paddles up or down. ::
|
||||
|
||||
[...]
|
||||
def run():
|
||||
[...]
|
||||
running = True
|
||||
while running:
|
||||
events = sdl2.ext.get_events()
|
||||
for event in events:
|
||||
if event.type == sdl2.SDL_QUIT:
|
||||
running = False
|
||||
break
|
||||
if event.type == sdl2.SDL_KEYDOWN:
|
||||
if event.key.keysym.sym == sdl2.SDLK_UP:
|
||||
player1.velocity.vy = -3
|
||||
elif event.key.keysym.sym == sdl2.SDLK_DOWN:
|
||||
player1.velocity.vy = 3
|
||||
elif event.type == sdl2.SDL_KEYUP:
|
||||
if event.key.keysym.sym in (sdl2.SDLK_UP, sdl2.SDLK_DOWN):
|
||||
player1.velocity.vy = 0
|
||||
sdl2.SDL_Delay(10)
|
||||
world.process()
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run())
|
||||
|
||||
Every event that can occur and that is supported by SDL2 can be identified by a
|
||||
static event type code. This allows us to check for a key stroke, mouse button
|
||||
press, and so on. First, we have to check for ``sdl2.SDL_KEYDOWN`` and
|
||||
``sdl2.SDL_KEYUP`` events, so we can start and stop the paddle movement on
|
||||
demand. Once we identified such events, we need to check, whether the pressed
|
||||
or released key is actually the Up or Down key, so that we do not start or stop
|
||||
moving the paddle, if the user presses R or G or whatever.
|
||||
|
||||
Whenever the Up or Down key are pressed down, we allow the left player
|
||||
paddle to move by changing its velocity information for the vertical
|
||||
direction. Likewise, if either of those keys is released, we stop moving
|
||||
the paddle.
|
||||
|
||||
Improved bouncing
|
||||
-----------------
|
||||
We have a moving paddle and we have a ball that bounces from one side to
|
||||
another, which makes the game ... quite boring. If you played Pong before,
|
||||
you know that most variations of it will cause the ball to bounce in a
|
||||
certain angle, if it collides with a paddle. Most of those
|
||||
implementations achieve this by implementing the paddle collision as if
|
||||
the ball collides with a rounded surface. If it collides with the center
|
||||
of the paddle, it will bounce back straight, if it hits the paddle near
|
||||
the center, it will bounce back with a pointed angle and on the corners
|
||||
of the paddle it will bounce back with some angle close to 90 degrees to
|
||||
its initial movement direction. ::
|
||||
|
||||
class CollisionSystem(sdl2.ext.Applicator):
|
||||
[...]
|
||||
|
||||
def process(self, world, componentsets):
|
||||
collitems = [comp for comp in componentsets if self._overlap(comp)]
|
||||
if collitems:
|
||||
self.ball.velocity.vx = -self.ball.velocity.vx
|
||||
|
||||
sprite = collitems[0][1]
|
||||
ballcentery = self.ball.sprite.y + self.ball.sprite.size[1] // 2
|
||||
halfheight = sprite.size[1] // 2
|
||||
stepsize = halfheight // 10
|
||||
degrees = 0.7
|
||||
paddlecentery = sprite.y + halfheight
|
||||
if ballcentery < paddlecentery:
|
||||
factor = (paddlecentery - ballcentery) // stepsize
|
||||
self.ball.velocity.vy = -int(round(factor * degrees))
|
||||
elif ballcentery > paddlecentery:
|
||||
factor = (ballcentery - paddlecentery) // stepsize
|
||||
self.ball.velocity.vy = int(round(factor * degrees))
|
||||
else:
|
||||
self.ball.velocity.vy = - self.ball.velocity.vy
|
||||
|
||||
The reworked processing code above simulates a curved paddle by
|
||||
creating segmented areas, which cause the ball to be reflected in
|
||||
different angles. Instead of doing some complex trigonometry to
|
||||
calculate an accurate angle and transform it on a x/y plane, we simply
|
||||
check, where the ball collided with the paddle and adjust the vertical
|
||||
velocity.
|
||||
|
||||
If the ball now hits a paddle, it can be reflected at different angles,
|
||||
hitting the top and bottom window boundaries... and will stay there. If it
|
||||
hits the window boundaries, it should be reflected, too, but not with a
|
||||
varying angle, but with the exact angle, it hit the boundary with.
|
||||
This means that we just need to invert the vertical velocity, once the
|
||||
ball hits the top or bottom. ::
|
||||
|
||||
class CollisionSystem(sdl2.ext.Applicator):
|
||||
[...]
|
||||
|
||||
def process(self, world, componentsets):
|
||||
[...]
|
||||
|
||||
if (self.ball.sprite.y <= self.miny or
|
||||
self.ball.sprite.y + self.ball.sprite.size[1] >= self.maxy):
|
||||
self.ball.velocity.vy = - self.ball.velocity.vy
|
||||
|
||||
if (self.ball.sprite.x <= self.minx or
|
||||
self.ball.sprite.x + self.ball.sprite.size[0] >= self.maxx):
|
||||
self.ball.velocity.vx = - self.ball.velocity.vx
|
||||
|
||||
Creating an enemy
|
||||
-----------------
|
||||
Now that we can shoot back the ball in different ways, it would be nice
|
||||
to have an opponent to play against. We could enhance the main event
|
||||
loop to recognise two different keys and manipulate the second paddle's
|
||||
velocity for two people playing against each other. We also could
|
||||
create a simple computer-controlled player that tries to hit the ball
|
||||
back to us, which sounds more interesting. ::
|
||||
|
||||
class TrackingAIController(sdl2.ext.Applicator):
|
||||
def __init__(self, miny, maxy):
|
||||
super(TrackingAIController, self).__init__()
|
||||
self.componenttypes = PlayerData, Velocity, sdl2.ext.Sprite
|
||||
self.miny = miny
|
||||
self.maxy = maxy
|
||||
self.ball = None
|
||||
|
||||
def process(self, world, componentsets):
|
||||
for pdata, vel, sprite in componentsets:
|
||||
if not pdata.ai:
|
||||
continue
|
||||
|
||||
centery = sprite.y + sprite.size[1] // 2
|
||||
if self.ball.velocity.vx < 0:
|
||||
# ball is moving away from the AI
|
||||
if centery < self.maxy // 2:
|
||||
vel.vy = 3
|
||||
elif centery > self.maxy // 2:
|
||||
vel.vy = -3
|
||||
else:
|
||||
vel.vy = 0
|
||||
else:
|
||||
bcentery = self.ball.sprite.y + self.ball.sprite.size[1] // 2
|
||||
if bcentery < centery:
|
||||
vel.vy = -3
|
||||
elif bcentery > centery:
|
||||
vel.vy = 3
|
||||
else:
|
||||
vel.vy = 0
|
||||
|
||||
|
||||
class PlayerData(object):
|
||||
def __init__(self):
|
||||
super(PlayerData, self).__init__()
|
||||
self.ai = False
|
||||
|
||||
|
||||
class Player(sdl2.ext.Entity):
|
||||
def __init__(self, world, sprite, posx=0, posy=0, ai=False):
|
||||
self.sprite = sprite
|
||||
self.sprite.position = posx, posy
|
||||
self.velocity = Velocity()
|
||||
self.playerdata = PlayerData()
|
||||
self.playerdata.ai = ai
|
||||
|
||||
|
||||
def run():
|
||||
[...]
|
||||
aicontroller = TrackingAIController(0, 600)
|
||||
|
||||
world.add_system(aicontroller)
|
||||
world.add_system(movement)
|
||||
world.add_system(collision)
|
||||
world.add_system(spriterenderer)
|
||||
|
||||
player1 = Player(world, sp_paddle1, 0, 250)
|
||||
player2 = Player(world, sp_paddle2, 780, 250, True)
|
||||
[...]
|
||||
aicontroller.ball = ball
|
||||
|
||||
[...]
|
||||
|
||||
We start by creating a component ``PlayerData`` that flags a player as
|
||||
being AI controlled or not. Afterwards, a ``TrackingAIController`` is
|
||||
implemented, which, depending on the information of the ``PlayerData``
|
||||
component, will move the specific player paddle around by manipulating
|
||||
its velocity information.
|
||||
|
||||
The AI is pretty simple, just following the ball's vertical movement,
|
||||
trying to hit it at its center, if the ball moves into the direction of
|
||||
the AI-controlled paddle. As soon as the ball moves away from the
|
||||
paddle, the paddle will move back to the vertical center.
|
||||
|
||||
.. tip::
|
||||
|
||||
Add ``True`` as last parameter to the first ``Player()`` constructor to
|
||||
see two AIs playing against each other.
|
||||
|
||||
Next steps
|
||||
----------
|
||||
We created the basics of a Pong game, which can be found in the
|
||||
examples folder. However, there are some more things to do, such as
|
||||
|
||||
* resetting the ball to the center with a random vertical velocity, if
|
||||
it hits either the left or right window bounds
|
||||
|
||||
* adding the ability to track the points made by either player, if the
|
||||
ball hit the left or right side
|
||||
|
||||
* drawing a dashed line in the middle to make the game field look
|
||||
nicer
|
||||
|
||||
* displaying the points made by each player
|
||||
|
||||
It is your turn now to implement these features. Go ahead, it is not as
|
||||
complex as it sounds.
|
||||
|
||||
* you can reset the ball's position in the ``CollisionSystem`` code,
|
||||
by changing the code for the ``minx`` and ``maxx`` test
|
||||
|
||||
* you could enhance the ``CollisionSystem`` to process ``PlayerData``
|
||||
components and add the functionality to add points there (or write a
|
||||
small processor that keeps track of the ball only and processes only
|
||||
the ``PlayerData`` and ``video.SoftSprite`` objects of each player for
|
||||
adding points). Alternatively, you could use the
|
||||
:class:`sdl2.ext.EventHandler` class to raise a score count
|
||||
function within the ``CollisionSystem``, if the ball collides with
|
||||
one of the paddles.
|
||||
|
||||
* write an own render sytem, based on :class:`sdl2.ext.Applicator`,
|
||||
which takes care of position and sprite sets ::
|
||||
|
||||
StaticRepeatingSprite(Entity):
|
||||
...
|
||||
self.positions = Positions((400, 0), (400, 60), (400, 120), ...)
|
||||
...
|
||||
|
||||
* draw some simple images for 0-9 and render them as sprites,
|
||||
depending on the points a player made.
|
||||
|
||||
.. rubric:: Footnotes
|
||||
|
||||
.. [#f1] Component-Oriented Programming
|
|
@ -0,0 +1,369 @@
|
|||
PySDL2 for Pygamers
|
||||
===================
|
||||
|
||||
Care to move to a newer SDL with your Pygame knowledge? Then you should
|
||||
know one thing or two about PySDL2 before hacking code, since it is
|
||||
completely different from Pygame. Do not let that fact scare you away,
|
||||
the basics with graphics and sound are still the same (as they are
|
||||
fundamental), but you will not find many similarities to the Pygame API
|
||||
within PySDL2.
|
||||
|
||||
.. todo::
|
||||
|
||||
More details, examples, etc.
|
||||
|
||||
|
||||
Technical differences
|
||||
---------------------
|
||||
Pygame is implemented as a mixture of Python, C and Assembler code,
|
||||
wrapping 3rd party libraries with CPython API interfaces. PySDL2 in
|
||||
contrast is written in pure Python, using :mod:`ctypes` to interface
|
||||
with the C interfaces of 3rd party libraries.
|
||||
|
||||
API differences
|
||||
---------------
|
||||
|
||||
pygame
|
||||
^^^^^^
|
||||
======================= =================================================
|
||||
pygame sdl2
|
||||
======================= =================================================
|
||||
``init()`` :func:`sdl2.SDL_Init()` where appropriate
|
||||
``quit()`` :func:`sdl2.SDL_Quit()` where appropriate
|
||||
``error`` No equivalent
|
||||
``get_error()`` :func:`sdl2.SDL_GetError()`
|
||||
``set_error()`` :func:`sdl2.SDL_SetError()`
|
||||
``get_sdl_version()`` :func:`sdl2.SDL_GetVersion()`
|
||||
``get_sdl_byteorder()`` :data:`sdl2.SDL_BYTEORDER`
|
||||
``register_quit()`` No equivalent planned
|
||||
``encode_string()`` No equivalent planned
|
||||
``encode_file_path()`` No equivalent planned
|
||||
======================= =================================================
|
||||
|
||||
pygame.cdrom
|
||||
^^^^^^^^^^^^
|
||||
PySDL2 does not feature any CD-ROM related interfaces. They were
|
||||
removed in SDL2 and PySDL2 does not provide its own facilities.
|
||||
|
||||
pygame.Color
|
||||
^^^^^^^^^^^^
|
||||
You can find a similar class in :class:`sdl2.ext.Color`. It does
|
||||
not feature a ``set_length()`` or ``correct_gamma()`` method, though.
|
||||
|
||||
pygame.cursors
|
||||
^^^^^^^^^^^^^^
|
||||
PySDL2 does not feature any pre-defined cursor settings at the moment.
|
||||
|
||||
pygame.display
|
||||
^^^^^^^^^^^^^^
|
||||
======================= =================================================
|
||||
pygame.display sdl2
|
||||
======================= =================================================
|
||||
``init()`` :func:`sdl2.ext.init()`
|
||||
``quit()`` :func:`sdl2.ext.quit()`
|
||||
``get_init()`` :func:`sdl2.SDL_WasInit()`
|
||||
``set_mode()`` :class:`sdl2.ext.Window`
|
||||
``get_surface()`` :meth:`sdl2.ext.Window.get_surface()`
|
||||
``flip()`` :meth:`sdl2.ext.Window.refresh()`
|
||||
``update()`` :meth:`sdl2.ext.Window.refresh()`
|
||||
``get_driver()`` :func:`sdl2.SDL_GetCurrentVideoDriver()`
|
||||
``Info`` No equivalent
|
||||
``get_wm_info()`` :func:`sdl2.SDL_GetWindowWMInfo()`
|
||||
``list_modes()`` :func:`sdl2.SDL_GetNumDisplayModes()`
|
||||
``mode_ok()`` :func:`sdl2.SDL_GetClosestDisplayMode()`
|
||||
``gl_get_attribute()`` :func:`sdl2.SDL_GL_GetAttribute()`
|
||||
``gl_set_attribute()`` :func:`sdl2.SDL_GL_SetAttribute()`
|
||||
``get_active()`` No equivalent
|
||||
``iconify()`` :meth:`sdl2.ext.Window.minimize()`
|
||||
``toggle_fullscreen()`` :func:`sdl2.SDL_SetWindowFullscreen()`
|
||||
``set_gamma()`` :func:`sdl2.SDL_SetWindowBrightness()`
|
||||
``set_gamma_ramp()`` :func:`sdl2.SDL_SetWindowGammaRamp.()`
|
||||
``set_icon()`` :func:`sdl2.SDL_SetWindowIcon()`
|
||||
``set_caption()`` :attr:`sdl2.ext.Window.title`
|
||||
``get_caption()`` :attr:`sdl2.ext.Window.title`
|
||||
``set_palette()`` :func:`sdl2.SDL_SetSurfacePalette()`
|
||||
======================= =================================================
|
||||
|
||||
pygame.draw
|
||||
^^^^^^^^^^^
|
||||
Drawing primitives can be accessed through either the
|
||||
``sdl2.SDL_RenderDraw*()`` and ``sdl2.SDL_RenderFill*()`` functions or
|
||||
the more powerful :mod:`sdl2.sdlgfx` module,
|
||||
|
||||
pygame.event
|
||||
^^^^^^^^^^^^
|
||||
================= =================================================
|
||||
pygame.event sdl2
|
||||
================= =================================================
|
||||
``pump()`` :func:`sdl2.SDL_PumpEvents()`
|
||||
``get()`` :func:`sdl2.SDL_PollEvent()` or :func:`sdl2.ext.get_events()`
|
||||
``poll()`` :func:`sdl2.SDL_PollEvent()`
|
||||
``wait()`` :func:`sdl2.SDL_WaitEvent()`
|
||||
``peek()`` :func:`sdl2.SDL_PeepEvents()`
|
||||
``clear()`` :func:`sdl2.SDL_FlushEvents()`
|
||||
``event_name()`` No equivalent
|
||||
``set_blocked()`` :func:`sdl2.SDL_EventState()`
|
||||
``get_blocked()`` :func:`sdl2.SDL_EventState()`
|
||||
``set_allowed()`` :func:`sdl2.SDL_EventState()`
|
||||
``set_grab()`` :func:`sdl2.SDL_SetWindowGrab()`
|
||||
``get_grab()`` :func:`sdl2.SDL_GetWindowGrab()`
|
||||
``post()`` :func:`sdl2.SDL_PeepEvents()`
|
||||
``Event`` :class:`sdl2.SDL_Event`
|
||||
================= =================================================
|
||||
|
||||
pygame.font
|
||||
^^^^^^^^^^^
|
||||
====================== =================================================
|
||||
pygame.font sdl2
|
||||
====================== =================================================
|
||||
``init()`` :func:`sdl2.sdlttf.TTF_Init()`
|
||||
``quit()`` :func:`sdl2.sdlttf.TTF_Quit()`
|
||||
``get_init()`` :func:`sdl2.sdlttf.TTF_WasInit()`
|
||||
``get_default_font()`` No equivalent planned [#f1]_
|
||||
``get_fonts()`` No equivalent planned [#f1]_
|
||||
``match_font()`` No equivalent planned [#f1]_
|
||||
``SysFont`` No equivalent planned [#f1]_
|
||||
``Font`` No equivalent planned [#f1]_
|
||||
====================== =================================================
|
||||
|
||||
pygame.freetype
|
||||
^^^^^^^^^^^^^^^
|
||||
PySDL2 does not feature direct FreeType support.
|
||||
|
||||
pygame.gfxdraw
|
||||
^^^^^^^^^^^^^^
|
||||
PySDL2 offers SDL_gfx support through the :mod:`sdl2.sdlgfx` module.
|
||||
|
||||
pygame.image
|
||||
^^^^^^^^^^^^
|
||||
================== =================================================
|
||||
pygame.image sdl2
|
||||
================== =================================================
|
||||
``load()`` :func:`sdl2.sdlimage.IMG_Load()`,
|
||||
:func:`sdl2.ext.load_image()`
|
||||
``save()`` :func:`sdl2.surface.SDL_SaveBMP()`,
|
||||
:func:`sdl2.sdlimage.IMG_SavePNG()`
|
||||
``get_extended()`` :func:`sdl2.sdlimage.IMG_isBMP()` et al.
|
||||
``tostring()`` No equivalent yet
|
||||
``fromstring()`` No equivalent yet
|
||||
``frombuffer()`` No equivalent yet
|
||||
================== =================================================
|
||||
|
||||
pygame.joystick
|
||||
^^^^^^^^^^^^^^^
|
||||
================== ========================================================
|
||||
pygame.joystick sdl2
|
||||
================== ========================================================
|
||||
``init()`` :func:`sdl2.SDL_Init()`
|
||||
``quit()`` :func:`sdl2.SDL_Quit()`
|
||||
``get_init()`` :func:`sdl2.SDL_WasInit()`
|
||||
``get_count()`` :func:`sdl2.joystick.SDL_NumJoysticks()`
|
||||
``Joystick()`` :class:`sdl2.joystick.SDL_Joystick` and related
|
||||
functions
|
||||
================== ========================================================
|
||||
|
||||
pygame.key
|
||||
^^^^^^^^^^
|
||||
================== ========================================================
|
||||
pygame.key sdl2
|
||||
================== ========================================================
|
||||
``get_focused()`` :func:`sdl2.keyboard.SDL_GetKeyboardFocus()`
|
||||
``get_pressed()`` :func:`sdl2.keyboard.SDL_GetKeyboardState()`
|
||||
``get_mods()`` :func:`sdl2.keyboard.SDL_GetModState()`
|
||||
``set_mods()`` :func:`sdl2.keyboard.SDL_SetModState()`
|
||||
``set_repeat()`` Based on the OS/WM settings, no equivalent
|
||||
``get_repeat()`` Based on the OS/WM settings, no equivalent
|
||||
``name()`` :func:`sdl2.keyboard.SDL_GetKeyName()`
|
||||
================== ========================================================
|
||||
|
||||
pygame.locals
|
||||
^^^^^^^^^^^^^
|
||||
Constants in PySDL2 are spread across the different packages and
|
||||
modules, depending on where they originate from.
|
||||
|
||||
pygame.mixer
|
||||
^^^^^^^^^^^^
|
||||
====================== ====================================================
|
||||
pygame.mixer sdl2
|
||||
====================== ====================================================
|
||||
``init()`` :func:`sdl2.sdlmixer.Mix_Init()`
|
||||
``quit()`` :func:`sdl2.sdlmixer.Mix_Quit()`
|
||||
``get_init()`` No equivalent planned
|
||||
``stop()`` :func:`sdl2.sdlmixer.Mix_HaltChannel()`,
|
||||
:func:`sdl2.sdlmixer.Mix_HaltGroup()`,
|
||||
:func:`sdl2.sdlmixer.Mix_HaltMusic()`
|
||||
``pause()`` :func:`sdl2.sdlmixer.Mix_Pause()`,
|
||||
:func:`sdl2.sdlmixer.Mix_PauseMusic()`
|
||||
``unpause()`` :func:`sdl2.sdlmixer.Mix_Resume()`,
|
||||
:func:`sdl2.sdlmixer.Mix_ResumeMusic()`
|
||||
``fadeout()`` :func:`sdl2.sdlmixer.Mix_FadeOutChannel()`,
|
||||
:func:`sdl2.sdlmixer.Mix_FadeOutGroup()`,
|
||||
:func:`sdl2.sdlmixer.Mix_FadeOutMusic()`
|
||||
``set_num_channels()`` :func:`sdl2.sdlmixer.Mix_AllocateChannels()`
|
||||
``get_num_channels()`` :func:`sdl2.sdlmixer.Mix_AllocateChannels()`
|
||||
``set_reserved()`` :func:`sdl2.sdlmixer.Mix_ReserveChannels()`
|
||||
``find_channel()`` No equivalent planned
|
||||
``get_busy()`` :func:`sdl2.sdlmixer.Mix_ChannelFinished`
|
||||
``Sound`` :class:`sdl2.sdlmixer.Mix_Chunk`
|
||||
``Channel`` No equivalent, use the channel functions instead
|
||||
====================== ====================================================
|
||||
|
||||
pygame.mixer.music
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
See `pygame.mixer`_.
|
||||
|
||||
pygame.mouse
|
||||
^^^^^^^^^^^^
|
||||
================= ====================================================
|
||||
pygame.mouse sdl2
|
||||
================= ====================================================
|
||||
``get_pressed()`` :func:`sdl2.mouse.SDL_GetMouseState()`
|
||||
``get_pos()`` :func:`sdl2.mouse.SDL_GetMouseState()`
|
||||
``get_rel()`` :func:`sdl2.mouse.SDL_GetRelativeMouseState()`
|
||||
``set_pos()`` :func:`sdl2.mouse.SDL_WarpMouseInWindow()`
|
||||
``set_visible()`` :func:`sdl2.mouse.SDL_ShowCursor()`
|
||||
``get_focused()`` :func:`sdl2.mouse.SDL_GetMouseFocus()`
|
||||
``set_cursor()`` :func:`sdl2.mouse.SDL_GetCursor()`
|
||||
``get_cursor()`` :func:`sdl2.mouse.SDL_SetCursor()`
|
||||
================= ====================================================
|
||||
|
||||
pygame.movie
|
||||
^^^^^^^^^^^^
|
||||
No such module is planned for PySDL2.
|
||||
|
||||
pygame.Overlay
|
||||
^^^^^^^^^^^^^^
|
||||
You can work with YUV overlays by using the :mod:`sdl2.render` module
|
||||
with :class:`sdl2.render.SDL_Texture` objects.
|
||||
|
||||
pygame.PixelArray
|
||||
^^^^^^^^^^^^^^^^^
|
||||
You can access pixel data of sprites and surfaces directly via the
|
||||
:class:`sdl2.ext.PixelView` class. It does not feature comparison or
|
||||
extractions methods.
|
||||
|
||||
pygame.Rect
|
||||
^^^^^^^^^^^
|
||||
No such functionality is available for PySDL2. Rectangles are represented
|
||||
via :class:`sdl2.rect.SDL_Rect` for low-level SDL2 wrappers or 4-value
|
||||
tuples.
|
||||
|
||||
pygame.scrap
|
||||
^^^^^^^^^^^^
|
||||
PySDL2 offers basic text-based clipboard access via the
|
||||
:mod:`sdl2.clipboard` module. A feature-rich clipboard API as for Pygame
|
||||
does not exist yet.
|
||||
|
||||
pygame.sndarray
|
||||
^^^^^^^^^^^^^^^
|
||||
No such module is available for PySDL2 yet.
|
||||
|
||||
pygame.sprite
|
||||
^^^^^^^^^^^^^
|
||||
PySDL2 uses a different approach of rendering and managing sprite
|
||||
objects via a component-based system and the :class:`sdl2.ext.Sprite`
|
||||
class. A sprite module as for Pygame is not planned.
|
||||
|
||||
pygame.Surface
|
||||
^^^^^^^^^^^^^^
|
||||
======================= =====================================================
|
||||
pygame.Surface sdl2
|
||||
======================= =====================================================
|
||||
``blit()`` :meth:`sdl2.surface.SDL_BlitSurface()`,
|
||||
:class:`sdl2.ext.SpriteRenderSystem`
|
||||
``convert()`` :func:`sdl2.surface.SDL_ConvertSurface()`
|
||||
``convert_alpha()`` :func:`sdl2.surface.SDL_ConvertSurface()`
|
||||
``copy()`` :func:`sdl2.surface.SDL_ConvertSurface()`
|
||||
``fill()`` :func:`sdl2.surface.SDL_FillRect()`,
|
||||
:func:`sdl2.surface.SDL_FillRects()`,
|
||||
:func:`sdl2.ext.fill()`
|
||||
``scroll()`` No equivalent planned
|
||||
``set_colorkey()`` :func:`sdl2.surface.SDL_SetColorKey()`
|
||||
``get_colorkey()`` :func:`sdl2.surface.SDL_GetColorKey()`
|
||||
``set_alpha()`` :func:`sdl2.surface.SDL_SetSurfaceAlphaMod()`
|
||||
``get_alpha()`` :func:`sdl2.surface.SDL_GetSurfaceAlphaMod()`
|
||||
``lock()`` :func:`sdl2.surface.SDL_LockSurface()`
|
||||
``unlock()`` :func:`sdl2.surface.SDL_UnlockSurface()`
|
||||
``mustlock()`` :func:`sdl2.surface.SDL_MUSTLOCK()`
|
||||
``get_locked()`` :attr:`sdl2.surface.SDL_Surface.locked`
|
||||
``get_locks()`` No equivalent planned
|
||||
``get_at()`` Direct access to the pixels for surfaces can be
|
||||
achieved via the :class:`sdl2.ext.PixelView` class
|
||||
``set_at()`` Direct access to the pixels for surfaces can be
|
||||
achieved via the :class:`sdl2.ext.PixelView` class
|
||||
``get_at_mapped()`` No equivalent planned
|
||||
``get_palette()`` via :attr:`sdl2.surface.SDL_Surface.format` and the
|
||||
:attr:`sdl2.pixels.SDL_PixelFormat.palette`
|
||||
attribute
|
||||
``get_palette_at()`` ``sdl2.pixels.SDL_Palette.colors[offset]``
|
||||
``set_palette()`` :func:`sdl2.surface.SDL_SetSurfacePalette()`
|
||||
``set_palette_at()`` ``sdl2.pixels.SDL_Palette.colors[offset]``
|
||||
``map_rgb()`` :func:`sdl2.pixels.SDL_MapRGB()`
|
||||
``unmap_rgb()`` :func:`sdl2.pixels.SDL_GetRGB()`
|
||||
``set_clip()`` :func:`sdl2.surface.SDL_SetClipRect()`
|
||||
``get_clip()`` :func:`sdl2.surface.SDL_GetClipRect()`
|
||||
``subsurface()`` :func:`sdl2.ext.subsurface()`
|
||||
``get_parent()`` No equivalent yet
|
||||
``get_abs_parent()`` As for ``get_parent``
|
||||
``get_offset()`` As for ``get_parent``
|
||||
``get_abs_offset()`` As for ``get_parent``
|
||||
``get_size()`` :attr:`sdl2.ext.Sprite.size`,
|
||||
:attr:`sdl2.surface.SDL_Surface.w`,
|
||||
:attr:`sdl2.surface.SDL_Surface.h`
|
||||
``get_width()`` ``sdl2.ext.Sprite.size[0]``,
|
||||
:attr:`sdl2.surface.SDL_Surface.w`,
|
||||
``get_height()`` ``sdl2.ext.Sprite.size[1]``,
|
||||
:attr:`sdl2.surface.SDL_Surface.h`
|
||||
``get_rect()`` No equivalent planned
|
||||
``get_bitsize()`` :attr:`sdl2.pixels.SDL_PixelFormat.BitsPerPixel`
|
||||
``get_bytesize()`` :attr:`sdl2.pixels.SDL_PixelFormat.BytesPerPixel`
|
||||
``get_flags()`` :attr:`sdl2.surface.SDL_Surface.flags`
|
||||
``get_pitch()`` :attr:`sdl2.surface.SDL_Surface.pitch`
|
||||
``get_masks()`` :attr:`sdl2.pixels.SDL_PixelFormat.Rmask`, ...
|
||||
``get_shifts()`` :attr:`sdl2.pixels.SDL_PixelFormat.Rshift`, ...
|
||||
``get_losses()`` :attr:`sdl2.pixels.SDL_PixelFormat.Rloss`, ...
|
||||
``get_bounding_rect()`` No equivalent planned
|
||||
``get_view()`` :class:`sdl2.ext.PixelView`
|
||||
``get_buffer()`` :class:`sdl2.ext.PixelView` or
|
||||
:attr:`sdl2.surface.SDL_Surface.pixels`
|
||||
======================= =====================================================
|
||||
|
||||
pygame.surfarray
|
||||
^^^^^^^^^^^^^^^^
|
||||
2D and 3D pixel access can be achieved via the
|
||||
:class:`sdl2.ext.PixelView` class in environments without
|
||||
numpy. Simplified numpy-array creation with direct pixel access (similar
|
||||
to ``pygame.surfarray.pixels2d()`` and ``pygame.surfarray.pixels3d()``)
|
||||
is available via :func:`sdl2.ext.pixels2d()` and
|
||||
:func:`sdl2.ext.pixels3d()`.
|
||||
|
||||
pygame.time
|
||||
^^^^^^^^^^^
|
||||
=============== =================================================
|
||||
pygame.time sdl2
|
||||
=============== =================================================
|
||||
``get_ticks()`` :func:`sdl2.timer.SDL_GetTicks()`
|
||||
``wait()`` :func:`sdl2.timer.SDL_Delay()`
|
||||
``delay()`` :func:`sdl2.timer.SDL_Delay()`
|
||||
``Clock`` No equivalent planned
|
||||
=============== =================================================
|
||||
|
||||
pygame.transform
|
||||
^^^^^^^^^^^^^^^^
|
||||
The are no transformation helpers in PySDL2 at moment. Those might be
|
||||
implemented later on via numpy helpers, the Python Imaging Library or
|
||||
other 3rd party packages.
|
||||
|
||||
pygame.version
|
||||
^^^^^^^^^^^^^^
|
||||
=============== =================================================
|
||||
pygame.version sdl2
|
||||
=============== =================================================
|
||||
``ver`` :attr:`sdl2.__version__`
|
||||
``vernum`` :attr:`sdl2.version_info`
|
||||
=============== =================================================
|
||||
|
||||
.. rubric:: Footnotes
|
||||
|
||||
.. [#f1] Check https://bitbucket.org/marcusva/python-utils for an easy
|
||||
to use system font detection module
|
After Width: | Height: | Size: 673 B |
|
@ -0,0 +1,604 @@
|
|||
/*
|
||||
* basic.css
|
||||
* ~~~~~~~~~
|
||||
*
|
||||
* Sphinx stylesheet -- basic theme.
|
||||
*
|
||||
* :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
* :license: BSD, see LICENSE for details.
|
||||
*
|
||||
*/
|
||||
|
||||
/* -- main layout ----------------------------------------------------------- */
|
||||
|
||||
div.clearer {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
/* -- relbar ---------------------------------------------------------------- */
|
||||
|
||||
div.related {
|
||||
width: 100%;
|
||||
font-size: 90%;
|
||||
}
|
||||
|
||||
div.related h3 {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div.related ul {
|
||||
margin: 0;
|
||||
padding: 0 0 0 10px;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
div.related li {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
div.related li.right {
|
||||
float: right;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
/* -- sidebar --------------------------------------------------------------- */
|
||||
|
||||
div.sphinxsidebarwrapper {
|
||||
padding: 10px 5px 0 10px;
|
||||
}
|
||||
|
||||
div.sphinxsidebar {
|
||||
float: left;
|
||||
width: 230px;
|
||||
margin-left: -100%;
|
||||
font-size: 90%;
|
||||
word-wrap: break-word;
|
||||
overflow-wrap : break-word;
|
||||
}
|
||||
|
||||
div.sphinxsidebar ul {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
div.sphinxsidebar ul ul,
|
||||
div.sphinxsidebar ul.want-points {
|
||||
margin-left: 20px;
|
||||
list-style: square;
|
||||
}
|
||||
|
||||
div.sphinxsidebar ul ul {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
div.sphinxsidebar form {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
div.sphinxsidebar input {
|
||||
border: 1px solid #98dbcc;
|
||||
font-family: sans-serif;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
div.sphinxsidebar #searchbox input[type="text"] {
|
||||
width: 170px;
|
||||
}
|
||||
|
||||
img {
|
||||
border: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
/* -- search page ----------------------------------------------------------- */
|
||||
|
||||
ul.search {
|
||||
margin: 10px 0 0 20px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ul.search li {
|
||||
padding: 5px 0 5px 20px;
|
||||
background-image: url(file.png);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0 7px;
|
||||
}
|
||||
|
||||
ul.search li a {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
ul.search li div.context {
|
||||
color: #888;
|
||||
margin: 2px 0 0 30px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
ul.keywordmatches li.goodmatch a {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* -- index page ------------------------------------------------------------ */
|
||||
|
||||
table.contentstable {
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
table.contentstable p.biglink {
|
||||
line-height: 150%;
|
||||
}
|
||||
|
||||
a.biglink {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
|
||||
span.linkdescr {
|
||||
font-style: italic;
|
||||
padding-top: 5px;
|
||||
font-size: 90%;
|
||||
}
|
||||
|
||||
/* -- general index --------------------------------------------------------- */
|
||||
|
||||
table.indextable {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.indextable td {
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
table.indextable dl, table.indextable dd {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
table.indextable tr.pcap {
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
table.indextable tr.cap {
|
||||
margin-top: 10px;
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
img.toggler {
|
||||
margin-right: 3px;
|
||||
margin-top: 3px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
div.modindex-jumpbox {
|
||||
border-top: 1px solid #ddd;
|
||||
border-bottom: 1px solid #ddd;
|
||||
margin: 1em 0 1em 0;
|
||||
padding: 0.4em;
|
||||
}
|
||||
|
||||
div.genindex-jumpbox {
|
||||
border-top: 1px solid #ddd;
|
||||
border-bottom: 1px solid #ddd;
|
||||
margin: 1em 0 1em 0;
|
||||
padding: 0.4em;
|
||||
}
|
||||
|
||||
/* -- general body styles --------------------------------------------------- */
|
||||
|
||||
div.body p, div.body dd, div.body li, div.body blockquote {
|
||||
-moz-hyphens: auto;
|
||||
-ms-hyphens: auto;
|
||||
-webkit-hyphens: auto;
|
||||
hyphens: auto;
|
||||
}
|
||||
|
||||
a.headerlink {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
h1:hover > a.headerlink,
|
||||
h2:hover > a.headerlink,
|
||||
h3:hover > a.headerlink,
|
||||
h4:hover > a.headerlink,
|
||||
h5:hover > a.headerlink,
|
||||
h6:hover > a.headerlink,
|
||||
dt:hover > a.headerlink,
|
||||
caption:hover > a.headerlink,
|
||||
p.caption:hover > a.headerlink,
|
||||
div.code-block-caption:hover > a.headerlink {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
div.body p.caption {
|
||||
text-align: inherit;
|
||||
}
|
||||
|
||||
div.body td {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.field-list ul {
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
.first {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
p.rubric {
|
||||
margin-top: 30px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
img.align-left, .figure.align-left, object.align-left {
|
||||
clear: left;
|
||||
float: left;
|
||||
margin-right: 1em;
|
||||
}
|
||||
|
||||
img.align-right, .figure.align-right, object.align-right {
|
||||
clear: right;
|
||||
float: right;
|
||||
margin-left: 1em;
|
||||
}
|
||||
|
||||
img.align-center, .figure.align-center, object.align-center {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.align-left {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.align-center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.align-right {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* -- sidebars -------------------------------------------------------------- */
|
||||
|
||||
div.sidebar {
|
||||
margin: 0 0 0.5em 1em;
|
||||
border: 1px solid #ddb;
|
||||
padding: 7px 7px 0 7px;
|
||||
background-color: #ffe;
|
||||
width: 40%;
|
||||
float: right;
|
||||
}
|
||||
|
||||
p.sidebar-title {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* -- topics ---------------------------------------------------------------- */
|
||||
|
||||
div.topic {
|
||||
border: 1px solid #ccc;
|
||||
padding: 7px 7px 0 7px;
|
||||
margin: 10px 0 10px 0;
|
||||
}
|
||||
|
||||
p.topic-title {
|
||||
font-size: 1.1em;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* -- admonitions ----------------------------------------------------------- */
|
||||
|
||||
div.admonition {
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
padding: 7px;
|
||||
}
|
||||
|
||||
div.admonition dt {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
div.admonition dl {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
p.admonition-title {
|
||||
margin: 0px 10px 5px 0px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
div.body p.centered {
|
||||
text-align: center;
|
||||
margin-top: 25px;
|
||||
}
|
||||
|
||||
/* -- tables ---------------------------------------------------------------- */
|
||||
|
||||
table.docutils {
|
||||
border: 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
table caption span.caption-number {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
table caption span.caption-text {
|
||||
}
|
||||
|
||||
table.docutils td, table.docutils th {
|
||||
padding: 1px 8px 1px 5px;
|
||||
border-top: 0;
|
||||
border-left: 0;
|
||||
border-right: 0;
|
||||
border-bottom: 1px solid #aaa;
|
||||
}
|
||||
|
||||
table.field-list td, table.field-list th {
|
||||
border: 0 !important;
|
||||
}
|
||||
|
||||
table.footnote td, table.footnote th {
|
||||
border: 0 !important;
|
||||
}
|
||||
|
||||
th {
|
||||
text-align: left;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
table.citation {
|
||||
border-left: solid 1px gray;
|
||||
margin-left: 1px;
|
||||
}
|
||||
|
||||
table.citation td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
/* -- figures --------------------------------------------------------------- */
|
||||
|
||||
div.figure {
|
||||
margin: 0.5em;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
div.figure p.caption {
|
||||
padding: 0.3em;
|
||||
}
|
||||
|
||||
div.figure p.caption span.caption-number {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
div.figure p.caption span.caption-text {
|
||||
}
|
||||
|
||||
|
||||
/* -- other body styles ----------------------------------------------------- */
|
||||
|
||||
ol.arabic {
|
||||
list-style: decimal;
|
||||
}
|
||||
|
||||
ol.loweralpha {
|
||||
list-style: lower-alpha;
|
||||
}
|
||||
|
||||
ol.upperalpha {
|
||||
list-style: upper-alpha;
|
||||
}
|
||||
|
||||
ol.lowerroman {
|
||||
list-style: lower-roman;
|
||||
}
|
||||
|
||||
ol.upperroman {
|
||||
list-style: upper-roman;
|
||||
}
|
||||
|
||||
dl {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
dd p {
|
||||
margin-top: 0px;
|
||||
}
|
||||
|
||||
dd ul, dd table {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
dd {
|
||||
margin-top: 3px;
|
||||
margin-bottom: 10px;
|
||||
margin-left: 30px;
|
||||
}
|
||||
|
||||
dt:target, .highlighted {
|
||||
background-color: #fbe54e;
|
||||
}
|
||||
|
||||
dl.glossary dt {
|
||||
font-weight: bold;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
.field-list ul {
|
||||
margin: 0;
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
.field-list p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.optional {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
|
||||
.sig-paren {
|
||||
font-size: larger;
|
||||
}
|
||||
|
||||
.versionmodified {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.system-message {
|
||||
background-color: #fda;
|
||||
padding: 5px;
|
||||
border: 3px solid red;
|
||||
}
|
||||
|
||||
.footnote:target {
|
||||
background-color: #ffa;
|
||||
}
|
||||
|
||||
.line-block {
|
||||
display: block;
|
||||
margin-top: 1em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.line-block .line-block {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
margin-left: 1.5em;
|
||||
}
|
||||
|
||||
.guilabel, .menuselection {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
.accelerator {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.classifier {
|
||||
font-style: oblique;
|
||||
}
|
||||
|
||||
abbr, acronym {
|
||||
border-bottom: dotted 1px;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
/* -- code displays --------------------------------------------------------- */
|
||||
|
||||
pre {
|
||||
overflow: auto;
|
||||
overflow-y: hidden; /* fixes display issues on Chrome browsers */
|
||||
}
|
||||
|
||||
td.linenos pre {
|
||||
padding: 5px 0px;
|
||||
border: 0;
|
||||
background-color: transparent;
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
table.highlighttable {
|
||||
margin-left: 0.5em;
|
||||
}
|
||||
|
||||
table.highlighttable td {
|
||||
padding: 0 0.5em 0 0.5em;
|
||||
}
|
||||
|
||||
div.code-block-caption {
|
||||
padding: 2px 5px;
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
div.code-block-caption code {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
div.code-block-caption + div > div.highlight > pre {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
div.code-block-caption span.caption-number {
|
||||
padding: 0.1em 0.3em;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
div.code-block-caption span.caption-text {
|
||||
}
|
||||
|
||||
div.literal-block-wrapper {
|
||||
padding: 1em 1em 0;
|
||||
}
|
||||
|
||||
div.literal-block-wrapper div.highlight {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
code.descname {
|
||||
background-color: transparent;
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
code.descclassname {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
code.xref, a code {
|
||||
background-color: transparent;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.viewcode-link {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.viewcode-back {
|
||||
float: right;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
div.viewcode-block:target {
|
||||
margin: -1px -10px;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
/* -- math display ---------------------------------------------------------- */
|
||||
|
||||
img.math {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.body div.math p {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
span.eqno {
|
||||
float: right;
|
||||
}
|
||||
|
||||
/* -- printout stylesheet --------------------------------------------------- */
|
||||
|
||||
@media print {
|
||||
div.document,
|
||||
div.documentwrapper,
|
||||
div.bodywrapper {
|
||||
margin: 0 !important;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.sphinxsidebar,
|
||||
div.related,
|
||||
div.footer,
|
||||
#top-link {
|
||||
display: none;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,261 @@
|
|||
/*
|
||||
* default.css_t
|
||||
* ~~~~~~~~~~~~~
|
||||
*
|
||||
* Sphinx stylesheet -- default theme.
|
||||
*
|
||||
* :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
* :license: BSD, see LICENSE for details.
|
||||
*
|
||||
*/
|
||||
|
||||
@import url("basic.css");
|
||||
|
||||
/* -- page layout ----------------------------------------------------------- */
|
||||
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
font-size: 100%;
|
||||
background-color: #11303d;
|
||||
color: #000;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
div.document {
|
||||
background-color: #1c4e63;
|
||||
}
|
||||
|
||||
div.documentwrapper {
|
||||
float: left;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.bodywrapper {
|
||||
margin: 0 0 0 230px;
|
||||
}
|
||||
|
||||
div.body {
|
||||
background-color: #ffffff;
|
||||
color: #000000;
|
||||
padding: 0 20px 30px 20px;
|
||||
}
|
||||
|
||||
div.footer {
|
||||
color: #ffffff;
|
||||
width: 100%;
|
||||
padding: 9px 0 9px 0;
|
||||
text-align: center;
|
||||
font-size: 75%;
|
||||
}
|
||||
|
||||
div.footer a {
|
||||
color: #ffffff;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
div.related {
|
||||
background-color: #133f52;
|
||||
line-height: 30px;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
div.related a {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
div.sphinxsidebar {
|
||||
}
|
||||
|
||||
div.sphinxsidebar h3 {
|
||||
font-family: 'Trebuchet MS', sans-serif;
|
||||
color: #ffffff;
|
||||
font-size: 1.4em;
|
||||
font-weight: normal;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
div.sphinxsidebar h3 a {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
div.sphinxsidebar h4 {
|
||||
font-family: 'Trebuchet MS', sans-serif;
|
||||
color: #ffffff;
|
||||
font-size: 1.3em;
|
||||
font-weight: normal;
|
||||
margin: 5px 0 0 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
div.sphinxsidebar p {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
div.sphinxsidebar p.topless {
|
||||
margin: 5px 10px 10px 10px;
|
||||
}
|
||||
|
||||
div.sphinxsidebar ul {
|
||||
margin: 10px;
|
||||
padding: 0;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
div.sphinxsidebar a {
|
||||
color: #98dbcc;
|
||||
}
|
||||
|
||||
div.sphinxsidebar input {
|
||||
border: 1px solid #98dbcc;
|
||||
font-family: sans-serif;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* -- hyperlink styles ------------------------------------------------------ */
|
||||
|
||||
a {
|
||||
color: #355f7c;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #355f7c;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* -- body styles ----------------------------------------------------------- */
|
||||
|
||||
div.body h1,
|
||||
div.body h2,
|
||||
div.body h3,
|
||||
div.body h4,
|
||||
div.body h5,
|
||||
div.body h6 {
|
||||
font-family: 'Trebuchet MS', sans-serif;
|
||||
background-color: #f2f2f2;
|
||||
font-weight: normal;
|
||||
color: #20435c;
|
||||
border-bottom: 1px solid #ccc;
|
||||
margin: 20px -20px 10px -20px;
|
||||
padding: 3px 0 3px 10px;
|
||||
}
|
||||
|
||||
div.body h1 { margin-top: 0; font-size: 200%; }
|
||||
div.body h2 { font-size: 160%; }
|
||||
div.body h3 { font-size: 140%; }
|
||||
div.body h4 { font-size: 120%; }
|
||||
div.body h5 { font-size: 110%; }
|
||||
div.body h6 { font-size: 100%; }
|
||||
|
||||
a.headerlink {
|
||||
color: #c60f0f;
|
||||
font-size: 0.8em;
|
||||
padding: 0 4px 0 4px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a.headerlink:hover {
|
||||
background-color: #c60f0f;
|
||||
color: white;
|
||||
}
|
||||
|
||||
div.body p, div.body dd, div.body li, div.body blockquote {
|
||||
text-align: justify;
|
||||
line-height: 130%;
|
||||
}
|
||||
|
||||
div.admonition p.admonition-title + p {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
div.admonition p {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
div.admonition pre {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
div.admonition ul, div.admonition ol {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
div.note {
|
||||
background-color: #eee;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
div.seealso {
|
||||
background-color: #ffc;
|
||||
border: 1px solid #ff6;
|
||||
}
|
||||
|
||||
div.topic {
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
div.warning {
|
||||
background-color: #ffe4e4;
|
||||
border: 1px solid #f66;
|
||||
}
|
||||
|
||||
p.admonition-title {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
p.admonition-title:after {
|
||||
content: ":";
|
||||
}
|
||||
|
||||
pre {
|
||||
padding: 5px;
|
||||
background-color: #eeffcc;
|
||||
color: #333333;
|
||||
line-height: 120%;
|
||||
border: 1px solid #ac9;
|
||||
border-left: none;
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: #ecf0f3;
|
||||
padding: 0 1px 0 1px;
|
||||
font-size: 0.95em;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: #ede;
|
||||
}
|
||||
|
||||
.warning code {
|
||||
background: #efc2c2;
|
||||
}
|
||||
|
||||
.note code {
|
||||
background: #d6d6d6;
|
||||
}
|
||||
|
||||
.viewcode-back {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
div.viewcode-block:target {
|
||||
background-color: #f4debf;
|
||||
border-top: 1px solid #ac9;
|
||||
border-bottom: 1px solid #ac9;
|
||||
}
|
||||
|
||||
div.code-block-caption {
|
||||
color: #efefef;
|
||||
background-color: #1c4e63;
|
||||
}
|
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 3.4 KiB |
|
@ -0,0 +1 @@
|
|||
@import url("classic.css");
|
|
@ -0,0 +1,287 @@
|
|||
/*
|
||||
* doctools.js
|
||||
* ~~~~~~~~~~~
|
||||
*
|
||||
* Sphinx JavaScript utilities for all documentation.
|
||||
*
|
||||
* :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
* :license: BSD, see LICENSE for details.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* select a different prefix for underscore
|
||||
*/
|
||||
$u = _.noConflict();
|
||||
|
||||
/**
|
||||
* make the code below compatible with browsers without
|
||||
* an installed firebug like debugger
|
||||
if (!window.console || !console.firebug) {
|
||||
var names = ["log", "debug", "info", "warn", "error", "assert", "dir",
|
||||
"dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace",
|
||||
"profile", "profileEnd"];
|
||||
window.console = {};
|
||||
for (var i = 0; i < names.length; ++i)
|
||||
window.console[names[i]] = function() {};
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* small helper function to urldecode strings
|
||||
*/
|
||||
jQuery.urldecode = function(x) {
|
||||
return decodeURIComponent(x).replace(/\+/g, ' ');
|
||||
};
|
||||
|
||||
/**
|
||||
* small helper function to urlencode strings
|
||||
*/
|
||||
jQuery.urlencode = encodeURIComponent;
|
||||
|
||||
/**
|
||||
* This function returns the parsed url parameters of the
|
||||
* current request. Multiple values per key are supported,
|
||||
* it will always return arrays of strings for the value parts.
|
||||
*/
|
||||
jQuery.getQueryParameters = function(s) {
|
||||
if (typeof s == 'undefined')
|
||||
s = document.location.search;
|
||||
var parts = s.substr(s.indexOf('?') + 1).split('&');
|
||||
var result = {};
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
var tmp = parts[i].split('=', 2);
|
||||
var key = jQuery.urldecode(tmp[0]);
|
||||
var value = jQuery.urldecode(tmp[1]);
|
||||
if (key in result)
|
||||
result[key].push(value);
|
||||
else
|
||||
result[key] = [value];
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* highlight a given string on a jquery object by wrapping it in
|
||||
* span elements with the given class name.
|
||||
*/
|
||||
jQuery.fn.highlightText = function(text, className) {
|
||||
function highlight(node) {
|
||||
if (node.nodeType == 3) {
|
||||
var val = node.nodeValue;
|
||||
var pos = val.toLowerCase().indexOf(text);
|
||||
if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) {
|
||||
var span = document.createElement("span");
|
||||
span.className = className;
|
||||
span.appendChild(document.createTextNode(val.substr(pos, text.length)));
|
||||
node.parentNode.insertBefore(span, node.parentNode.insertBefore(
|
||||
document.createTextNode(val.substr(pos + text.length)),
|
||||
node.nextSibling));
|
||||
node.nodeValue = val.substr(0, pos);
|
||||
}
|
||||
}
|
||||
else if (!jQuery(node).is("button, select, textarea")) {
|
||||
jQuery.each(node.childNodes, function() {
|
||||
highlight(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
return this.each(function() {
|
||||
highlight(this);
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* backward compatibility for jQuery.browser
|
||||
* This will be supported until firefox bug is fixed.
|
||||
*/
|
||||
if (!jQuery.browser) {
|
||||
jQuery.uaMatch = function(ua) {
|
||||
ua = ua.toLowerCase();
|
||||
|
||||
var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
|
||||
/(webkit)[ \/]([\w.]+)/.exec(ua) ||
|
||||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
|
||||
/(msie) ([\w.]+)/.exec(ua) ||
|
||||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
|
||||
[];
|
||||
|
||||
return {
|
||||
browser: match[ 1 ] || "",
|
||||
version: match[ 2 ] || "0"
|
||||
};
|
||||
};
|
||||
jQuery.browser = {};
|
||||
jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Small JavaScript module for the documentation.
|
||||
*/
|
||||
var Documentation = {
|
||||
|
||||
init : function() {
|
||||
this.fixFirefoxAnchorBug();
|
||||
this.highlightSearchWords();
|
||||
this.initIndexTable();
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* i18n support
|
||||
*/
|
||||
TRANSLATIONS : {},
|
||||
PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; },
|
||||
LOCALE : 'unknown',
|
||||
|
||||
// gettext and ngettext don't access this so that the functions
|
||||
// can safely bound to a different name (_ = Documentation.gettext)
|
||||
gettext : function(string) {
|
||||
var translated = Documentation.TRANSLATIONS[string];
|
||||
if (typeof translated == 'undefined')
|
||||
return string;
|
||||
return (typeof translated == 'string') ? translated : translated[0];
|
||||
},
|
||||
|
||||
ngettext : function(singular, plural, n) {
|
||||
var translated = Documentation.TRANSLATIONS[singular];
|
||||
if (typeof translated == 'undefined')
|
||||
return (n == 1) ? singular : plural;
|
||||
return translated[Documentation.PLURALEXPR(n)];
|
||||
},
|
||||
|
||||
addTranslations : function(catalog) {
|
||||
for (var key in catalog.messages)
|
||||
this.TRANSLATIONS[key] = catalog.messages[key];
|
||||
this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')');
|
||||
this.LOCALE = catalog.locale;
|
||||
},
|
||||
|
||||
/**
|
||||
* add context elements like header anchor links
|
||||
*/
|
||||
addContextElements : function() {
|
||||
$('div[id] > :header:first').each(function() {
|
||||
$('<a class="headerlink">\u00B6</a>').
|
||||
attr('href', '#' + this.id).
|
||||
attr('title', _('Permalink to this headline')).
|
||||
appendTo(this);
|
||||
});
|
||||
$('dt[id]').each(function() {
|
||||
$('<a class="headerlink">\u00B6</a>').
|
||||
attr('href', '#' + this.id).
|
||||
attr('title', _('Permalink to this definition')).
|
||||
appendTo(this);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* workaround a firefox stupidity
|
||||
* see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075
|
||||
*/
|
||||
fixFirefoxAnchorBug : function() {
|
||||
if (document.location.hash)
|
||||
window.setTimeout(function() {
|
||||
document.location.href += '';
|
||||
}, 10);
|
||||
},
|
||||
|
||||
/**
|
||||
* highlight the search words provided in the url in the text
|
||||
*/
|
||||
highlightSearchWords : function() {
|
||||
var params = $.getQueryParameters();
|
||||
var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : [];
|
||||
if (terms.length) {
|
||||
var body = $('div.body');
|
||||
if (!body.length) {
|
||||
body = $('body');
|
||||
}
|
||||
window.setTimeout(function() {
|
||||
$.each(terms, function() {
|
||||
body.highlightText(this.toLowerCase(), 'highlighted');
|
||||
});
|
||||
}, 10);
|
||||
$('<p class="highlight-link"><a href="javascript:Documentation.' +
|
||||
'hideSearchWords()">' + _('Hide Search Matches') + '</a></p>')
|
||||
.appendTo($('#searchbox'));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* init the domain index toggle buttons
|
||||
*/
|
||||
initIndexTable : function() {
|
||||
var togglers = $('img.toggler').click(function() {
|
||||
var src = $(this).attr('src');
|
||||
var idnum = $(this).attr('id').substr(7);
|
||||
$('tr.cg-' + idnum).toggle();
|
||||
if (src.substr(-9) == 'minus.png')
|
||||
$(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
|
||||
else
|
||||
$(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
|
||||
}).css('display', '');
|
||||
if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) {
|
||||
togglers.click();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* helper function to hide the search marks again
|
||||
*/
|
||||
hideSearchWords : function() {
|
||||
$('#searchbox .highlight-link').fadeOut(300);
|
||||
$('span.highlighted').removeClass('highlighted');
|
||||
},
|
||||
|
||||
/**
|
||||
* make the url absolute
|
||||
*/
|
||||
makeURL : function(relativeURL) {
|
||||
return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL;
|
||||
},
|
||||
|
||||
/**
|
||||
* get the current relative url
|
||||
*/
|
||||
getCurrentURL : function() {
|
||||
var path = document.location.pathname;
|
||||
var parts = path.split(/\//);
|
||||
$.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() {
|
||||
if (this == '..')
|
||||
parts.pop();
|
||||
});
|
||||
var url = parts.join('/');
|
||||
return path.substring(url.lastIndexOf('/') + 1, path.length - 1);
|
||||
},
|
||||
|
||||
initOnKeyListeners: function() {
|
||||
$(document).keyup(function(event) {
|
||||
var activeElementType = document.activeElement.tagName;
|
||||
// don't navigate when in search box or textarea
|
||||
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT') {
|
||||
switch (event.keyCode) {
|
||||
case 37: // left
|
||||
var prevHref = $('link[rel="prev"]').prop('href');
|
||||
if (prevHref) {
|
||||
window.location.href = prevHref;
|
||||
return false;
|
||||
}
|
||||
case 39: // right
|
||||
var nextHref = $('link[rel="next"]').prop('href');
|
||||
if (nextHref) {
|
||||
window.location.href = nextHref;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// quick alias for translations
|
||||
_ = Documentation.gettext;
|
||||
|
||||
$(document).ready(function() {
|
||||
Documentation.init();
|
||||
});
|
After Width: | Height: | Size: 347 B |
After Width: | Height: | Size: 347 B |
After Width: | Height: | Size: 358 B |
After Width: | Height: | Size: 173 B |
After Width: | Height: | Size: 173 B |
|
@ -0,0 +1,65 @@
|
|||
.highlight .hll { background-color: #ffffcc }
|
||||
.highlight { background: #eeffcc; }
|
||||
.highlight .c { color: #408090; font-style: italic } /* Comment */
|
||||
.highlight .err { border: 1px solid #FF0000 } /* Error */
|
||||
.highlight .k { color: #007020; font-weight: bold } /* Keyword */
|
||||
.highlight .o { color: #666666 } /* Operator */
|
||||
.highlight .ch { color: #408090; font-style: italic } /* Comment.Hashbang */
|
||||
.highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */
|
||||
.highlight .cp { color: #007020 } /* Comment.Preproc */
|
||||
.highlight .cpf { color: #408090; font-style: italic } /* Comment.PreprocFile */
|
||||
.highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */
|
||||
.highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */
|
||||
.highlight .gd { color: #A00000 } /* Generic.Deleted */
|
||||
.highlight .ge { font-style: italic } /* Generic.Emph */
|
||||
.highlight .gr { color: #FF0000 } /* Generic.Error */
|
||||
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
||||
.highlight .gi { color: #00A000 } /* Generic.Inserted */
|
||||
.highlight .go { color: #333333 } /* Generic.Output */
|
||||
.highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
|
||||
.highlight .gs { font-weight: bold } /* Generic.Strong */
|
||||
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
||||
.highlight .gt { color: #0044DD } /* Generic.Traceback */
|
||||
.highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
|
||||
.highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
|
||||
.highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
|
||||
.highlight .kp { color: #007020 } /* Keyword.Pseudo */
|
||||
.highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
|
||||
.highlight .kt { color: #902000 } /* Keyword.Type */
|
||||
.highlight .m { color: #208050 } /* Literal.Number */
|
||||
.highlight .s { color: #4070a0 } /* Literal.String */
|
||||
.highlight .na { color: #4070a0 } /* Name.Attribute */
|
||||
.highlight .nb { color: #007020 } /* Name.Builtin */
|
||||
.highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
|
||||
.highlight .no { color: #60add5 } /* Name.Constant */
|
||||
.highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
|
||||
.highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */
|
||||
.highlight .ne { color: #007020 } /* Name.Exception */
|
||||
.highlight .nf { color: #06287e } /* Name.Function */
|
||||
.highlight .nl { color: #002070; font-weight: bold } /* Name.Label */
|
||||
.highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
|
||||
.highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */
|
||||
.highlight .nv { color: #bb60d5 } /* Name.Variable */
|
||||
.highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */
|
||||
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
|
||||
.highlight .mb { color: #208050 } /* Literal.Number.Bin */
|
||||
.highlight .mf { color: #208050 } /* Literal.Number.Float */
|
||||
.highlight .mh { color: #208050 } /* Literal.Number.Hex */
|
||||
.highlight .mi { color: #208050 } /* Literal.Number.Integer */
|
||||
.highlight .mo { color: #208050 } /* Literal.Number.Oct */
|
||||
.highlight .sb { color: #4070a0 } /* Literal.String.Backtick */
|
||||
.highlight .sc { color: #4070a0 } /* Literal.String.Char */
|
||||
.highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
|
||||
.highlight .s2 { color: #4070a0 } /* Literal.String.Double */
|
||||
.highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
|
||||
.highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */
|
||||
.highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
|
||||
.highlight .sx { color: #c65d09 } /* Literal.String.Other */
|
||||
.highlight .sr { color: #235388 } /* Literal.String.Regex */
|
||||
.highlight .s1 { color: #4070a0 } /* Literal.String.Single */
|
||||
.highlight .ss { color: #517918 } /* Literal.String.Symbol */
|
||||
.highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */
|
||||
.highlight .vc { color: #bb60d5 } /* Name.Variable.Class */
|
||||
.highlight .vg { color: #bb60d5 } /* Name.Variable.Global */
|
||||
.highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */
|
||||
.highlight .il { color: #208050 } /* Literal.Number.Integer.Long */
|
|
@ -0,0 +1,651 @@
|
|||
/*
|
||||
* searchtools.js_t
|
||||
* ~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* Sphinx JavaScript utilities for the full-text search.
|
||||
*
|
||||
* :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
* :license: BSD, see LICENSE for details.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* Non-minified version JS is _stemmer.js if file is provided */
|
||||
/**
|
||||
* Porter Stemmer
|
||||
*/
|
||||
var Stemmer = function() {
|
||||
|
||||
var step2list = {
|
||||
ational: 'ate',
|
||||
tional: 'tion',
|
||||
enci: 'ence',
|
||||
anci: 'ance',
|
||||
izer: 'ize',
|
||||
bli: 'ble',
|
||||
alli: 'al',
|
||||
entli: 'ent',
|
||||
eli: 'e',
|
||||
ousli: 'ous',
|
||||
ization: 'ize',
|
||||
ation: 'ate',
|
||||
ator: 'ate',
|
||||
alism: 'al',
|
||||
iveness: 'ive',
|
||||
fulness: 'ful',
|
||||
ousness: 'ous',
|
||||
aliti: 'al',
|
||||
iviti: 'ive',
|
||||
biliti: 'ble',
|
||||
logi: 'log'
|
||||
};
|
||||
|
||||
var step3list = {
|
||||
icate: 'ic',
|
||||
ative: '',
|
||||
alize: 'al',
|
||||
iciti: 'ic',
|
||||
ical: 'ic',
|
||||
ful: '',
|
||||
ness: ''
|
||||
};
|
||||
|
||||
var c = "[^aeiou]"; // consonant
|
||||
var v = "[aeiouy]"; // vowel
|
||||
var C = c + "[^aeiouy]*"; // consonant sequence
|
||||
var V = v + "[aeiou]*"; // vowel sequence
|
||||
|
||||
var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0
|
||||
var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1
|
||||
var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1
|
||||
var s_v = "^(" + C + ")?" + v; // vowel in stem
|
||||
|
||||
this.stemWord = function (w) {
|
||||
var stem;
|
||||
var suffix;
|
||||
var firstch;
|
||||
var origword = w;
|
||||
|
||||
if (w.length < 3)
|
||||
return w;
|
||||
|
||||
var re;
|
||||
var re2;
|
||||
var re3;
|
||||
var re4;
|
||||
|
||||
firstch = w.substr(0,1);
|
||||
if (firstch == "y")
|
||||
w = firstch.toUpperCase() + w.substr(1);
|
||||
|
||||
// Step 1a
|
||||
re = /^(.+?)(ss|i)es$/;
|
||||
re2 = /^(.+?)([^s])s$/;
|
||||
|
||||
if (re.test(w))
|
||||
w = w.replace(re,"$1$2");
|
||||
else if (re2.test(w))
|
||||
w = w.replace(re2,"$1$2");
|
||||
|
||||
// Step 1b
|
||||
re = /^(.+?)eed$/;
|
||||
re2 = /^(.+?)(ed|ing)$/;
|
||||
if (re.test(w)) {
|
||||
var fp = re.exec(w);
|
||||
re = new RegExp(mgr0);
|
||||
if (re.test(fp[1])) {
|
||||
re = /.$/;
|
||||
w = w.replace(re,"");
|
||||
}
|
||||
}
|
||||
else if (re2.test(w)) {
|
||||
var fp = re2.exec(w);
|
||||
stem = fp[1];
|
||||
re2 = new RegExp(s_v);
|
||||
if (re2.test(stem)) {
|
||||
w = stem;
|
||||
re2 = /(at|bl|iz)$/;
|
||||
re3 = new RegExp("([^aeiouylsz])\\1$");
|
||||
re4 = new RegExp("^" + C + v + "[^aeiouwxy]$");
|
||||
if (re2.test(w))
|
||||
w = w + "e";
|
||||
else if (re3.test(w)) {
|
||||
re = /.$/;
|
||||
w = w.replace(re,"");
|
||||
}
|
||||
else if (re4.test(w))
|
||||
w = w + "e";
|
||||
}
|
||||
}
|
||||
|
||||
// Step 1c
|
||||
re = /^(.+?)y$/;
|
||||
if (re.test(w)) {
|
||||
var fp = re.exec(w);
|
||||
stem = fp[1];
|
||||
re = new RegExp(s_v);
|
||||
if (re.test(stem))
|
||||
w = stem + "i";
|
||||
}
|
||||
|
||||
// Step 2
|
||||
re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;
|
||||
if (re.test(w)) {
|
||||
var fp = re.exec(w);
|
||||
stem = fp[1];
|
||||
suffix = fp[2];
|
||||
re = new RegExp(mgr0);
|
||||
if (re.test(stem))
|
||||
w = stem + step2list[suffix];
|
||||
}
|
||||
|
||||
// Step 3
|
||||
re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
|
||||
if (re.test(w)) {
|
||||
var fp = re.exec(w);
|
||||
stem = fp[1];
|
||||
suffix = fp[2];
|
||||
re = new RegExp(mgr0);
|
||||
if (re.test(stem))
|
||||
w = stem + step3list[suffix];
|
||||
}
|
||||
|
||||
// Step 4
|
||||
re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
|
||||
re2 = /^(.+?)(s|t)(ion)$/;
|
||||
if (re.test(w)) {
|
||||
var fp = re.exec(w);
|
||||
stem = fp[1];
|
||||
re = new RegExp(mgr1);
|
||||
if (re.test(stem))
|
||||
w = stem;
|
||||
}
|
||||
else if (re2.test(w)) {
|
||||
var fp = re2.exec(w);
|
||||
stem = fp[1] + fp[2];
|
||||
re2 = new RegExp(mgr1);
|
||||
if (re2.test(stem))
|
||||
w = stem;
|
||||
}
|
||||
|
||||
// Step 5
|
||||
re = /^(.+?)e$/;
|
||||
if (re.test(w)) {
|
||||
var fp = re.exec(w);
|
||||
stem = fp[1];
|
||||
re = new RegExp(mgr1);
|
||||
re2 = new RegExp(meq1);
|
||||
re3 = new RegExp("^" + C + v + "[^aeiouwxy]$");
|
||||
if (re.test(stem) || (re2.test(stem) && !(re3.test(stem))))
|
||||
w = stem;
|
||||
}
|
||||
re = /ll$/;
|
||||
re2 = new RegExp(mgr1);
|
||||
if (re.test(w) && re2.test(w)) {
|
||||
re = /.$/;
|
||||
w = w.replace(re,"");
|
||||
}
|
||||
|
||||
// and turn initial Y back to y
|
||||
if (firstch == "y")
|
||||
w = firstch.toLowerCase() + w.substr(1);
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Simple result scoring code.
|
||||
*/
|
||||
var Scorer = {
|
||||
// Implement the following function to further tweak the score for each result
|
||||
// The function takes a result array [filename, title, anchor, descr, score]
|
||||
// and returns the new score.
|
||||
/*
|
||||
score: function(result) {
|
||||
return result[4];
|
||||
},
|
||||
*/
|
||||
|
||||
// query matches the full name of an object
|
||||
objNameMatch: 11,
|
||||
// or matches in the last dotted part of the object name
|
||||
objPartialMatch: 6,
|
||||
// Additive scores depending on the priority of the object
|
||||
objPrio: {0: 15, // used to be importantResults
|
||||
1: 5, // used to be objectResults
|
||||
2: -5}, // used to be unimportantResults
|
||||
// Used when the priority is not in the mapping.
|
||||
objPrioDefault: 0,
|
||||
|
||||
// query found in title
|
||||
title: 15,
|
||||
// query found in terms
|
||||
term: 5
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Search Module
|
||||
*/
|
||||
var Search = {
|
||||
|
||||
_index : null,
|
||||
_queued_query : null,
|
||||
_pulse_status : -1,
|
||||
|
||||
init : function() {
|
||||
var params = $.getQueryParameters();
|
||||
if (params.q) {
|
||||
var query = params.q[0];
|
||||
$('input[name="q"]')[0].value = query;
|
||||
this.performSearch(query);
|
||||
}
|
||||
},
|
||||
|
||||
loadIndex : function(url) {
|
||||
$.ajax({type: "GET", url: url, data: null,
|
||||
dataType: "script", cache: true,
|
||||
complete: function(jqxhr, textstatus) {
|
||||
if (textstatus != "success") {
|
||||
document.getElementById("searchindexloader").src = url;
|
||||
}
|
||||
}});
|
||||
},
|
||||
|
||||
setIndex : function(index) {
|
||||
var q;
|
||||
this._index = index;
|
||||
if ((q = this._queued_query) !== null) {
|
||||
this._queued_query = null;
|
||||
Search.query(q);
|
||||
}
|
||||
},
|
||||
|
||||
hasIndex : function() {
|
||||
return this._index !== null;
|
||||
},
|
||||
|
||||
deferQuery : function(query) {
|
||||
this._queued_query = query;
|
||||
},
|
||||
|
||||
stopPulse : function() {
|
||||
this._pulse_status = 0;
|
||||
},
|
||||
|
||||
startPulse : function() {
|
||||
if (this._pulse_status >= 0)
|
||||
return;
|
||||
function pulse() {
|
||||
var i;
|
||||
Search._pulse_status = (Search._pulse_status + 1) % 4;
|
||||
var dotString = '';
|
||||
for (i = 0; i < Search._pulse_status; i++)
|
||||
dotString += '.';
|
||||
Search.dots.text(dotString);
|
||||
if (Search._pulse_status > -1)
|
||||
window.setTimeout(pulse, 500);
|
||||
}
|
||||
pulse();
|
||||
},
|
||||
|
||||
/**
|
||||
* perform a search for something (or wait until index is loaded)
|
||||
*/
|
||||
performSearch : function(query) {
|
||||
// create the required interface elements
|
||||
this.out = $('#search-results');
|
||||
this.title = $('<h2>' + _('Searching') + '</h2>').appendTo(this.out);
|
||||
this.dots = $('<span></span>').appendTo(this.title);
|
||||
this.status = $('<p style="display: none"></p>').appendTo(this.out);
|
||||
this.output = $('<ul class="search"/>').appendTo(this.out);
|
||||
|
||||
$('#search-progress').text(_('Preparing search...'));
|
||||
this.startPulse();
|
||||
|
||||
// index already loaded, the browser was quick!
|
||||
if (this.hasIndex())
|
||||
this.query(query);
|
||||
else
|
||||
this.deferQuery(query);
|
||||
},
|
||||
|
||||
/**
|
||||
* execute search (requires search index to be loaded)
|
||||
*/
|
||||
query : function(query) {
|
||||
var i;
|
||||
var stopwords = ["a","and","are","as","at","be","but","by","for","if","in","into","is","it","near","no","not","of","on","or","such","that","the","their","then","there","these","they","this","to","was","will","with"];
|
||||
|
||||
// stem the searchterms and add them to the correct list
|
||||
var stemmer = new Stemmer();
|
||||
var searchterms = [];
|
||||
var excluded = [];
|
||||
var hlterms = [];
|
||||
var tmp = query.split(/\s+/);
|
||||
var objectterms = [];
|
||||
for (i = 0; i < tmp.length; i++) {
|
||||
if (tmp[i] !== "") {
|
||||
objectterms.push(tmp[i].toLowerCase());
|
||||
}
|
||||
|
||||
if ($u.indexOf(stopwords, tmp[i].toLowerCase()) != -1 || tmp[i].match(/^\d+$/) ||
|
||||
tmp[i] === "") {
|
||||
// skip this "word"
|
||||
continue;
|
||||
}
|
||||
// stem the word
|
||||
var word = stemmer.stemWord(tmp[i].toLowerCase());
|
||||
var toAppend;
|
||||
// select the correct list
|
||||
if (word[0] == '-') {
|
||||
toAppend = excluded;
|
||||
word = word.substr(1);
|
||||
}
|
||||
else {
|
||||
toAppend = searchterms;
|
||||
hlterms.push(tmp[i].toLowerCase());
|
||||
}
|
||||
// only add if not already in the list
|
||||
if (!$u.contains(toAppend, word))
|
||||
toAppend.push(word);
|
||||
}
|
||||
var highlightstring = '?highlight=' + $.urlencode(hlterms.join(" "));
|
||||
|
||||
// console.debug('SEARCH: searching for:');
|
||||
// console.info('required: ', searchterms);
|
||||
// console.info('excluded: ', excluded);
|
||||
|
||||
// prepare search
|
||||
var terms = this._index.terms;
|
||||
var titleterms = this._index.titleterms;
|
||||
|
||||
// array of [filename, title, anchor, descr, score]
|
||||
var results = [];
|
||||
$('#search-progress').empty();
|
||||
|
||||
// lookup as object
|
||||
for (i = 0; i < objectterms.length; i++) {
|
||||
var others = [].concat(objectterms.slice(0, i),
|
||||
objectterms.slice(i+1, objectterms.length));
|
||||
results = results.concat(this.performObjectSearch(objectterms[i], others));
|
||||
}
|
||||
|
||||
// lookup as search terms in fulltext
|
||||
results = results.concat(this.performTermsSearch(searchterms, excluded, terms, titleterms));
|
||||
|
||||
// let the scorer override scores with a custom scoring function
|
||||
if (Scorer.score) {
|
||||
for (i = 0; i < results.length; i++)
|
||||
results[i][4] = Scorer.score(results[i]);
|
||||
}
|
||||
|
||||
// now sort the results by score (in opposite order of appearance, since the
|
||||
// display function below uses pop() to retrieve items) and then
|
||||
// alphabetically
|
||||
results.sort(function(a, b) {
|
||||
var left = a[4];
|
||||
var right = b[4];
|
||||
if (left > right) {
|
||||
return 1;
|
||||
} else if (left < right) {
|
||||
return -1;
|
||||
} else {
|
||||
// same score: sort alphabetically
|
||||
left = a[1].toLowerCase();
|
||||
right = b[1].toLowerCase();
|
||||
return (left > right) ? -1 : ((left < right) ? 1 : 0);
|
||||
}
|
||||
});
|
||||
|
||||
// for debugging
|
||||
//Search.lastresults = results.slice(); // a copy
|
||||
//console.info('search results:', Search.lastresults);
|
||||
|
||||
// print the results
|
||||
var resultCount = results.length;
|
||||
function displayNextItem() {
|
||||
// results left, load the summary and display it
|
||||
if (results.length) {
|
||||
var item = results.pop();
|
||||
var listItem = $('<li style="display:none"></li>');
|
||||
if (DOCUMENTATION_OPTIONS.FILE_SUFFIX === '') {
|
||||
// dirhtml builder
|
||||
var dirname = item[0] + '/';
|
||||
if (dirname.match(/\/index\/$/)) {
|
||||
dirname = dirname.substring(0, dirname.length-6);
|
||||
} else if (dirname == 'index/') {
|
||||
dirname = '';
|
||||
}
|
||||
listItem.append($('<a/>').attr('href',
|
||||
DOCUMENTATION_OPTIONS.URL_ROOT + dirname +
|
||||
highlightstring + item[2]).html(item[1]));
|
||||
} else {
|
||||
// normal html builders
|
||||
listItem.append($('<a/>').attr('href',
|
||||
item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX +
|
||||
highlightstring + item[2]).html(item[1]));
|
||||
}
|
||||
if (item[3]) {
|
||||
listItem.append($('<span> (' + item[3] + ')</span>'));
|
||||
Search.output.append(listItem);
|
||||
listItem.slideDown(5, function() {
|
||||
displayNextItem();
|
||||
});
|
||||
} else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
|
||||
$.ajax({url: DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' + item[0] + '.txt',
|
||||
dataType: "text",
|
||||
complete: function(jqxhr, textstatus) {
|
||||
var data = jqxhr.responseText;
|
||||
if (data !== '' && data !== undefined) {
|
||||
listItem.append(Search.makeSearchSummary(data, searchterms, hlterms));
|
||||
}
|
||||
Search.output.append(listItem);
|
||||
listItem.slideDown(5, function() {
|
||||
displayNextItem();
|
||||
});
|
||||
}});
|
||||
} else {
|
||||
// no source available, just display title
|
||||
Search.output.append(listItem);
|
||||
listItem.slideDown(5, function() {
|
||||
displayNextItem();
|
||||
});
|
||||
}
|
||||
}
|
||||
// search finished, update title and status message
|
||||
else {
|
||||
Search.stopPulse();
|
||||
Search.title.text(_('Search Results'));
|
||||
if (!resultCount)
|
||||
Search.status.text(_('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.'));
|
||||
else
|
||||
Search.status.text(_('Search finished, found %s page(s) matching the search query.').replace('%s', resultCount));
|
||||
Search.status.fadeIn(500);
|
||||
}
|
||||
}
|
||||
displayNextItem();
|
||||
},
|
||||
|
||||
/**
|
||||
* search for object names
|
||||
*/
|
||||
performObjectSearch : function(object, otherterms) {
|
||||
var filenames = this._index.filenames;
|
||||
var objects = this._index.objects;
|
||||
var objnames = this._index.objnames;
|
||||
var titles = this._index.titles;
|
||||
|
||||
var i;
|
||||
var results = [];
|
||||
|
||||
for (var prefix in objects) {
|
||||
for (var name in objects[prefix]) {
|
||||
var fullname = (prefix ? prefix + '.' : '') + name;
|
||||
if (fullname.toLowerCase().indexOf(object) > -1) {
|
||||
var score = 0;
|
||||
var parts = fullname.split('.');
|
||||
// check for different match types: exact matches of full name or
|
||||
// "last name" (i.e. last dotted part)
|
||||
if (fullname == object || parts[parts.length - 1] == object) {
|
||||
score += Scorer.objNameMatch;
|
||||
// matches in last name
|
||||
} else if (parts[parts.length - 1].indexOf(object) > -1) {
|
||||
score += Scorer.objPartialMatch;
|
||||
}
|
||||
var match = objects[prefix][name];
|
||||
var objname = objnames[match[1]][2];
|
||||
var title = titles[match[0]];
|
||||
// If more than one term searched for, we require other words to be
|
||||
// found in the name/title/description
|
||||
if (otherterms.length > 0) {
|
||||
var haystack = (prefix + ' ' + name + ' ' +
|
||||
objname + ' ' + title).toLowerCase();
|
||||
var allfound = true;
|
||||
for (i = 0; i < otherterms.length; i++) {
|
||||
if (haystack.indexOf(otherterms[i]) == -1) {
|
||||
allfound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!allfound) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
var descr = objname + _(', in ') + title;
|
||||
|
||||
var anchor = match[3];
|
||||
if (anchor === '')
|
||||
anchor = fullname;
|
||||
else if (anchor == '-')
|
||||
anchor = objnames[match[1]][1] + '-' + fullname;
|
||||
// add custom score for some objects according to scorer
|
||||
if (Scorer.objPrio.hasOwnProperty(match[2])) {
|
||||
score += Scorer.objPrio[match[2]];
|
||||
} else {
|
||||
score += Scorer.objPrioDefault;
|
||||
}
|
||||
results.push([filenames[match[0]], fullname, '#'+anchor, descr, score]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
},
|
||||
|
||||
/**
|
||||
* search for full-text terms in the index
|
||||
*/
|
||||
performTermsSearch : function(searchterms, excluded, terms, titleterms) {
|
||||
var filenames = this._index.filenames;
|
||||
var titles = this._index.titles;
|
||||
|
||||
var i, j, file;
|
||||
var fileMap = {};
|
||||
var scoreMap = {};
|
||||
var results = [];
|
||||
|
||||
// perform the search on the required terms
|
||||
for (i = 0; i < searchterms.length; i++) {
|
||||
var word = searchterms[i];
|
||||
var files = [];
|
||||
var _o = [
|
||||
{files: terms[word], score: Scorer.term},
|
||||
{files: titleterms[word], score: Scorer.title}
|
||||
];
|
||||
|
||||
// no match but word was a required one
|
||||
if ($u.every(_o, function(o){return o.files === undefined;})) {
|
||||
break;
|
||||
}
|
||||
// found search word in contents
|
||||
$u.each(_o, function(o) {
|
||||
var _files = o.files;
|
||||
if (_files === undefined)
|
||||
return
|
||||
|
||||
if (_files.length === undefined)
|
||||
_files = [_files];
|
||||
files = files.concat(_files);
|
||||
|
||||
// set score for the word in each file to Scorer.term
|
||||
for (j = 0; j < _files.length; j++) {
|
||||
file = _files[j];
|
||||
if (!(file in scoreMap))
|
||||
scoreMap[file] = {}
|
||||
scoreMap[file][word] = o.score;
|
||||
}
|
||||
});
|
||||
|
||||
// create the mapping
|
||||
for (j = 0; j < files.length; j++) {
|
||||
file = files[j];
|
||||
if (file in fileMap)
|
||||
fileMap[file].push(word);
|
||||
else
|
||||
fileMap[file] = [word];
|
||||
}
|
||||
}
|
||||
|
||||
// now check if the files don't contain excluded terms
|
||||
for (file in fileMap) {
|
||||
var valid = true;
|
||||
|
||||
// check if all requirements are matched
|
||||
if (fileMap[file].length != searchterms.length)
|
||||
continue;
|
||||
|
||||
// ensure that none of the excluded terms is in the search result
|
||||
for (i = 0; i < excluded.length; i++) {
|
||||
if (terms[excluded[i]] == file ||
|
||||
titleterms[excluded[i]] == file ||
|
||||
$u.contains(terms[excluded[i]] || [], file) ||
|
||||
$u.contains(titleterms[excluded[i]] || [], file)) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we have still a valid result we can add it to the result list
|
||||
if (valid) {
|
||||
// select one (max) score for the file.
|
||||
// for better ranking, we should calculate ranking by using words statistics like basic tf-idf...
|
||||
var score = $u.max($u.map(fileMap[file], function(w){return scoreMap[file][w]}));
|
||||
results.push([filenames[file], titles[file], '', null, score]);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
},
|
||||
|
||||
/**
|
||||
* helper function to return a node containing the
|
||||
* search summary for a given text. keywords is a list
|
||||
* of stemmed words, hlwords is the list of normal, unstemmed
|
||||
* words. the first one is used to find the occurrence, the
|
||||
* latter for highlighting it.
|
||||
*/
|
||||
makeSearchSummary : function(text, keywords, hlwords) {
|
||||
var textLower = text.toLowerCase();
|
||||
var start = 0;
|
||||
$.each(keywords, function() {
|
||||
var i = textLower.indexOf(this.toLowerCase());
|
||||
if (i > -1)
|
||||
start = i;
|
||||
});
|
||||
start = Math.max(start - 120, 0);
|
||||
var excerpt = ((start > 0) ? '...' : '') +
|
||||
$.trim(text.substr(start, 240)) +
|
||||
((start + 240 - text.length) ? '...' : '');
|
||||
var rv = $('<div class="context"></div>').text(excerpt);
|
||||
$.each(hlwords, function() {
|
||||
rv = rv.highlightText(this, 'highlighted');
|
||||
});
|
||||
return rv;
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
Search.init();
|
||||
});
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* sidebar.js
|
||||
* ~~~~~~~~~~
|
||||
*
|
||||
* This script makes the Sphinx sidebar collapsible.
|
||||
*
|
||||
* .sphinxsidebar contains .sphinxsidebarwrapper. This script adds
|
||||
* in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton
|
||||
* used to collapse and expand the sidebar.
|
||||
*
|
||||
* When the sidebar is collapsed the .sphinxsidebarwrapper is hidden
|
||||
* and the width of the sidebar and the margin-left of the document
|
||||
* are decreased. When the sidebar is expanded the opposite happens.
|
||||
* This script saves a per-browser/per-session cookie used to
|
||||
* remember the position of the sidebar among the pages.
|
||||
* Once the browser is closed the cookie is deleted and the position
|
||||
* reset to the default (expanded).
|
||||
*
|
||||
* :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
* :license: BSD, see LICENSE for details.
|
||||
*
|
||||
*/
|
||||
|
||||
$(function() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// global elements used by the functions.
|
||||
// the 'sidebarbutton' element is defined as global after its
|
||||
// creation, in the add_sidebar_button function
|
||||
var bodywrapper = $('.bodywrapper');
|
||||
var sidebar = $('.sphinxsidebar');
|
||||
var sidebarwrapper = $('.sphinxsidebarwrapper');
|
||||
|
||||
// for some reason, the document has no sidebar; do not run into errors
|
||||
if (!sidebar.length) return;
|
||||
|
||||
// original margin-left of the bodywrapper and width of the sidebar
|
||||
// with the sidebar expanded
|
||||
var bw_margin_expanded = bodywrapper.css('margin-left');
|
||||
var ssb_width_expanded = sidebar.width();
|
||||
|
||||
// margin-left of the bodywrapper and width of the sidebar
|
||||
// with the sidebar collapsed
|
||||
var bw_margin_collapsed = '.8em';
|
||||
var ssb_width_collapsed = '.8em';
|
||||
|
||||
// colors used by the current theme
|
||||
var dark_color = $('.related').css('background-color');
|
||||
var light_color = $('.document').css('background-color');
|
||||
|
||||
function sidebar_is_collapsed() {
|
||||
return sidebarwrapper.is(':not(:visible)');
|
||||
}
|
||||
|
||||
function toggle_sidebar() {
|
||||
if (sidebar_is_collapsed())
|
||||
expand_sidebar();
|
||||
else
|
||||
collapse_sidebar();
|
||||
}
|
||||
|
||||
function collapse_sidebar() {
|
||||
sidebarwrapper.hide();
|
||||
sidebar.css('width', ssb_width_collapsed);
|
||||
bodywrapper.css('margin-left', bw_margin_collapsed);
|
||||
sidebarbutton.css({
|
||||
'margin-left': '0',
|
||||
'height': bodywrapper.height()
|
||||
});
|
||||
sidebarbutton.find('span').text('»');
|
||||
sidebarbutton.attr('title', _('Expand sidebar'));
|
||||
document.cookie = 'sidebar=collapsed';
|
||||
}
|
||||
|
||||
function expand_sidebar() {
|
||||
bodywrapper.css('margin-left', bw_margin_expanded);
|
||||
sidebar.css('width', ssb_width_expanded);
|
||||
sidebarwrapper.show();
|
||||
sidebarbutton.css({
|
||||
'margin-left': ssb_width_expanded-12,
|
||||
'height': bodywrapper.height()
|
||||
});
|
||||
sidebarbutton.find('span').text('«');
|
||||
sidebarbutton.attr('title', _('Collapse sidebar'));
|
||||
document.cookie = 'sidebar=expanded';
|
||||
}
|
||||
|
||||
function add_sidebar_button() {
|
||||
sidebarwrapper.css({
|
||||
'float': 'left',
|
||||
'margin-right': '0',
|
||||
'width': ssb_width_expanded - 28
|
||||
});
|
||||
// create the button
|
||||
sidebar.append(
|
||||
'<div id="sidebarbutton"><span>«</span></div>'
|
||||
);
|
||||
var sidebarbutton = $('#sidebarbutton');
|
||||
light_color = sidebarbutton.css('background-color');
|
||||
// find the height of the viewport to center the '<<' in the page
|
||||
var viewport_height;
|
||||
if (window.innerHeight)
|
||||
viewport_height = window.innerHeight;
|
||||
else
|
||||
viewport_height = $(window).height();
|
||||
sidebarbutton.find('span').css({
|
||||
'display': 'block',
|
||||
'margin-top': (viewport_height - sidebar.position().top - 20) / 2
|
||||
});
|
||||
|
||||
sidebarbutton.click(toggle_sidebar);
|
||||
sidebarbutton.attr('title', _('Collapse sidebar'));
|
||||
sidebarbutton.css({
|
||||
'color': '#FFFFFF',
|
||||
'border-left': '1px solid ' + dark_color,
|
||||
'font-size': '1.2em',
|
||||
'cursor': 'pointer',
|
||||
'height': bodywrapper.height(),
|
||||
'padding-top': '1px',
|
||||
'margin-left': ssb_width_expanded - 12
|
||||
});
|
||||
|
||||
sidebarbutton.hover(
|
||||
function () {
|
||||
$(this).css('background-color', dark_color);
|
||||
},
|
||||
function () {
|
||||
$(this).css('background-color', light_color);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function set_position_from_cookie() {
|
||||
if (!document.cookie)
|
||||
return;
|
||||
var items = document.cookie.split(';');
|
||||
for(var k=0; k<items.length; k++) {
|
||||
var key_val = items[k].split('=');
|
||||
var key = key_val[0].replace(/ /, ""); // strip leading spaces
|
||||
if (key == 'sidebar') {
|
||||
var value = key_val[1];
|
||||
if ((value == 'collapsed') && (!sidebar_is_collapsed()))
|
||||
collapse_sidebar();
|
||||
else if ((value == 'expanded') && (sidebar_is_collapsed()))
|
||||
expand_sidebar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_sidebar_button();
|
||||
var sidebarbutton = $('#sidebarbutton');
|
||||
set_position_from_cookie();
|
||||
});
|
|
@ -0,0 +1,999 @@
|
|||
// Underscore.js 1.3.1
|
||||
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
|
||||
// Underscore is freely distributable under the MIT license.
|
||||
// Portions of Underscore are inspired or borrowed from Prototype,
|
||||
// Oliver Steele's Functional, and John Resig's Micro-Templating.
|
||||
// For all details and documentation:
|
||||
// http://documentcloud.github.com/underscore
|
||||
|
||||
(function() {
|
||||
|
||||
// Baseline setup
|
||||
// --------------
|
||||
|
||||
// Establish the root object, `window` in the browser, or `global` on the server.
|
||||
var root = this;
|
||||
|
||||
// Save the previous value of the `_` variable.
|
||||
var previousUnderscore = root._;
|
||||
|
||||
// Establish the object that gets returned to break out of a loop iteration.
|
||||
var breaker = {};
|
||||
|
||||
// Save bytes in the minified (but not gzipped) version:
|
||||
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
|
||||
|
||||
// Create quick reference variables for speed access to core prototypes.
|
||||
var slice = ArrayProto.slice,
|
||||
unshift = ArrayProto.unshift,
|
||||
toString = ObjProto.toString,
|
||||
hasOwnProperty = ObjProto.hasOwnProperty;
|
||||
|
||||
// All **ECMAScript 5** native function implementations that we hope to use
|
||||
// are declared here.
|
||||
var
|
||||
nativeForEach = ArrayProto.forEach,
|
||||
nativeMap = ArrayProto.map,
|
||||
nativeReduce = ArrayProto.reduce,
|
||||
nativeReduceRight = ArrayProto.reduceRight,
|
||||
nativeFilter = ArrayProto.filter,
|
||||
nativeEvery = ArrayProto.every,
|
||||
nativeSome = ArrayProto.some,
|
||||
nativeIndexOf = ArrayProto.indexOf,
|
||||
nativeLastIndexOf = ArrayProto.lastIndexOf,
|
||||
nativeIsArray = Array.isArray,
|
||||
nativeKeys = Object.keys,
|
||||
nativeBind = FuncProto.bind;
|
||||
|
||||
// Create a safe reference to the Underscore object for use below.
|
||||
var _ = function(obj) { return new wrapper(obj); };
|
||||
|
||||
// Export the Underscore object for **Node.js**, with
|
||||
// backwards-compatibility for the old `require()` API. If we're in
|
||||
// the browser, add `_` as a global object via a string identifier,
|
||||
// for Closure Compiler "advanced" mode.
|
||||
if (typeof exports !== 'undefined') {
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
exports = module.exports = _;
|
||||
}
|
||||
exports._ = _;
|
||||
} else {
|
||||
root['_'] = _;
|
||||
}
|
||||
|
||||
// Current version.
|
||||
_.VERSION = '1.3.1';
|
||||
|
||||
// Collection Functions
|
||||
// --------------------
|
||||
|
||||
// The cornerstone, an `each` implementation, aka `forEach`.
|
||||
// Handles objects with the built-in `forEach`, arrays, and raw objects.
|
||||
// Delegates to **ECMAScript 5**'s native `forEach` if available.
|
||||
var each = _.each = _.forEach = function(obj, iterator, context) {
|
||||
if (obj == null) return;
|
||||
if (nativeForEach && obj.forEach === nativeForEach) {
|
||||
obj.forEach(iterator, context);
|
||||
} else if (obj.length === +obj.length) {
|
||||
for (var i = 0, l = obj.length; i < l; i++) {
|
||||
if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return;
|
||||
}
|
||||
} else {
|
||||
for (var key in obj) {
|
||||
if (_.has(obj, key)) {
|
||||
if (iterator.call(context, obj[key], key, obj) === breaker) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Return the results of applying the iterator to each element.
|
||||
// Delegates to **ECMAScript 5**'s native `map` if available.
|
||||
_.map = _.collect = function(obj, iterator, context) {
|
||||
var results = [];
|
||||
if (obj == null) return results;
|
||||
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
|
||||
each(obj, function(value, index, list) {
|
||||
results[results.length] = iterator.call(context, value, index, list);
|
||||
});
|
||||
if (obj.length === +obj.length) results.length = obj.length;
|
||||
return results;
|
||||
};
|
||||
|
||||
// **Reduce** builds up a single result from a list of values, aka `inject`,
|
||||
// or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
|
||||
_.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
|
||||
var initial = arguments.length > 2;
|
||||
if (obj == null) obj = [];
|
||||
if (nativeReduce && obj.reduce === nativeReduce) {
|
||||
if (context) iterator = _.bind(iterator, context);
|
||||
return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
|
||||
}
|
||||
each(obj, function(value, index, list) {
|
||||
if (!initial) {
|
||||
memo = value;
|
||||
initial = true;
|
||||
} else {
|
||||
memo = iterator.call(context, memo, value, index, list);
|
||||
}
|
||||
});
|
||||
if (!initial) throw new TypeError('Reduce of empty array with no initial value');
|
||||
return memo;
|
||||
};
|
||||
|
||||
// The right-associative version of reduce, also known as `foldr`.
|
||||
// Delegates to **ECMAScript 5**'s native `reduceRight` if available.
|
||||
_.reduceRight = _.foldr = function(obj, iterator, memo, context) {
|
||||
var initial = arguments.length > 2;
|
||||
if (obj == null) obj = [];
|
||||
if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
|
||||
if (context) iterator = _.bind(iterator, context);
|
||||
return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
|
||||
}
|
||||
var reversed = _.toArray(obj).reverse();
|
||||
if (context && !initial) iterator = _.bind(iterator, context);
|
||||
return initial ? _.reduce(reversed, iterator, memo, context) : _.reduce(reversed, iterator);
|
||||
};
|
||||
|
||||
// Return the first value which passes a truth test. Aliased as `detect`.
|
||||
_.find = _.detect = function(obj, iterator, context) {
|
||||
var result;
|
||||
any(obj, function(value, index, list) {
|
||||
if (iterator.call(context, value, index, list)) {
|
||||
result = value;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
// Return all the elements that pass a truth test.
|
||||
// Delegates to **ECMAScript 5**'s native `filter` if available.
|
||||
// Aliased as `select`.
|
||||
_.filter = _.select = function(obj, iterator, context) {
|
||||
var results = [];
|
||||
if (obj == null) return results;
|
||||
if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
|
||||
each(obj, function(value, index, list) {
|
||||
if (iterator.call(context, value, index, list)) results[results.length] = value;
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
||||
// Return all the elements for which a truth test fails.
|
||||
_.reject = function(obj, iterator, context) {
|
||||
var results = [];
|
||||
if (obj == null) return results;
|
||||
each(obj, function(value, index, list) {
|
||||
if (!iterator.call(context, value, index, list)) results[results.length] = value;
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
||||
// Determine whether all of the elements match a truth test.
|
||||
// Delegates to **ECMAScript 5**'s native `every` if available.
|
||||
// Aliased as `all`.
|
||||
_.every = _.all = function(obj, iterator, context) {
|
||||
var result = true;
|
||||
if (obj == null) return result;
|
||||
if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
|
||||
each(obj, function(value, index, list) {
|
||||
if (!(result = result && iterator.call(context, value, index, list))) return breaker;
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
// Determine if at least one element in the object matches a truth test.
|
||||
// Delegates to **ECMAScript 5**'s native `some` if available.
|
||||
// Aliased as `any`.
|
||||
var any = _.some = _.any = function(obj, iterator, context) {
|
||||
iterator || (iterator = _.identity);
|
||||
var result = false;
|
||||
if (obj == null) return result;
|
||||
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
|
||||
each(obj, function(value, index, list) {
|
||||
if (result || (result = iterator.call(context, value, index, list))) return breaker;
|
||||
});
|
||||
return !!result;
|
||||
};
|
||||
|
||||
// Determine if a given value is included in the array or object using `===`.
|
||||
// Aliased as `contains`.
|
||||
_.include = _.contains = function(obj, target) {
|
||||
var found = false;
|
||||
if (obj == null) return found;
|
||||
if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
|
||||
found = any(obj, function(value) {
|
||||
return value === target;
|
||||
});
|
||||
return found;
|
||||
};
|
||||
|
||||
// Invoke a method (with arguments) on every item in a collection.
|
||||
_.invoke = function(obj, method) {
|
||||
var args = slice.call(arguments, 2);
|
||||
return _.map(obj, function(value) {
|
||||
return (_.isFunction(method) ? method || value : value[method]).apply(value, args);
|
||||
});
|
||||
};
|
||||
|
||||
// Convenience version of a common use case of `map`: fetching a property.
|
||||
_.pluck = function(obj, key) {
|
||||
return _.map(obj, function(value){ return value[key]; });
|
||||
};
|
||||
|
||||
// Return the maximum element or (element-based computation).
|
||||
_.max = function(obj, iterator, context) {
|
||||
if (!iterator && _.isArray(obj)) return Math.max.apply(Math, obj);
|
||||
if (!iterator && _.isEmpty(obj)) return -Infinity;
|
||||
var result = {computed : -Infinity};
|
||||
each(obj, function(value, index, list) {
|
||||
var computed = iterator ? iterator.call(context, value, index, list) : value;
|
||||
computed >= result.computed && (result = {value : value, computed : computed});
|
||||
});
|
||||
return result.value;
|
||||
};
|
||||
|
||||
// Return the minimum element (or element-based computation).
|
||||
_.min = function(obj, iterator, context) {
|
||||
if (!iterator && _.isArray(obj)) return Math.min.apply(Math, obj);
|
||||
if (!iterator && _.isEmpty(obj)) return Infinity;
|
||||
var result = {computed : Infinity};
|
||||
each(obj, function(value, index, list) {
|
||||
var computed = iterator ? iterator.call(context, value, index, list) : value;
|
||||
computed < result.computed && (result = {value : value, computed : computed});
|
||||
});
|
||||
return result.value;
|
||||
};
|
||||
|
||||
// Shuffle an array.
|
||||
_.shuffle = function(obj) {
|
||||
var shuffled = [], rand;
|
||||
each(obj, function(value, index, list) {
|
||||
if (index == 0) {
|
||||
shuffled[0] = value;
|
||||
} else {
|
||||
rand = Math.floor(Math.random() * (index + 1));
|
||||
shuffled[index] = shuffled[rand];
|
||||
shuffled[rand] = value;
|
||||
}
|
||||
});
|
||||
return shuffled;
|
||||
};
|
||||
|
||||
// Sort the object's values by a criterion produced by an iterator.
|
||||
_.sortBy = function(obj, iterator, context) {
|
||||
return _.pluck(_.map(obj, function(value, index, list) {
|
||||
return {
|
||||
value : value,
|
||||
criteria : iterator.call(context, value, index, list)
|
||||
};
|
||||
}).sort(function(left, right) {
|
||||
var a = left.criteria, b = right.criteria;
|
||||
return a < b ? -1 : a > b ? 1 : 0;
|
||||
}), 'value');
|
||||
};
|
||||
|
||||
// Groups the object's values by a criterion. Pass either a string attribute
|
||||
// to group by, or a function that returns the criterion.
|
||||
_.groupBy = function(obj, val) {
|
||||
var result = {};
|
||||
var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; };
|
||||
each(obj, function(value, index) {
|
||||
var key = iterator(value, index);
|
||||
(result[key] || (result[key] = [])).push(value);
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
// Use a comparator function to figure out at what index an object should
|
||||
// be inserted so as to maintain order. Uses binary search.
|
||||
_.sortedIndex = function(array, obj, iterator) {
|
||||
iterator || (iterator = _.identity);
|
||||
var low = 0, high = array.length;
|
||||
while (low < high) {
|
||||
var mid = (low + high) >> 1;
|
||||
iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid;
|
||||
}
|
||||
return low;
|
||||
};
|
||||
|
||||
// Safely convert anything iterable into a real, live array.
|
||||
_.toArray = function(iterable) {
|
||||
if (!iterable) return [];
|
||||
if (iterable.toArray) return iterable.toArray();
|
||||
if (_.isArray(iterable)) return slice.call(iterable);
|
||||
if (_.isArguments(iterable)) return slice.call(iterable);
|
||||
return _.values(iterable);
|
||||
};
|
||||
|
||||
// Return the number of elements in an object.
|
||||
_.size = function(obj) {
|
||||
return _.toArray(obj).length;
|
||||
};
|
||||
|
||||
// Array Functions
|
||||
// ---------------
|
||||
|
||||
// Get the first element of an array. Passing **n** will return the first N
|
||||
// values in the array. Aliased as `head`. The **guard** check allows it to work
|
||||
// with `_.map`.
|
||||
_.first = _.head = function(array, n, guard) {
|
||||
return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
|
||||
};
|
||||
|
||||
// Returns everything but the last entry of the array. Especcialy useful on
|
||||
// the arguments object. Passing **n** will return all the values in
|
||||
// the array, excluding the last N. The **guard** check allows it to work with
|
||||
// `_.map`.
|
||||
_.initial = function(array, n, guard) {
|
||||
return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
|
||||
};
|
||||
|
||||
// Get the last element of an array. Passing **n** will return the last N
|
||||
// values in the array. The **guard** check allows it to work with `_.map`.
|
||||
_.last = function(array, n, guard) {
|
||||
if ((n != null) && !guard) {
|
||||
return slice.call(array, Math.max(array.length - n, 0));
|
||||
} else {
|
||||
return array[array.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
// Returns everything but the first entry of the array. Aliased as `tail`.
|
||||
// Especially useful on the arguments object. Passing an **index** will return
|
||||
// the rest of the values in the array from that index onward. The **guard**
|
||||
// check allows it to work with `_.map`.
|
||||
_.rest = _.tail = function(array, index, guard) {
|
||||
return slice.call(array, (index == null) || guard ? 1 : index);
|
||||
};
|
||||
|
||||
// Trim out all falsy values from an array.
|
||||
_.compact = function(array) {
|
||||
return _.filter(array, function(value){ return !!value; });
|
||||
};
|
||||
|
||||
// Return a completely flattened version of an array.
|
||||
_.flatten = function(array, shallow) {
|
||||
return _.reduce(array, function(memo, value) {
|
||||
if (_.isArray(value)) return memo.concat(shallow ? value : _.flatten(value));
|
||||
memo[memo.length] = value;
|
||||
return memo;
|
||||
}, []);
|
||||
};
|
||||
|
||||
// Return a version of the array that does not contain the specified value(s).
|
||||
_.without = function(array) {
|
||||
return _.difference(array, slice.call(arguments, 1));
|
||||
};
|
||||
|
||||
// Produce a duplicate-free version of the array. If the array has already
|
||||
// been sorted, you have the option of using a faster algorithm.
|
||||
// Aliased as `unique`.
|
||||
_.uniq = _.unique = function(array, isSorted, iterator) {
|
||||
var initial = iterator ? _.map(array, iterator) : array;
|
||||
var result = [];
|
||||
_.reduce(initial, function(memo, el, i) {
|
||||
if (0 == i || (isSorted === true ? _.last(memo) != el : !_.include(memo, el))) {
|
||||
memo[memo.length] = el;
|
||||
result[result.length] = array[i];
|
||||
}
|
||||
return memo;
|
||||
}, []);
|
||||
return result;
|
||||
};
|
||||
|
||||
// Produce an array that contains the union: each distinct element from all of
|
||||
// the passed-in arrays.
|
||||
_.union = function() {
|
||||
return _.uniq(_.flatten(arguments, true));
|
||||
};
|
||||
|
||||
// Produce an array that contains every item shared between all the
|
||||
// passed-in arrays. (Aliased as "intersect" for back-compat.)
|
||||
_.intersection = _.intersect = function(array) {
|
||||
var rest = slice.call(arguments, 1);
|
||||
return _.filter(_.uniq(array), function(item) {
|
||||
return _.every(rest, function(other) {
|
||||
return _.indexOf(other, item) >= 0;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Take the difference between one array and a number of other arrays.
|
||||
// Only the elements present in just the first array will remain.
|
||||
_.difference = function(array) {
|
||||
var rest = _.flatten(slice.call(arguments, 1));
|
||||
return _.filter(array, function(value){ return !_.include(rest, value); });
|
||||
};
|
||||
|
||||
// Zip together multiple lists into a single array -- elements that share
|
||||
// an index go together.
|
||||
_.zip = function() {
|
||||
var args = slice.call(arguments);
|
||||
var length = _.max(_.pluck(args, 'length'));
|
||||
var results = new Array(length);
|
||||
for (var i = 0; i < length; i++) results[i] = _.pluck(args, "" + i);
|
||||
return results;
|
||||
};
|
||||
|
||||
// If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
|
||||
// we need this function. Return the position of the first occurrence of an
|
||||
// item in an array, or -1 if the item is not included in the array.
|
||||
// Delegates to **ECMAScript 5**'s native `indexOf` if available.
|
||||
// If the array is large and already in sort order, pass `true`
|
||||
// for **isSorted** to use binary search.
|
||||
_.indexOf = function(array, item, isSorted) {
|
||||
if (array == null) return -1;
|
||||
var i, l;
|
||||
if (isSorted) {
|
||||
i = _.sortedIndex(array, item);
|
||||
return array[i] === item ? i : -1;
|
||||
}
|
||||
if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item);
|
||||
for (i = 0, l = array.length; i < l; i++) if (i in array && array[i] === item) return i;
|
||||
return -1;
|
||||
};
|
||||
|
||||
// Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
|
||||
_.lastIndexOf = function(array, item) {
|
||||
if (array == null) return -1;
|
||||
if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item);
|
||||
var i = array.length;
|
||||
while (i--) if (i in array && array[i] === item) return i;
|
||||
return -1;
|
||||
};
|
||||
|
||||
// Generate an integer Array containing an arithmetic progression. A port of
|
||||
// the native Python `range()` function. See
|
||||
// [the Python documentation](http://docs.python.org/library/functions.html#range).
|
||||
_.range = function(start, stop, step) {
|
||||
if (arguments.length <= 1) {
|
||||
stop = start || 0;
|
||||
start = 0;
|
||||
}
|
||||
step = arguments[2] || 1;
|
||||
|
||||
var len = Math.max(Math.ceil((stop - start) / step), 0);
|
||||
var idx = 0;
|
||||
var range = new Array(len);
|
||||
|
||||
while(idx < len) {
|
||||
range[idx++] = start;
|
||||
start += step;
|
||||
}
|
||||
|
||||
return range;
|
||||
};
|
||||
|
||||
// Function (ahem) Functions
|
||||
// ------------------
|
||||
|
||||
// Reusable constructor function for prototype setting.
|
||||
var ctor = function(){};
|
||||
|
||||
// Create a function bound to a given object (assigning `this`, and arguments,
|
||||
// optionally). Binding with arguments is also known as `curry`.
|
||||
// Delegates to **ECMAScript 5**'s native `Function.bind` if available.
|
||||
// We check for `func.bind` first, to fail fast when `func` is undefined.
|
||||
_.bind = function bind(func, context) {
|
||||
var bound, args;
|
||||
if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
|
||||
if (!_.isFunction(func)) throw new TypeError;
|
||||
args = slice.call(arguments, 2);
|
||||
return bound = function() {
|
||||
if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
|
||||
ctor.prototype = func.prototype;
|
||||
var self = new ctor;
|
||||
var result = func.apply(self, args.concat(slice.call(arguments)));
|
||||
if (Object(result) === result) return result;
|
||||
return self;
|
||||
};
|
||||
};
|
||||
|
||||
// Bind all of an object's methods to that object. Useful for ensuring that
|
||||
// all callbacks defined on an object belong to it.
|
||||
_.bindAll = function(obj) {
|
||||
var funcs = slice.call(arguments, 1);
|
||||
if (funcs.length == 0) funcs = _.functions(obj);
|
||||
each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
|
||||
return obj;
|
||||
};
|
||||
|
||||
// Memoize an expensive function by storing its results.
|
||||
_.memoize = function(func, hasher) {
|
||||
var memo = {};
|
||||
hasher || (hasher = _.identity);
|
||||
return function() {
|
||||
var key = hasher.apply(this, arguments);
|
||||
return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
|
||||
};
|
||||
};
|
||||
|
||||
// Delays a function for the given number of milliseconds, and then calls
|
||||
// it with the arguments supplied.
|
||||
_.delay = function(func, wait) {
|
||||
var args = slice.call(arguments, 2);
|
||||
return setTimeout(function(){ return func.apply(func, args); }, wait);
|
||||
};
|
||||
|
||||
// Defers a function, scheduling it to run after the current call stack has
|
||||
// cleared.
|
||||
_.defer = function(func) {
|
||||
return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
|
||||
};
|
||||
|
||||
// Returns a function, that, when invoked, will only be triggered at most once
|
||||
// during a given window of time.
|
||||
_.throttle = function(func, wait) {
|
||||
var context, args, timeout, throttling, more;
|
||||
var whenDone = _.debounce(function(){ more = throttling = false; }, wait);
|
||||
return function() {
|
||||
context = this; args = arguments;
|
||||
var later = function() {
|
||||
timeout = null;
|
||||
if (more) func.apply(context, args);
|
||||
whenDone();
|
||||
};
|
||||
if (!timeout) timeout = setTimeout(later, wait);
|
||||
if (throttling) {
|
||||
more = true;
|
||||
} else {
|
||||
func.apply(context, args);
|
||||
}
|
||||
whenDone();
|
||||
throttling = true;
|
||||
};
|
||||
};
|
||||
|
||||
// Returns a function, that, as long as it continues to be invoked, will not
|
||||
// be triggered. The function will be called after it stops being called for
|
||||
// N milliseconds.
|
||||
_.debounce = function(func, wait) {
|
||||
var timeout;
|
||||
return function() {
|
||||
var context = this, args = arguments;
|
||||
var later = function() {
|
||||
timeout = null;
|
||||
func.apply(context, args);
|
||||
};
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
};
|
||||
};
|
||||
|
||||
// Returns a function that will be executed at most one time, no matter how
|
||||
// often you call it. Useful for lazy initialization.
|
||||
_.once = function(func) {
|
||||
var ran = false, memo;
|
||||
return function() {
|
||||
if (ran) return memo;
|
||||
ran = true;
|
||||
return memo = func.apply(this, arguments);
|
||||
};
|
||||
};
|
||||
|
||||
// Returns the first function passed as an argument to the second,
|
||||
// allowing you to adjust arguments, run code before and after, and
|
||||
// conditionally execute the original function.
|
||||
_.wrap = function(func, wrapper) {
|
||||
return function() {
|
||||
var args = [func].concat(slice.call(arguments, 0));
|
||||
return wrapper.apply(this, args);
|
||||
};
|
||||
};
|
||||
|
||||
// Returns a function that is the composition of a list of functions, each
|
||||
// consuming the return value of the function that follows.
|
||||
_.compose = function() {
|
||||
var funcs = arguments;
|
||||
return function() {
|
||||
var args = arguments;
|
||||
for (var i = funcs.length - 1; i >= 0; i--) {
|
||||
args = [funcs[i].apply(this, args)];
|
||||
}
|
||||
return args[0];
|
||||
};
|
||||
};
|
||||
|
||||
// Returns a function that will only be executed after being called N times.
|
||||
_.after = function(times, func) {
|
||||
if (times <= 0) return func();
|
||||
return function() {
|
||||
if (--times < 1) { return func.apply(this, arguments); }
|
||||
};
|
||||
};
|
||||
|
||||
// Object Functions
|
||||
// ----------------
|
||||
|
||||
// Retrieve the names of an object's properties.
|
||||
// Delegates to **ECMAScript 5**'s native `Object.keys`
|
||||
_.keys = nativeKeys || function(obj) {
|
||||
if (obj !== Object(obj)) throw new TypeError('Invalid object');
|
||||
var keys = [];
|
||||
for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
|
||||
return keys;
|
||||
};
|
||||
|
||||
// Retrieve the values of an object's properties.
|
||||
_.values = function(obj) {
|
||||
return _.map(obj, _.identity);
|
||||
};
|
||||
|
||||
// Return a sorted list of the function names available on the object.
|
||||
// Aliased as `methods`
|
||||
_.functions = _.methods = function(obj) {
|
||||
var names = [];
|
||||
for (var key in obj) {
|
||||
if (_.isFunction(obj[key])) names.push(key);
|
||||
}
|
||||
return names.sort();
|
||||
};
|
||||
|
||||
// Extend a given object with all the properties in passed-in object(s).
|
||||
_.extend = function(obj) {
|
||||
each(slice.call(arguments, 1), function(source) {
|
||||
for (var prop in source) {
|
||||
obj[prop] = source[prop];
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
};
|
||||
|
||||
// Fill in a given object with default properties.
|
||||
_.defaults = function(obj) {
|
||||
each(slice.call(arguments, 1), function(source) {
|
||||
for (var prop in source) {
|
||||
if (obj[prop] == null) obj[prop] = source[prop];
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
};
|
||||
|
||||
// Create a (shallow-cloned) duplicate of an object.
|
||||
_.clone = function(obj) {
|
||||
if (!_.isObject(obj)) return obj;
|
||||
return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
|
||||
};
|
||||
|
||||
// Invokes interceptor with the obj, and then returns obj.
|
||||
// The primary purpose of this method is to "tap into" a method chain, in
|
||||
// order to perform operations on intermediate results within the chain.
|
||||
_.tap = function(obj, interceptor) {
|
||||
interceptor(obj);
|
||||
return obj;
|
||||
};
|
||||
|
||||
// Internal recursive comparison function.
|
||||
function eq(a, b, stack) {
|
||||
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
||||
// See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
|
||||
if (a === b) return a !== 0 || 1 / a == 1 / b;
|
||||
// A strict comparison is necessary because `null == undefined`.
|
||||
if (a == null || b == null) return a === b;
|
||||
// Unwrap any wrapped objects.
|
||||
if (a._chain) a = a._wrapped;
|
||||
if (b._chain) b = b._wrapped;
|
||||
// Invoke a custom `isEqual` method if one is provided.
|
||||
if (a.isEqual && _.isFunction(a.isEqual)) return a.isEqual(b);
|
||||
if (b.isEqual && _.isFunction(b.isEqual)) return b.isEqual(a);
|
||||
// Compare `[[Class]]` names.
|
||||
var className = toString.call(a);
|
||||
if (className != toString.call(b)) return false;
|
||||
switch (className) {
|
||||
// Strings, numbers, dates, and booleans are compared by value.
|
||||
case '[object String]':
|
||||
// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
|
||||
// equivalent to `new String("5")`.
|
||||
return a == String(b);
|
||||
case '[object Number]':
|
||||
// `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
|
||||
// other numeric values.
|
||||
return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
|
||||
case '[object Date]':
|
||||
case '[object Boolean]':
|
||||
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
|
||||
// millisecond representations. Note that invalid dates with millisecond representations
|
||||
// of `NaN` are not equivalent.
|
||||
return +a == +b;
|
||||
// RegExps are compared by their source patterns and flags.
|
||||
case '[object RegExp]':
|
||||
return a.source == b.source &&
|
||||
a.global == b.global &&
|
||||
a.multiline == b.multiline &&
|
||||
a.ignoreCase == b.ignoreCase;
|
||||
}
|
||||
if (typeof a != 'object' || typeof b != 'object') return false;
|
||||
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
||||
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
||||
var length = stack.length;
|
||||
while (length--) {
|
||||
// Linear search. Performance is inversely proportional to the number of
|
||||
// unique nested structures.
|
||||
if (stack[length] == a) return true;
|
||||
}
|
||||
// Add the first object to the stack of traversed objects.
|
||||
stack.push(a);
|
||||
var size = 0, result = true;
|
||||
// Recursively compare objects and arrays.
|
||||
if (className == '[object Array]') {
|
||||
// Compare array lengths to determine if a deep comparison is necessary.
|
||||
size = a.length;
|
||||
result = size == b.length;
|
||||
if (result) {
|
||||
// Deep compare the contents, ignoring non-numeric properties.
|
||||
while (size--) {
|
||||
// Ensure commutative equality for sparse arrays.
|
||||
if (!(result = size in a == size in b && eq(a[size], b[size], stack))) break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Objects with different constructors are not equivalent.
|
||||
if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false;
|
||||
// Deep compare objects.
|
||||
for (var key in a) {
|
||||
if (_.has(a, key)) {
|
||||
// Count the expected number of properties.
|
||||
size++;
|
||||
// Deep compare each member.
|
||||
if (!(result = _.has(b, key) && eq(a[key], b[key], stack))) break;
|
||||
}
|
||||
}
|
||||
// Ensure that both objects contain the same number of properties.
|
||||
if (result) {
|
||||
for (key in b) {
|
||||
if (_.has(b, key) && !(size--)) break;
|
||||
}
|
||||
result = !size;
|
||||
}
|
||||
}
|
||||
// Remove the first object from the stack of traversed objects.
|
||||
stack.pop();
|
||||
return result;
|
||||
}
|
||||
|
||||
// Perform a deep comparison to check if two objects are equal.
|
||||
_.isEqual = function(a, b) {
|
||||
return eq(a, b, []);
|
||||
};
|
||||
|
||||
// Is a given array, string, or object empty?
|
||||
// An "empty" object has no enumerable own-properties.
|
||||
_.isEmpty = function(obj) {
|
||||
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
|
||||
for (var key in obj) if (_.has(obj, key)) return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
// Is a given value a DOM element?
|
||||
_.isElement = function(obj) {
|
||||
return !!(obj && obj.nodeType == 1);
|
||||
};
|
||||
|
||||
// Is a given value an array?
|
||||
// Delegates to ECMA5's native Array.isArray
|
||||
_.isArray = nativeIsArray || function(obj) {
|
||||
return toString.call(obj) == '[object Array]';
|
||||
};
|
||||
|
||||
// Is a given variable an object?
|
||||
_.isObject = function(obj) {
|
||||
return obj === Object(obj);
|
||||
};
|
||||
|
||||
// Is a given variable an arguments object?
|
||||
_.isArguments = function(obj) {
|
||||
return toString.call(obj) == '[object Arguments]';
|
||||
};
|
||||
if (!_.isArguments(arguments)) {
|
||||
_.isArguments = function(obj) {
|
||||
return !!(obj && _.has(obj, 'callee'));
|
||||
};
|
||||
}
|
||||
|
||||
// Is a given value a function?
|
||||
_.isFunction = function(obj) {
|
||||
return toString.call(obj) == '[object Function]';
|
||||
};
|
||||
|
||||
// Is a given value a string?
|
||||
_.isString = function(obj) {
|
||||
return toString.call(obj) == '[object String]';
|
||||
};
|
||||
|
||||
// Is a given value a number?
|
||||
_.isNumber = function(obj) {
|
||||
return toString.call(obj) == '[object Number]';
|
||||
};
|
||||
|
||||
// Is the given value `NaN`?
|
||||
_.isNaN = function(obj) {
|
||||
// `NaN` is the only value for which `===` is not reflexive.
|
||||
return obj !== obj;
|
||||
};
|
||||
|
||||
// Is a given value a boolean?
|
||||
_.isBoolean = function(obj) {
|
||||
return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
|
||||
};
|
||||
|
||||
// Is a given value a date?
|
||||
_.isDate = function(obj) {
|
||||
return toString.call(obj) == '[object Date]';
|
||||
};
|
||||
|
||||
// Is the given value a regular expression?
|
||||
_.isRegExp = function(obj) {
|
||||
return toString.call(obj) == '[object RegExp]';
|
||||
};
|
||||
|
||||
// Is a given value equal to null?
|
||||
_.isNull = function(obj) {
|
||||
return obj === null;
|
||||
};
|
||||
|
||||
// Is a given variable undefined?
|
||||
_.isUndefined = function(obj) {
|
||||
return obj === void 0;
|
||||
};
|
||||
|
||||
// Has own property?
|
||||
_.has = function(obj, key) {
|
||||
return hasOwnProperty.call(obj, key);
|
||||
};
|
||||
|
||||
// Utility Functions
|
||||
// -----------------
|
||||
|
||||
// Run Underscore.js in *noConflict* mode, returning the `_` variable to its
|
||||
// previous owner. Returns a reference to the Underscore object.
|
||||
_.noConflict = function() {
|
||||
root._ = previousUnderscore;
|
||||
return this;
|
||||
};
|
||||
|
||||
// Keep the identity function around for default iterators.
|
||||
_.identity = function(value) {
|
||||
return value;
|
||||
};
|
||||
|
||||
// Run a function **n** times.
|
||||
_.times = function (n, iterator, context) {
|
||||
for (var i = 0; i < n; i++) iterator.call(context, i);
|
||||
};
|
||||
|
||||
// Escape a string for HTML interpolation.
|
||||
_.escape = function(string) {
|
||||
return (''+string).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/');
|
||||
};
|
||||
|
||||
// Add your own custom functions to the Underscore object, ensuring that
|
||||
// they're correctly added to the OOP wrapper as well.
|
||||
_.mixin = function(obj) {
|
||||
each(_.functions(obj), function(name){
|
||||
addToWrapper(name, _[name] = obj[name]);
|
||||
});
|
||||
};
|
||||
|
||||
// Generate a unique integer id (unique within the entire client session).
|
||||
// Useful for temporary DOM ids.
|
||||
var idCounter = 0;
|
||||
_.uniqueId = function(prefix) {
|
||||
var id = idCounter++;
|
||||
return prefix ? prefix + id : id;
|
||||
};
|
||||
|
||||
// By default, Underscore uses ERB-style template delimiters, change the
|
||||
// following template settings to use alternative delimiters.
|
||||
_.templateSettings = {
|
||||
evaluate : /<%([\s\S]+?)%>/g,
|
||||
interpolate : /<%=([\s\S]+?)%>/g,
|
||||
escape : /<%-([\s\S]+?)%>/g
|
||||
};
|
||||
|
||||
// When customizing `templateSettings`, if you don't want to define an
|
||||
// interpolation, evaluation or escaping regex, we need one that is
|
||||
// guaranteed not to match.
|
||||
var noMatch = /.^/;
|
||||
|
||||
// Within an interpolation, evaluation, or escaping, remove HTML escaping
|
||||
// that had been previously added.
|
||||
var unescape = function(code) {
|
||||
return code.replace(/\\\\/g, '\\').replace(/\\'/g, "'");
|
||||
};
|
||||
|
||||
// JavaScript micro-templating, similar to John Resig's implementation.
|
||||
// Underscore templating handles arbitrary delimiters, preserves whitespace,
|
||||
// and correctly escapes quotes within interpolated code.
|
||||
_.template = function(str, data) {
|
||||
var c = _.templateSettings;
|
||||
var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' +
|
||||
'with(obj||{}){__p.push(\'' +
|
||||
str.replace(/\\/g, '\\\\')
|
||||
.replace(/'/g, "\\'")
|
||||
.replace(c.escape || noMatch, function(match, code) {
|
||||
return "',_.escape(" + unescape(code) + "),'";
|
||||
})
|
||||
.replace(c.interpolate || noMatch, function(match, code) {
|
||||
return "'," + unescape(code) + ",'";
|
||||
})
|
||||
.replace(c.evaluate || noMatch, function(match, code) {
|
||||
return "');" + unescape(code).replace(/[\r\n\t]/g, ' ') + ";__p.push('";
|
||||
})
|
||||
.replace(/\r/g, '\\r')
|
||||
.replace(/\n/g, '\\n')
|
||||
.replace(/\t/g, '\\t')
|
||||
+ "');}return __p.join('');";
|
||||
var func = new Function('obj', '_', tmpl);
|
||||
if (data) return func(data, _);
|
||||
return function(data) {
|
||||
return func.call(this, data, _);
|
||||
};
|
||||
};
|
||||
|
||||
// Add a "chain" function, which will delegate to the wrapper.
|
||||
_.chain = function(obj) {
|
||||
return _(obj).chain();
|
||||
};
|
||||
|
||||
// The OOP Wrapper
|
||||
// ---------------
|
||||
|
||||
// If Underscore is called as a function, it returns a wrapped object that
|
||||
// can be used OO-style. This wrapper holds altered versions of all the
|
||||
// underscore functions. Wrapped objects may be chained.
|
||||
var wrapper = function(obj) { this._wrapped = obj; };
|
||||
|
||||
// Expose `wrapper.prototype` as `_.prototype`
|
||||
_.prototype = wrapper.prototype;
|
||||
|
||||
// Helper function to continue chaining intermediate results.
|
||||
var result = function(obj, chain) {
|
||||
return chain ? _(obj).chain() : obj;
|
||||
};
|
||||
|
||||
// A method to easily add functions to the OOP wrapper.
|
||||
var addToWrapper = function(name, func) {
|
||||
wrapper.prototype[name] = function() {
|
||||
var args = slice.call(arguments);
|
||||
unshift.call(args, this._wrapped);
|
||||
return result(func.apply(_, args), this._chain);
|
||||
};
|
||||
};
|
||||
|
||||
// Add all of the Underscore functions to the wrapper object.
|
||||
_.mixin(_);
|
||||
|
||||
// Add all mutator Array functions to the wrapper.
|
||||
each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
|
||||
var method = ArrayProto[name];
|
||||
wrapper.prototype[name] = function() {
|
||||
var wrapped = this._wrapped;
|
||||
method.apply(wrapped, arguments);
|
||||
var length = wrapped.length;
|
||||
if ((name == 'shift' || name == 'splice') && length === 0) delete wrapped[0];
|
||||
return result(wrapped, this._chain);
|
||||
};
|
||||
});
|
||||
|
||||
// Add all accessor Array functions to the wrapper.
|
||||
each(['concat', 'join', 'slice'], function(name) {
|
||||
var method = ArrayProto[name];
|
||||
wrapper.prototype[name] = function() {
|
||||
return result(method.apply(this._wrapped, arguments), this._chain);
|
||||
};
|
||||
});
|
||||
|
||||
// Start chaining a wrapped Underscore object.
|
||||
wrapper.prototype.chain = function() {
|
||||
this._chain = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
// Extracts the result from a wrapped and chained object.
|
||||
wrapper.prototype.value = function() {
|
||||
return this._wrapped;
|
||||
};
|
||||
|
||||
}).call(this);
|
|
@ -0,0 +1,31 @@
|
|||
// Underscore.js 1.3.1
|
||||
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
|
||||
// Underscore is freely distributable under the MIT license.
|
||||
// Portions of Underscore are inspired or borrowed from Prototype,
|
||||
// Oliver Steele's Functional, and John Resig's Micro-Templating.
|
||||
// For all details and documentation:
|
||||
// http://documentcloud.github.com/underscore
|
||||
(function(){function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==
|
||||
c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&q(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&q(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c,
|
||||
h)&&!f--)break;g=!f}}d.pop();return g}var r=this,G=r._,n={},k=Array.prototype,o=Object.prototype,i=k.slice,H=k.unshift,l=o.toString,I=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,p=k.indexOf,D=k.lastIndexOf,o=Array.isArray,J=Object.keys,s=Function.prototype.bind,b=function(a){return new m(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else r._=b;b.VERSION="1.3.1";var j=b.each=
|
||||
b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e<f;e++){if(e in a&&c.call(d,a[e],e,a)===n)break}else for(e in a)if(b.has(a,e)&&c.call(d,a[e],e,a)===n)break};b.map=b.collect=function(a,c,b){var e=[];if(a==null)return e;if(x&&a.map===x)return a.map(c,b);j(a,function(a,g,h){e[e.length]=c.call(b,a,g,h)});if(a.length===+a.length)e.length=a.length;return e};b.reduce=b.foldl=b.inject=function(a,c,d,e){var f=arguments.length>2;a==
|
||||
null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect=
|
||||
function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e=
|
||||
e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck=
|
||||
function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b<e.computed&&(e={value:a,computed:b})});
|
||||
return e.value};b.shuffle=function(a){var b=[],d;j(a,function(a,f){f==0?b[0]=a:(d=Math.floor(Math.random()*(f+1)),b[f]=b[d],b[d]=a)});return b};b.sortBy=function(a,c,d){return b.pluck(b.map(a,function(a,b,g){return{value:a,criteria:c.call(d,a,b,g)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a,
|
||||
c,d){d||(d=b.identity);for(var e=0,f=a.length;e<f;){var g=e+f>>1;d(a[g])<d(c)?e=g+1:f=g}return e};b.toArray=function(a){return!a?[]:a.toArray?a.toArray():b.isArray(a)?i.call(a):b.isArguments(a)?i.call(a):b.values(a)};b.size=function(a){return b.toArray(a).length};b.first=b.head=function(a,b,d){return b!=null&&!d?i.call(a,0,b):a[0]};b.initial=function(a,b,d){return i.call(a,0,a.length-(b==null||d?1:b))};b.last=function(a,b,d){return b!=null&&!d?i.call(a,Math.max(a.length-b,0)):a[a.length-1]};b.rest=
|
||||
b.tail=function(a,b,d){return i.call(a,b==null||d?1:b)};b.compact=function(a){return b.filter(a,function(a){return!!a})};b.flatten=function(a,c){return b.reduce(a,function(a,e){if(b.isArray(e))return a.concat(c?e:b.flatten(e));a[a.length]=e;return a},[])};b.without=function(a){return b.difference(a,i.call(arguments,1))};b.uniq=b.unique=function(a,c,d){var d=d?b.map(a,d):a,e=[];b.reduce(d,function(d,g,h){if(0==h||(c===true?b.last(d)!=g:!b.include(d,g)))d[d.length]=g,e[e.length]=a[h];return d},[]);
|
||||
return e};b.union=function(){return b.uniq(b.flatten(arguments,true))};b.intersection=b.intersect=function(a){var c=i.call(arguments,1);return b.filter(b.uniq(a),function(a){return b.every(c,function(c){return b.indexOf(c,a)>=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e<c;e++)d[e]=b.pluck(a,""+e);return d};b.indexOf=function(a,c,
|
||||
d){if(a==null)return-1;var e;if(d)return d=b.sortedIndex(a,c),a[d]===c?d:-1;if(p&&a.indexOf===p)return a.indexOf(c);for(d=0,e=a.length;d<e;d++)if(d in a&&a[d]===c)return d;return-1};b.lastIndexOf=function(a,b){if(a==null)return-1;if(D&&a.lastIndexOf===D)return a.lastIndexOf(b);for(var d=a.length;d--;)if(d in a&&a[d]===b)return d;return-1};b.range=function(a,b,d){arguments.length<=1&&(b=a||0,a=0);for(var d=arguments[2]||1,e=Math.max(Math.ceil((b-a)/d),0),f=0,g=Array(e);f<e;)g[f++]=a,a+=d;return g};
|
||||
var F=function(){};b.bind=function(a,c){var d,e;if(a.bind===s&&s)return s.apply(a,i.call(arguments,1));if(!b.isFunction(a))throw new TypeError;e=i.call(arguments,2);return d=function(){if(!(this instanceof d))return a.apply(c,e.concat(i.call(arguments)));F.prototype=a.prototype;var b=new F,g=a.apply(b,e.concat(i.call(arguments)));return Object(g)===g?g:b}};b.bindAll=function(a){var c=i.call(arguments,1);c.length==0&&(c=b.functions(a));j(c,function(c){a[c]=b.bind(a[c],a)});return a};b.memoize=function(a,
|
||||
c){var d={};c||(c=b.identity);return function(){var e=c.apply(this,arguments);return b.has(d,e)?d[e]:d[e]=a.apply(this,arguments)}};b.delay=function(a,b){var d=i.call(arguments,2);return setTimeout(function(){return a.apply(a,d)},b)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(i.call(arguments,1)))};b.throttle=function(a,c){var d,e,f,g,h,i=b.debounce(function(){h=g=false},c);return function(){d=this;e=arguments;var b;f||(f=setTimeout(function(){f=null;h&&a.apply(d,e);i()},c));g?h=true:
|
||||
a.apply(d,e);i();g=true}};b.debounce=function(a,b){var d;return function(){var e=this,f=arguments;clearTimeout(d);d=setTimeout(function(){d=null;a.apply(e,f)},b)}};b.once=function(a){var b=false,d;return function(){if(b)return d;b=true;return d=a.apply(this,arguments)}};b.wrap=function(a,b){return function(){var d=[a].concat(i.call(arguments,0));return b.apply(this,d)}};b.compose=function(){var a=arguments;return function(){for(var b=arguments,d=a.length-1;d>=0;d--)b=[a[d].apply(this,b)];return b[0]}};
|
||||
b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments,
|
||||
1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};
|
||||
b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"};
|
||||
b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e<a;e++)b.call(d,e)};b.escape=function(a){return(""+a).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a),
|
||||
function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+
|
||||
u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]=
|
||||
function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain=
|
||||
true;return this};m.prototype.value=function(){return this._wrapped}}).call(this);
|
After Width: | Height: | Size: 345 B |
After Width: | Height: | Size: 345 B |
|
@ -0,0 +1,808 @@
|
|||
/*
|
||||
* websupport.js
|
||||
* ~~~~~~~~~~~~~
|
||||
*
|
||||
* sphinx.websupport utilities for all documentation.
|
||||
*
|
||||
* :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
* :license: BSD, see LICENSE for details.
|
||||
*
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
$.fn.autogrow = function() {
|
||||
return this.each(function() {
|
||||
var textarea = this;
|
||||
|
||||
$.fn.autogrow.resize(textarea);
|
||||
|
||||
$(textarea)
|
||||
.focus(function() {
|
||||
textarea.interval = setInterval(function() {
|
||||
$.fn.autogrow.resize(textarea);
|
||||
}, 500);
|
||||
})
|
||||
.blur(function() {
|
||||
clearInterval(textarea.interval);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$.fn.autogrow.resize = function(textarea) {
|
||||
var lineHeight = parseInt($(textarea).css('line-height'), 10);
|
||||
var lines = textarea.value.split('\n');
|
||||
var columns = textarea.cols;
|
||||
var lineCount = 0;
|
||||
$.each(lines, function() {
|
||||
lineCount += Math.ceil(this.length / columns) || 1;
|
||||
});
|
||||
var height = lineHeight * (lineCount + 1);
|
||||
$(textarea).css('height', height);
|
||||
};
|
||||
})(jQuery);
|
||||
|
||||
(function($) {
|
||||
var comp, by;
|
||||
|
||||
function init() {
|
||||
initEvents();
|
||||
initComparator();
|
||||
}
|
||||
|
||||
function initEvents() {
|
||||
$(document).on("click", 'a.comment-close', function(event) {
|
||||
event.preventDefault();
|
||||
hide($(this).attr('id').substring(2));
|
||||
});
|
||||
$(document).on("click", 'a.vote', function(event) {
|
||||
event.preventDefault();
|
||||
handleVote($(this));
|
||||
});
|
||||
$(document).on("click", 'a.reply', function(event) {
|
||||
event.preventDefault();
|
||||
openReply($(this).attr('id').substring(2));
|
||||
});
|
||||
$(document).on("click", 'a.close-reply', function(event) {
|
||||
event.preventDefault();
|
||||
closeReply($(this).attr('id').substring(2));
|
||||
});
|
||||
$(document).on("click", 'a.sort-option', function(event) {
|
||||
event.preventDefault();
|
||||
handleReSort($(this));
|
||||
});
|
||||
$(document).on("click", 'a.show-proposal', function(event) {
|
||||
event.preventDefault();
|
||||
showProposal($(this).attr('id').substring(2));
|
||||
});
|
||||
$(document).on("click", 'a.hide-proposal', function(event) {
|
||||
event.preventDefault();
|
||||
hideProposal($(this).attr('id').substring(2));
|
||||
});
|
||||
$(document).on("click", 'a.show-propose-change', function(event) {
|
||||
event.preventDefault();
|
||||
showProposeChange($(this).attr('id').substring(2));
|
||||
});
|
||||
$(document).on("click", 'a.hide-propose-change', function(event) {
|
||||
event.preventDefault();
|
||||
hideProposeChange($(this).attr('id').substring(2));
|
||||
});
|
||||
$(document).on("click", 'a.accept-comment', function(event) {
|
||||
event.preventDefault();
|
||||
acceptComment($(this).attr('id').substring(2));
|
||||
});
|
||||
$(document).on("click", 'a.delete-comment', function(event) {
|
||||
event.preventDefault();
|
||||
deleteComment($(this).attr('id').substring(2));
|
||||
});
|
||||
$(document).on("click", 'a.comment-markup', function(event) {
|
||||
event.preventDefault();
|
||||
toggleCommentMarkupBox($(this).attr('id').substring(2));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set comp, which is a comparator function used for sorting and
|
||||
* inserting comments into the list.
|
||||
*/
|
||||
function setComparator() {
|
||||
// If the first three letters are "asc", sort in ascending order
|
||||
// and remove the prefix.
|
||||
if (by.substring(0,3) == 'asc') {
|
||||
var i = by.substring(3);
|
||||
comp = function(a, b) { return a[i] - b[i]; };
|
||||
} else {
|
||||
// Otherwise sort in descending order.
|
||||
comp = function(a, b) { return b[by] - a[by]; };
|
||||
}
|
||||
|
||||
// Reset link styles and format the selected sort option.
|
||||
$('a.sel').attr('href', '#').removeClass('sel');
|
||||
$('a.by' + by).removeAttr('href').addClass('sel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a comp function. If the user has preferences stored in
|
||||
* the sortBy cookie, use those, otherwise use the default.
|
||||
*/
|
||||
function initComparator() {
|
||||
by = 'rating'; // Default to sort by rating.
|
||||
// If the sortBy cookie is set, use that instead.
|
||||
if (document.cookie.length > 0) {
|
||||
var start = document.cookie.indexOf('sortBy=');
|
||||
if (start != -1) {
|
||||
start = start + 7;
|
||||
var end = document.cookie.indexOf(";", start);
|
||||
if (end == -1) {
|
||||
end = document.cookie.length;
|
||||
by = unescape(document.cookie.substring(start, end));
|
||||
}
|
||||
}
|
||||
}
|
||||
setComparator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a comment div.
|
||||
*/
|
||||
function show(id) {
|
||||
$('#ao' + id).hide();
|
||||
$('#ah' + id).show();
|
||||
var context = $.extend({id: id}, opts);
|
||||
var popup = $(renderTemplate(popupTemplate, context)).hide();
|
||||
popup.find('textarea[name="proposal"]').hide();
|
||||
popup.find('a.by' + by).addClass('sel');
|
||||
var form = popup.find('#cf' + id);
|
||||
form.submit(function(event) {
|
||||
event.preventDefault();
|
||||
addComment(form);
|
||||
});
|
||||
$('#s' + id).after(popup);
|
||||
popup.slideDown('fast', function() {
|
||||
getComments(id);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide a comment div.
|
||||
*/
|
||||
function hide(id) {
|
||||
$('#ah' + id).hide();
|
||||
$('#ao' + id).show();
|
||||
var div = $('#sc' + id);
|
||||
div.slideUp('fast', function() {
|
||||
div.remove();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an ajax request to get comments for a node
|
||||
* and insert the comments into the comments tree.
|
||||
*/
|
||||
function getComments(id) {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: opts.getCommentsURL,
|
||||
data: {node: id},
|
||||
success: function(data, textStatus, request) {
|
||||
var ul = $('#cl' + id);
|
||||
var speed = 100;
|
||||
$('#cf' + id)
|
||||
.find('textarea[name="proposal"]')
|
||||
.data('source', data.source);
|
||||
|
||||
if (data.comments.length === 0) {
|
||||
ul.html('<li>No comments yet.</li>');
|
||||
ul.data('empty', true);
|
||||
} else {
|
||||
// If there are comments, sort them and put them in the list.
|
||||
var comments = sortComments(data.comments);
|
||||
speed = data.comments.length * 100;
|
||||
appendComments(comments, ul);
|
||||
ul.data('empty', false);
|
||||
}
|
||||
$('#cn' + id).slideUp(speed + 200);
|
||||
ul.slideDown(speed);
|
||||
},
|
||||
error: function(request, textStatus, error) {
|
||||
showError('Oops, there was a problem retrieving the comments.');
|
||||
},
|
||||
dataType: 'json'
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a comment via ajax and insert the comment into the comment tree.
|
||||
*/
|
||||
function addComment(form) {
|
||||
var node_id = form.find('input[name="node"]').val();
|
||||
var parent_id = form.find('input[name="parent"]').val();
|
||||
var text = form.find('textarea[name="comment"]').val();
|
||||
var proposal = form.find('textarea[name="proposal"]').val();
|
||||
|
||||
if (text == '') {
|
||||
showError('Please enter a comment.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable the form that is being submitted.
|
||||
form.find('textarea,input').attr('disabled', 'disabled');
|
||||
|
||||
// Send the comment to the server.
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: opts.addCommentURL,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
node: node_id,
|
||||
parent: parent_id,
|
||||
text: text,
|
||||
proposal: proposal
|
||||
},
|
||||
success: function(data, textStatus, error) {
|
||||
// Reset the form.
|
||||
if (node_id) {
|
||||
hideProposeChange(node_id);
|
||||
}
|
||||
form.find('textarea')
|
||||
.val('')
|
||||
.add(form.find('input'))
|
||||
.removeAttr('disabled');
|
||||
var ul = $('#cl' + (node_id || parent_id));
|
||||
if (ul.data('empty')) {
|
||||
$(ul).empty();
|
||||
ul.data('empty', false);
|
||||
}
|
||||
insertComment(data.comment);
|
||||
var ao = $('#ao' + node_id);
|
||||
ao.find('img').attr({'src': opts.commentBrightImage});
|
||||
if (node_id) {
|
||||
// if this was a "root" comment, remove the commenting box
|
||||
// (the user can get it back by reopening the comment popup)
|
||||
$('#ca' + node_id).slideUp();
|
||||
}
|
||||
},
|
||||
error: function(request, textStatus, error) {
|
||||
form.find('textarea,input').removeAttr('disabled');
|
||||
showError('Oops, there was a problem adding the comment.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively append comments to the main comment list and children
|
||||
* lists, creating the comment tree.
|
||||
*/
|
||||
function appendComments(comments, ul) {
|
||||
$.each(comments, function() {
|
||||
var div = createCommentDiv(this);
|
||||
ul.append($(document.createElement('li')).html(div));
|
||||
appendComments(this.children, div.find('ul.comment-children'));
|
||||
// To avoid stagnating data, don't store the comments children in data.
|
||||
this.children = null;
|
||||
div.data('comment', this);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* After adding a new comment, it must be inserted in the correct
|
||||
* location in the comment tree.
|
||||
*/
|
||||
function insertComment(comment) {
|
||||
var div = createCommentDiv(comment);
|
||||
|
||||
// To avoid stagnating data, don't store the comments children in data.
|
||||
comment.children = null;
|
||||
div.data('comment', comment);
|
||||
|
||||
var ul = $('#cl' + (comment.node || comment.parent));
|
||||
var siblings = getChildren(ul);
|
||||
|
||||
var li = $(document.createElement('li'));
|
||||
li.hide();
|
||||
|
||||
// Determine where in the parents children list to insert this comment.
|
||||
for(i=0; i < siblings.length; i++) {
|
||||
if (comp(comment, siblings[i]) <= 0) {
|
||||
$('#cd' + siblings[i].id)
|
||||
.parent()
|
||||
.before(li.html(div));
|
||||
li.slideDown('fast');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here, this comment rates lower than all the others,
|
||||
// or it is the only comment in the list.
|
||||
ul.append(li.html(div));
|
||||
li.slideDown('fast');
|
||||
}
|
||||
|
||||
function acceptComment(id) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: opts.acceptCommentURL,
|
||||
data: {id: id},
|
||||
success: function(data, textStatus, request) {
|
||||
$('#cm' + id).fadeOut('fast');
|
||||
$('#cd' + id).removeClass('moderate');
|
||||
},
|
||||
error: function(request, textStatus, error) {
|
||||
showError('Oops, there was a problem accepting the comment.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function deleteComment(id) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: opts.deleteCommentURL,
|
||||
data: {id: id},
|
||||
success: function(data, textStatus, request) {
|
||||
var div = $('#cd' + id);
|
||||
if (data == 'delete') {
|
||||
// Moderator mode: remove the comment and all children immediately
|
||||
div.slideUp('fast', function() {
|
||||
div.remove();
|
||||
});
|
||||
return;
|
||||
}
|
||||
// User mode: only mark the comment as deleted
|
||||
div
|
||||
.find('span.user-id:first')
|
||||
.text('[deleted]').end()
|
||||
.find('div.comment-text:first')
|
||||
.text('[deleted]').end()
|
||||
.find('#cm' + id + ', #dc' + id + ', #ac' + id + ', #rc' + id +
|
||||
', #sp' + id + ', #hp' + id + ', #cr' + id + ', #rl' + id)
|
||||
.remove();
|
||||
var comment = div.data('comment');
|
||||
comment.username = '[deleted]';
|
||||
comment.text = '[deleted]';
|
||||
div.data('comment', comment);
|
||||
},
|
||||
error: function(request, textStatus, error) {
|
||||
showError('Oops, there was a problem deleting the comment.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showProposal(id) {
|
||||
$('#sp' + id).hide();
|
||||
$('#hp' + id).show();
|
||||
$('#pr' + id).slideDown('fast');
|
||||
}
|
||||
|
||||
function hideProposal(id) {
|
||||
$('#hp' + id).hide();
|
||||
$('#sp' + id).show();
|
||||
$('#pr' + id).slideUp('fast');
|
||||
}
|
||||
|
||||
function showProposeChange(id) {
|
||||
$('#pc' + id).hide();
|
||||
$('#hc' + id).show();
|
||||
var textarea = $('#pt' + id);
|
||||
textarea.val(textarea.data('source'));
|
||||
$.fn.autogrow.resize(textarea[0]);
|
||||
textarea.slideDown('fast');
|
||||
}
|
||||
|
||||
function hideProposeChange(id) {
|
||||
$('#hc' + id).hide();
|
||||
$('#pc' + id).show();
|
||||
var textarea = $('#pt' + id);
|
||||
textarea.val('').removeAttr('disabled');
|
||||
textarea.slideUp('fast');
|
||||
}
|
||||
|
||||
function toggleCommentMarkupBox(id) {
|
||||
$('#mb' + id).toggle();
|
||||
}
|
||||
|
||||
/** Handle when the user clicks on a sort by link. */
|
||||
function handleReSort(link) {
|
||||
var classes = link.attr('class').split(/\s+/);
|
||||
for (var i=0; i<classes.length; i++) {
|
||||
if (classes[i] != 'sort-option') {
|
||||
by = classes[i].substring(2);
|
||||
}
|
||||
}
|
||||
setComparator();
|
||||
// Save/update the sortBy cookie.
|
||||
var expiration = new Date();
|
||||
expiration.setDate(expiration.getDate() + 365);
|
||||
document.cookie= 'sortBy=' + escape(by) +
|
||||
';expires=' + expiration.toUTCString();
|
||||
$('ul.comment-ul').each(function(index, ul) {
|
||||
var comments = getChildren($(ul), true);
|
||||
comments = sortComments(comments);
|
||||
appendComments(comments, $(ul).empty());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to process a vote when a user clicks an arrow.
|
||||
*/
|
||||
function handleVote(link) {
|
||||
if (!opts.voting) {
|
||||
showError("You'll need to login to vote.");
|
||||
return;
|
||||
}
|
||||
|
||||
var id = link.attr('id');
|
||||
if (!id) {
|
||||
// Didn't click on one of the voting arrows.
|
||||
return;
|
||||
}
|
||||
// If it is an unvote, the new vote value is 0,
|
||||
// Otherwise it's 1 for an upvote, or -1 for a downvote.
|
||||
var value = 0;
|
||||
if (id.charAt(1) != 'u') {
|
||||
value = id.charAt(0) == 'u' ? 1 : -1;
|
||||
}
|
||||
// The data to be sent to the server.
|
||||
var d = {
|
||||
comment_id: id.substring(2),
|
||||
value: value
|
||||
};
|
||||
|
||||
// Swap the vote and unvote links.
|
||||
link.hide();
|
||||
$('#' + id.charAt(0) + (id.charAt(1) == 'u' ? 'v' : 'u') + d.comment_id)
|
||||
.show();
|
||||
|
||||
// The div the comment is displayed in.
|
||||
var div = $('div#cd' + d.comment_id);
|
||||
var data = div.data('comment');
|
||||
|
||||
// If this is not an unvote, and the other vote arrow has
|
||||
// already been pressed, unpress it.
|
||||
if ((d.value !== 0) && (data.vote === d.value * -1)) {
|
||||
$('#' + (d.value == 1 ? 'd' : 'u') + 'u' + d.comment_id).hide();
|
||||
$('#' + (d.value == 1 ? 'd' : 'u') + 'v' + d.comment_id).show();
|
||||
}
|
||||
|
||||
// Update the comments rating in the local data.
|
||||
data.rating += (data.vote === 0) ? d.value : (d.value - data.vote);
|
||||
data.vote = d.value;
|
||||
div.data('comment', data);
|
||||
|
||||
// Change the rating text.
|
||||
div.find('.rating:first')
|
||||
.text(data.rating + ' point' + (data.rating == 1 ? '' : 's'));
|
||||
|
||||
// Send the vote information to the server.
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: opts.processVoteURL,
|
||||
data: d,
|
||||
error: function(request, textStatus, error) {
|
||||
showError('Oops, there was a problem casting that vote.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a reply form used to reply to an existing comment.
|
||||
*/
|
||||
function openReply(id) {
|
||||
// Swap out the reply link for the hide link
|
||||
$('#rl' + id).hide();
|
||||
$('#cr' + id).show();
|
||||
|
||||
// Add the reply li to the children ul.
|
||||
var div = $(renderTemplate(replyTemplate, {id: id})).hide();
|
||||
$('#cl' + id)
|
||||
.prepend(div)
|
||||
// Setup the submit handler for the reply form.
|
||||
.find('#rf' + id)
|
||||
.submit(function(event) {
|
||||
event.preventDefault();
|
||||
addComment($('#rf' + id));
|
||||
closeReply(id);
|
||||
})
|
||||
.find('input[type=button]')
|
||||
.click(function() {
|
||||
closeReply(id);
|
||||
});
|
||||
div.slideDown('fast', function() {
|
||||
$('#rf' + id).find('textarea').focus();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the reply form opened with openReply.
|
||||
*/
|
||||
function closeReply(id) {
|
||||
// Remove the reply div from the DOM.
|
||||
$('#rd' + id).slideUp('fast', function() {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
// Swap out the hide link for the reply link
|
||||
$('#cr' + id).hide();
|
||||
$('#rl' + id).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively sort a tree of comments using the comp comparator.
|
||||
*/
|
||||
function sortComments(comments) {
|
||||
comments.sort(comp);
|
||||
$.each(comments, function() {
|
||||
this.children = sortComments(this.children);
|
||||
});
|
||||
return comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the children comments from a ul. If recursive is true,
|
||||
* recursively include childrens' children.
|
||||
*/
|
||||
function getChildren(ul, recursive) {
|
||||
var children = [];
|
||||
ul.children().children("[id^='cd']")
|
||||
.each(function() {
|
||||
var comment = $(this).data('comment');
|
||||
if (recursive)
|
||||
comment.children = getChildren($(this).find('#cl' + comment.id), true);
|
||||
children.push(comment);
|
||||
});
|
||||
return children;
|
||||
}
|
||||
|
||||
/** Create a div to display a comment in. */
|
||||
function createCommentDiv(comment) {
|
||||
if (!comment.displayed && !opts.moderator) {
|
||||
return $('<div class="moderate">Thank you! Your comment will show up '
|
||||
+ 'once it is has been approved by a moderator.</div>');
|
||||
}
|
||||
// Prettify the comment rating.
|
||||
comment.pretty_rating = comment.rating + ' point' +
|
||||
(comment.rating == 1 ? '' : 's');
|
||||
// Make a class (for displaying not yet moderated comments differently)
|
||||
comment.css_class = comment.displayed ? '' : ' moderate';
|
||||
// Create a div for this comment.
|
||||
var context = $.extend({}, opts, comment);
|
||||
var div = $(renderTemplate(commentTemplate, context));
|
||||
|
||||
// If the user has voted on this comment, highlight the correct arrow.
|
||||
if (comment.vote) {
|
||||
var direction = (comment.vote == 1) ? 'u' : 'd';
|
||||
div.find('#' + direction + 'v' + comment.id).hide();
|
||||
div.find('#' + direction + 'u' + comment.id).show();
|
||||
}
|
||||
|
||||
if (opts.moderator || comment.text != '[deleted]') {
|
||||
div.find('a.reply').show();
|
||||
if (comment.proposal_diff)
|
||||
div.find('#sp' + comment.id).show();
|
||||
if (opts.moderator && !comment.displayed)
|
||||
div.find('#cm' + comment.id).show();
|
||||
if (opts.moderator || (opts.username == comment.username))
|
||||
div.find('#dc' + comment.id).show();
|
||||
}
|
||||
return div;
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple template renderer. Placeholders such as <%id%> are replaced
|
||||
* by context['id'] with items being escaped. Placeholders such as <#id#>
|
||||
* are not escaped.
|
||||
*/
|
||||
function renderTemplate(template, context) {
|
||||
var esc = $(document.createElement('div'));
|
||||
|
||||
function handle(ph, escape) {
|
||||
var cur = context;
|
||||
$.each(ph.split('.'), function() {
|
||||
cur = cur[this];
|
||||
});
|
||||
return escape ? esc.text(cur || "").html() : cur;
|
||||
}
|
||||
|
||||
return template.replace(/<([%#])([\w\.]*)\1>/g, function() {
|
||||
return handle(arguments[2], arguments[1] == '%' ? true : false);
|
||||
});
|
||||
}
|
||||
|
||||
/** Flash an error message briefly. */
|
||||
function showError(message) {
|
||||
$(document.createElement('div')).attr({'class': 'popup-error'})
|
||||
.append($(document.createElement('div'))
|
||||
.attr({'class': 'error-message'}).text(message))
|
||||
.appendTo('body')
|
||||
.fadeIn("slow")
|
||||
.delay(2000)
|
||||
.fadeOut("slow");
|
||||
}
|
||||
|
||||
/** Add a link the user uses to open the comments popup. */
|
||||
$.fn.comment = function() {
|
||||
return this.each(function() {
|
||||
var id = $(this).attr('id').substring(1);
|
||||
var count = COMMENT_METADATA[id];
|
||||
var title = count + ' comment' + (count == 1 ? '' : 's');
|
||||
var image = count > 0 ? opts.commentBrightImage : opts.commentImage;
|
||||
var addcls = count == 0 ? ' nocomment' : '';
|
||||
$(this)
|
||||
.append(
|
||||
$(document.createElement('a')).attr({
|
||||
href: '#',
|
||||
'class': 'sphinx-comment-open' + addcls,
|
||||
id: 'ao' + id
|
||||
})
|
||||
.append($(document.createElement('img')).attr({
|
||||
src: image,
|
||||
alt: 'comment',
|
||||
title: title
|
||||
}))
|
||||
.click(function(event) {
|
||||
event.preventDefault();
|
||||
show($(this).attr('id').substring(2));
|
||||
})
|
||||
)
|
||||
.append(
|
||||
$(document.createElement('a')).attr({
|
||||
href: '#',
|
||||
'class': 'sphinx-comment-close hidden',
|
||||
id: 'ah' + id
|
||||
})
|
||||
.append($(document.createElement('img')).attr({
|
||||
src: opts.closeCommentImage,
|
||||
alt: 'close',
|
||||
title: 'close'
|
||||
}))
|
||||
.click(function(event) {
|
||||
event.preventDefault();
|
||||
hide($(this).attr('id').substring(2));
|
||||
})
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
var opts = {
|
||||
processVoteURL: '/_process_vote',
|
||||
addCommentURL: '/_add_comment',
|
||||
getCommentsURL: '/_get_comments',
|
||||
acceptCommentURL: '/_accept_comment',
|
||||
deleteCommentURL: '/_delete_comment',
|
||||
commentImage: '/static/_static/comment.png',
|
||||
closeCommentImage: '/static/_static/comment-close.png',
|
||||
loadingImage: '/static/_static/ajax-loader.gif',
|
||||
commentBrightImage: '/static/_static/comment-bright.png',
|
||||
upArrow: '/static/_static/up.png',
|
||||
downArrow: '/static/_static/down.png',
|
||||
upArrowPressed: '/static/_static/up-pressed.png',
|
||||
downArrowPressed: '/static/_static/down-pressed.png',
|
||||
voting: false,
|
||||
moderator: false
|
||||
};
|
||||
|
||||
if (typeof COMMENT_OPTIONS != "undefined") {
|
||||
opts = jQuery.extend(opts, COMMENT_OPTIONS);
|
||||
}
|
||||
|
||||
var popupTemplate = '\
|
||||
<div class="sphinx-comments" id="sc<%id%>">\
|
||||
<p class="sort-options">\
|
||||
Sort by:\
|
||||
<a href="#" class="sort-option byrating">best rated</a>\
|
||||
<a href="#" class="sort-option byascage">newest</a>\
|
||||
<a href="#" class="sort-option byage">oldest</a>\
|
||||
</p>\
|
||||
<div class="comment-header">Comments</div>\
|
||||
<div class="comment-loading" id="cn<%id%>">\
|
||||
loading comments... <img src="<%loadingImage%>" alt="" /></div>\
|
||||
<ul id="cl<%id%>" class="comment-ul"></ul>\
|
||||
<div id="ca<%id%>">\
|
||||
<p class="add-a-comment">Add a comment\
|
||||
(<a href="#" class="comment-markup" id="ab<%id%>">markup</a>):</p>\
|
||||
<div class="comment-markup-box" id="mb<%id%>">\
|
||||
reStructured text markup: <i>*emph*</i>, <b>**strong**</b>, \
|
||||
<code>``code``</code>, \
|
||||
code blocks: <code>::</code> and an indented block after blank line</div>\
|
||||
<form method="post" id="cf<%id%>" class="comment-form" action="">\
|
||||
<textarea name="comment" cols="80"></textarea>\
|
||||
<p class="propose-button">\
|
||||
<a href="#" id="pc<%id%>" class="show-propose-change">\
|
||||
Propose a change ▹\
|
||||
</a>\
|
||||
<a href="#" id="hc<%id%>" class="hide-propose-change">\
|
||||
Propose a change ▿\
|
||||
</a>\
|
||||
</p>\
|
||||
<textarea name="proposal" id="pt<%id%>" cols="80"\
|
||||
spellcheck="false"></textarea>\
|
||||
<input type="submit" value="Add comment" />\
|
||||
<input type="hidden" name="node" value="<%id%>" />\
|
||||
<input type="hidden" name="parent" value="" />\
|
||||
</form>\
|
||||
</div>\
|
||||
</div>';
|
||||
|
||||
var commentTemplate = '\
|
||||
<div id="cd<%id%>" class="sphinx-comment<%css_class%>">\
|
||||
<div class="vote">\
|
||||
<div class="arrow">\
|
||||
<a href="#" id="uv<%id%>" class="vote" title="vote up">\
|
||||
<img src="<%upArrow%>" />\
|
||||
</a>\
|
||||
<a href="#" id="uu<%id%>" class="un vote" title="vote up">\
|
||||
<img src="<%upArrowPressed%>" />\
|
||||
</a>\
|
||||
</div>\
|
||||
<div class="arrow">\
|
||||
<a href="#" id="dv<%id%>" class="vote" title="vote down">\
|
||||
<img src="<%downArrow%>" id="da<%id%>" />\
|
||||
</a>\
|
||||
<a href="#" id="du<%id%>" class="un vote" title="vote down">\
|
||||
<img src="<%downArrowPressed%>" />\
|
||||
</a>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="comment-content">\
|
||||
<p class="tagline comment">\
|
||||
<span class="user-id"><%username%></span>\
|
||||
<span class="rating"><%pretty_rating%></span>\
|
||||
<span class="delta"><%time.delta%></span>\
|
||||
</p>\
|
||||
<div class="comment-text comment"><#text#></div>\
|
||||
<p class="comment-opts comment">\
|
||||
<a href="#" class="reply hidden" id="rl<%id%>">reply ▹</a>\
|
||||
<a href="#" class="close-reply" id="cr<%id%>">reply ▿</a>\
|
||||
<a href="#" id="sp<%id%>" class="show-proposal">proposal ▹</a>\
|
||||
<a href="#" id="hp<%id%>" class="hide-proposal">proposal ▿</a>\
|
||||
<a href="#" id="dc<%id%>" class="delete-comment hidden">delete</a>\
|
||||
<span id="cm<%id%>" class="moderation hidden">\
|
||||
<a href="#" id="ac<%id%>" class="accept-comment">accept</a>\
|
||||
</span>\
|
||||
</p>\
|
||||
<pre class="proposal" id="pr<%id%>">\
|
||||
<#proposal_diff#>\
|
||||
</pre>\
|
||||
<ul class="comment-children" id="cl<%id%>"></ul>\
|
||||
</div>\
|
||||
<div class="clearleft"></div>\
|
||||
</div>\
|
||||
</div>';
|
||||
|
||||
var replyTemplate = '\
|
||||
<li>\
|
||||
<div class="reply-div" id="rd<%id%>">\
|
||||
<form id="rf<%id%>">\
|
||||
<textarea name="comment" cols="80"></textarea>\
|
||||
<input type="submit" value="Add reply" />\
|
||||
<input type="button" value="Cancel" />\
|
||||
<input type="hidden" name="parent" value="<%id%>" />\
|
||||
<input type="hidden" name="node" value="" />\
|
||||
</form>\
|
||||
</div>\
|
||||
</li>';
|
||||
|
||||
$(document).ready(function() {
|
||||
init();
|
||||
});
|
||||
})(jQuery);
|
||||
|
||||
$(document).ready(function() {
|
||||
// add comment anchors for all paragraphs that are commentable
|
||||
$('.sphinx-has-comment').comment();
|
||||
|
||||
// highlight search words in search results
|
||||
$("div.context").each(function() {
|
||||
var params = $.getQueryParameters();
|
||||
var terms = (params.q) ? params.q[0].split(/\s+/) : [];
|
||||
var result = $(this);
|
||||
$.each(terms, function() {
|
||||
result.highlightText(this.toLowerCase(), 'highlighted');
|
||||
});
|
||||
});
|
||||
|
||||
// directly open comment window if requested
|
||||
var anchor = document.location.hash;
|
||||
if (anchor.substring(0, 9) == '#comment-') {
|
||||
$('#ao' + anchor.substring(9)).click();
|
||||
document.location.hash = '#s' + anchor.substring(9);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,161 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>License — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: './',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="index.html" />
|
||||
<link rel="prev" title="Todo list for PySDL2" href="todos.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="todos.html" title="Todo list for PySDL2"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="license">
|
||||
<h1>License<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">This</span> <span class="n">software</span> <span class="ow">is</span> <span class="n">distributed</span> <span class="n">under</span> <span class="n">the</span> <span class="n">Public</span> <span class="n">Domain</span><span class="o">.</span> <span class="n">Since</span> <span class="n">it</span> <span class="ow">is</span>
|
||||
<span class="ow">not</span> <span class="n">enough</span> <span class="n">anymore</span> <span class="n">to</span> <span class="n">tell</span> <span class="n">people</span><span class="p">:</span> <span class="s1">'hey, just do with it whatever</span>
|
||||
<span class="n">you</span> <span class="n">like</span> <span class="n">to</span> <span class="n">do</span><span class="s1">', you can consider this software being distributed</span>
|
||||
<span class="n">under</span> <span class="n">the</span> <span class="n">CC0</span> <span class="n">Public</span> <span class="n">Domain</span> <span class="n">Dedication</span>
|
||||
<span class="p">(</span><span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">creativecommons</span><span class="o">.</span><span class="n">org</span><span class="o">/</span><span class="n">publicdomain</span><span class="o">/</span><span class="n">zero</span><span class="o">/</span><span class="mf">1.0</span><span class="o">/</span><span class="n">legalcode</span><span class="o">.</span><span class="n">txt</span><span class="p">)</span><span class="o">.</span>
|
||||
|
||||
<span class="n">In</span> <span class="n">cases</span><span class="p">,</span> <span class="n">where</span> <span class="n">the</span> <span class="n">law</span> <span class="n">prohibits</span> <span class="n">the</span> <span class="n">recognition</span> <span class="n">of</span> <span class="n">Public</span> <span class="n">Domain</span>
|
||||
<span class="n">software</span><span class="p">,</span> <span class="n">this</span> <span class="n">software</span> <span class="n">can</span> <span class="n">be</span> <span class="n">licensed</span> <span class="n">under</span> <span class="n">the</span> <span class="n">zlib</span> <span class="n">license</span> <span class="k">as</span>
|
||||
<span class="n">stated</span> <span class="n">below</span><span class="p">:</span>
|
||||
|
||||
<span class="n">Copyright</span> <span class="p">(</span><span class="n">C</span><span class="p">)</span> <span class="mi">2012</span><span class="o">-</span><span class="mi">2014</span> <span class="n">Marcus</span> <span class="n">von</span> <span class="n">Appen</span> <span class="o"><</span><span class="n">marcus</span><span class="nd">@sysfault</span><span class="o">.</span><span class="n">org</span><span class="o">></span>
|
||||
|
||||
<span class="n">This</span> <span class="n">software</span> <span class="ow">is</span> <span class="n">provided</span> <span class="s1">'as-is'</span><span class="p">,</span> <span class="n">without</span> <span class="nb">any</span> <span class="n">express</span> <span class="ow">or</span> <span class="n">implied</span>
|
||||
<span class="n">warranty</span><span class="o">.</span> <span class="n">In</span> <span class="n">no</span> <span class="n">event</span> <span class="n">will</span> <span class="n">the</span> <span class="n">authors</span> <span class="n">be</span> <span class="n">held</span> <span class="n">liable</span> <span class="k">for</span> <span class="nb">any</span> <span class="n">damages</span>
|
||||
<span class="n">arising</span> <span class="kn">from</span> <span class="nn">the</span> <span class="n">use</span> <span class="n">of</span> <span class="n">this</span> <span class="n">software</span><span class="o">.</span>
|
||||
|
||||
<span class="n">Permission</span> <span class="ow">is</span> <span class="n">granted</span> <span class="n">to</span> <span class="n">anyone</span> <span class="n">to</span> <span class="n">use</span> <span class="n">this</span> <span class="n">software</span> <span class="k">for</span> <span class="nb">any</span> <span class="n">purpose</span><span class="p">,</span>
|
||||
<span class="n">including</span> <span class="n">commercial</span> <span class="n">applications</span><span class="p">,</span> <span class="ow">and</span> <span class="n">to</span> <span class="n">alter</span> <span class="n">it</span> <span class="ow">and</span> <span class="n">redistribute</span> <span class="n">it</span>
|
||||
<span class="n">freely</span><span class="p">,</span> <span class="n">subject</span> <span class="n">to</span> <span class="n">the</span> <span class="n">following</span> <span class="n">restrictions</span><span class="p">:</span>
|
||||
|
||||
<span class="mf">1.</span> <span class="n">The</span> <span class="n">origin</span> <span class="n">of</span> <span class="n">this</span> <span class="n">software</span> <span class="n">must</span> <span class="ow">not</span> <span class="n">be</span> <span class="n">misrepresented</span><span class="p">;</span> <span class="n">you</span> <span class="n">must</span> <span class="ow">not</span>
|
||||
<span class="n">claim</span> <span class="n">that</span> <span class="n">you</span> <span class="n">wrote</span> <span class="n">the</span> <span class="n">original</span> <span class="n">software</span><span class="o">.</span> <span class="n">If</span> <span class="n">you</span> <span class="n">use</span> <span class="n">this</span> <span class="n">software</span>
|
||||
<span class="ow">in</span> <span class="n">a</span> <span class="n">product</span><span class="p">,</span> <span class="n">an</span> <span class="n">acknowledgement</span> <span class="ow">in</span> <span class="n">the</span> <span class="n">product</span> <span class="n">documentation</span> <span class="n">would</span> <span class="n">be</span>
|
||||
<span class="n">appreciated</span> <span class="n">but</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">required</span><span class="o">.</span>
|
||||
<span class="mf">2.</span> <span class="n">Altered</span> <span class="n">source</span> <span class="n">versions</span> <span class="n">must</span> <span class="n">be</span> <span class="n">plainly</span> <span class="n">marked</span> <span class="k">as</span> <span class="n">such</span><span class="p">,</span> <span class="ow">and</span> <span class="n">must</span> <span class="ow">not</span> <span class="n">be</span>
|
||||
<span class="n">misrepresented</span> <span class="k">as</span> <span class="n">being</span> <span class="n">the</span> <span class="n">original</span> <span class="n">software</span><span class="o">.</span>
|
||||
<span class="mf">3.</span> <span class="n">This</span> <span class="n">notice</span> <span class="n">may</span> <span class="ow">not</span> <span class="n">be</span> <span class="n">removed</span> <span class="ow">or</span> <span class="n">altered</span> <span class="kn">from</span> <span class="nn">any</span> <span class="n">source</span> <span class="n">distribution</span><span class="o">.</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Some files are <strong>not</strong> covered by the license above.</p>
|
||||
<ul>
|
||||
<li><p class="first">For <code class="docutils literal"><span class="pre">examples/resources/tuffy.ttf</span></code>,
|
||||
<code class="docutils literal"><span class="pre">examples/resources/tuffy.copy.ttf</span></code> and
|
||||
<code class="docutils literal"><span class="pre">sdl2/test/resources/tuffy.ttf</span></code> the following terms apply:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">We</span><span class="p">,</span> <span class="n">the</span> <span class="n">copyright</span> <span class="n">holders</span> <span class="n">of</span> <span class="n">this</span> <span class="n">work</span><span class="p">,</span> <span class="n">hereby</span> <span class="n">release</span> <span class="n">it</span> <span class="n">into</span> <span class="n">the</span>
|
||||
<span class="n">public</span> <span class="n">domain</span><span class="o">.</span> <span class="n">This</span> <span class="n">applies</span> <span class="n">worldwide</span><span class="o">.</span>
|
||||
|
||||
<span class="n">In</span> <span class="n">case</span> <span class="n">this</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">legally</span> <span class="n">possible</span><span class="p">,</span>
|
||||
|
||||
<span class="n">We</span> <span class="n">grant</span> <span class="nb">any</span> <span class="n">entity</span> <span class="n">the</span> <span class="n">right</span> <span class="n">to</span> <span class="n">use</span> <span class="n">this</span> <span class="n">work</span> <span class="k">for</span> <span class="nb">any</span> <span class="n">purpose</span><span class="p">,</span> <span class="n">without</span>
|
||||
<span class="nb">any</span> <span class="n">conditions</span><span class="p">,</span> <span class="n">unless</span> <span class="n">such</span> <span class="n">conditions</span> <span class="n">are</span> <span class="n">required</span> <span class="n">by</span> <span class="n">law</span><span class="o">.</span>
|
||||
|
||||
<span class="n">Thatcher</span> <span class="n">Ulrich</span> <span class="o"><</span><span class="n">tu</span><span class="nd">@tulrich</span><span class="o">.</span><span class="n">com</span><span class="o">></span> <span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">tulrich</span><span class="o">.</span><span class="n">com</span>
|
||||
<span class="n">Karoly</span> <span class="n">Barta</span> <span class="n">bartakarcsi</span><span class="nd">@gmail</span><span class="o">.</span><span class="n">com</span>
|
||||
<span class="n">Michael</span> <span class="n">Evans</span> <span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">www</span><span class="o">.</span><span class="n">evertype</span><span class="o">.</span><span class="n">com</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</li>
|
||||
<li><p class="first">doc/python.inv</p>
|
||||
<p>An inventory index for linking to the proper places in the Python
|
||||
documentation, taken from <a class="reference external" href="http://docs.python.org/2/">http://docs.python.org/2/</a>. Its copyright and
|
||||
license information can be found at
|
||||
<a class="reference external" href="http://docs.python.org/2/copyright.html">http://docs.python.org/2/copyright.html</a> and
|
||||
<a class="reference external" href="http://docs.python.org/2/license.html">http://docs.python.org/2/license.html</a>.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="todos.html"
|
||||
title="previous chapter">Todo list for PySDL2</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="_sources/copying.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="todos.html" title="Todo list for PySDL2"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,179 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>PySDL2 FAQ — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: './',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="index.html" />
|
||||
<link rel="next" title="Release News" href="news.html" />
|
||||
<link rel="prev" title="Window routines to manage on-screen windows" href="modules/sdl2ext_window.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="news.html" title="Release News"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="modules/sdl2ext_window.html" title="Window routines to manage on-screen windows"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="pysdl2-faq">
|
||||
<span id="faq"></span><h1>PySDL2 FAQ<a class="headerlink" href="#pysdl2-faq" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This is a list of Frequently Asked Questions about PySDL2. If you think,
|
||||
something is missing, please suggest it!</p>
|
||||
<div class="section" id="on-importing">
|
||||
<h2>On importing...<a class="headerlink" href="#on-importing" title="Permalink to this headline">¶</a></h2>
|
||||
<p>... my script fails and complains that a SDL2 library could not be found!</p>
|
||||
<blockquote>
|
||||
<div>Do you have the libraries properly installed? Did you follow the operating
|
||||
system’s way of installing or registering libraries? If you placed the
|
||||
libraries in some folder, make sure that the <code class="docutils literal"><span class="pre">PYSDL2_DLL_PATH</span></code>
|
||||
environment variable points to the correct location.</div></blockquote>
|
||||
<p>... my script fails complaining that the <em>found</em> SDL2 library can’t be used!</p>
|
||||
<blockquote>
|
||||
<div>Do you use a 64-bit operating system? Please make sure, that the Python
|
||||
interpreter <em>and</em> that the SDL2 libraries are either 64-bit ones <em>or</em>
|
||||
32-bit ones. A 32-bit Python interpreter can’t deal with a 64-bit library
|
||||
and vice versa.</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="using">
|
||||
<h2>Using...<a class="headerlink" href="#using" title="Permalink to this headline">¶</a></h2>
|
||||
<p>... the sdl2 API is weird. Why do you use the SDL_ prefix all the time?</p>
|
||||
<blockquote>
|
||||
<div>The low-level APIs for SDL2, SDL2_mixer, SDL2_ttf, ... shall represent a
|
||||
clean wrapping around the original C API calls. Thus, if you have to search
|
||||
for documentation or want to make a Python to C conversion (or C to Python),
|
||||
most of the code cleanly maps to the original API naming and layout and you
|
||||
do not have to think about whether you had to use SDL_ or TTF_ or whatever
|
||||
as prefix or suffix.</div></blockquote>
|
||||
<p>... the sdl2 API is does not comply to PEP-8. Please make it PEP-8 compatible.</p>
|
||||
<blockquote>
|
||||
<div>Most of the API is PEP-8 compatible. The low-level bindings to SDL2 and
|
||||
related libraries however use the exact naming (including capital letters)
|
||||
as the functions or structures, they map to. See the previous entry for
|
||||
the reason of that.</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="how-do-i">
|
||||
<h2>How do I...<a class="headerlink" href="#how-do-i" title="Permalink to this headline">¶</a></h2>
|
||||
<p>... save my surfaces as image files?</p>
|
||||
<blockquote>
|
||||
<div>You can use <code class="xref py py-func docutils literal"><span class="pre">sdl2.SDL_SaveBMP()</span></code> to save them as bitmap files. Other
|
||||
formats are currently unsupported, but might be added to
|
||||
the <a class="reference internal" href="modules/sdl2ext.html#module-sdl2.ext" title="sdl2.ext: Python extensions for SDL2"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.ext</span></code></a> package in the future.</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="font-handling">
|
||||
<h2>Font handling...<a class="headerlink" href="#font-handling" title="Permalink to this headline">¶</a></h2>
|
||||
<p>... is too hard. Why can’t it work the same way as pygame does?</p>
|
||||
<blockquote>
|
||||
<div>The <a class="reference internal" href="modules/sdl2_sdlttf.html#module-sdl2.sdlttf" title="sdl2.sdlttf: SDL2_ttf library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.sdlttf</span></code></a> API does not know about platform-specific font
|
||||
locations and is unable to resolve font paths based on e.g. the font name
|
||||
or typeface. It’s not its job and PySDL2 likewise does not provide such
|
||||
functionality. If you need improved font detection support, you might want
|
||||
to take a look at the sysfont module of the python-utils project, which can
|
||||
be found at <a class="reference external" href="https://bitbucket.org/marcusva/python-utils/">https://bitbucket.org/marcusva/python-utils/</a>.</div></blockquote>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="index.html">Table Of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">PySDL2 FAQ</a><ul>
|
||||
<li><a class="reference internal" href="#on-importing">On importing...</a></li>
|
||||
<li><a class="reference internal" href="#using">Using...</a></li>
|
||||
<li><a class="reference internal" href="#how-do-i">How do I...</a></li>
|
||||
<li><a class="reference internal" href="#font-handling">Font handling...</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="modules/sdl2ext_window.html"
|
||||
title="previous chapter">Window routines to manage on-screen windows</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="news.html"
|
||||
title="next chapter">Release News</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="_sources/faq.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="news.html" title="Release News"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="modules/sdl2ext_window.html" title="Window routines to manage on-screen windows"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,200 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Welcome to PySDL2’s documentation! — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: './',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="#" />
|
||||
<link rel="next" title="Installing PySDL2" href="install.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="install.html" title="Installing PySDL2"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="#">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="welcome-to-pysdl2-s-documentation">
|
||||
<h1>Welcome to PySDL2’s documentation!<a class="headerlink" href="#welcome-to-pysdl2-s-documentation" title="Permalink to this headline">¶</a></h1>
|
||||
<p>PySDL2 is a wrapper around the SDL2 library and as such similar to the
|
||||
discontinued PySDL project. In contrast to PySDL, it has no licensing
|
||||
restrictions, nor does it rely on C code, but uses <a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a> instead.</p>
|
||||
</div>
|
||||
<div class="section" id="contents">
|
||||
<h1>Contents<a class="headerlink" href="#contents" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="toctree-wrapper compound">
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="install.html">Installing PySDL2</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="install.html#getting-the-sources">Getting the sources</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="install.html#prerequisites">Prerequisites</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="install.html#installation">Installation</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="integration.html">Integrating PySDL2</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="integration.html#importing">Importing</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="integration.html#using-different-sdl2-versions">Using different SDL2 versions</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="tutorial/index.html">Learn to fly - the tutorials</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="tutorial/helloworld.html">Hello World</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="tutorial/pong.html">The Pong Game</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="tutorial/pygamers.html">PySDL2 for Pygamers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="modules/index.html">API reference</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="modules/sdl2.html">sdl2 - SDL2 library wrapper</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="modules/sdl2_sdlgfx.html">sdl2.sdlgfx - SDL2_gfx library wrapper</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="modules/sdl2_sdlimage.html">sdl2.sdlimage - SDL2_image library wrapper</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="modules/sdl2_sdlmixer.html">sd2.sdlmixer - SDL2_mixer library wrapper</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="modules/sdl2_sdlttf.html">sd2.sdlttf - SDL2_ttf library wrapper</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="modules/sdl2ext.html">sdl2.ext - Python extensions for SDL2</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="faq.html">PySDL2 FAQ</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="faq.html#on-importing">On importing...</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="faq.html#using">Using...</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="faq.html#how-do-i">How do I...</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="faq.html#font-handling">Font handling...</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="news.html">Release News</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id1">0.9.5</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id2">0.9.4</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id3">0.9.3</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id4">0.9.2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id5">0.9.1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id6">0.9.0</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id7">0.8.0</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id8">0.7.0</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id9">0.6.0</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id10">0.5.0</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id11">0.4.1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id12">0.4.0</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id13">0.3.0</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id14">0.2.0</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="news.html#id15">0.1.0</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<p>Further readings:</p>
|
||||
<div class="toctree-wrapper compound">
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="todos.html">Todo list for PySDL2</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="copying.html">License</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="indices-and-tables">
|
||||
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li>
|
||||
<li><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></li>
|
||||
<li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="documentation-todos">
|
||||
<h1>Documentation TODOs<a class="headerlink" href="#documentation-todos" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="admonition-todo admonition">
|
||||
<p class="first admonition-title">Todo</p>
|
||||
<p class="last">More details, examples, etc.</p>
|
||||
</div>
|
||||
<p class="todo-source">(The <a class="reference internal" href="tutorial/pygamers.html#index-0"><em>original entry</em></a> is located in /opt/marcus/projects/py-sdl2/doc/tutorial/pygamers.rst, line 11.)</p>
|
||||
<p>Last generated on: Oct 20, 2016</p>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="#">Table Of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">Welcome to PySDL2’s documentation!</a></li>
|
||||
<li><a class="reference internal" href="#contents">Contents</a><ul>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
|
||||
<li><a class="reference internal" href="#documentation-todos">Documentation TODOs</a></li>
|
||||
</ul>
|
||||
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="install.html"
|
||||
title="next chapter">Installing PySDL2</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="_sources/index.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="install.html" title="Installing PySDL2"
|
||||
>next</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="#">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,218 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Installing PySDL2 — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: './',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="index.html" />
|
||||
<link rel="next" title="Integrating PySDL2" href="integration.html" />
|
||||
<link rel="prev" title="Welcome to PySDL2’s documentation!" href="index.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="integration.html" title="Integrating PySDL2"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="index.html" title="Welcome to PySDL2’s documentation!"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="installing-pysdl2">
|
||||
<h1>Installing PySDL2<a class="headerlink" href="#installing-pysdl2" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This section provides an overview and guidance for installing PySDL2 on
|
||||
various target platforms.</p>
|
||||
<div class="section" id="getting-the-sources">
|
||||
<h2>Getting the sources<a class="headerlink" href="#getting-the-sources" title="Permalink to this headline">¶</a></h2>
|
||||
<p>You can download the official releases of PySDL2 from
|
||||
<a class="reference external" href="https://bitbucket.org/marcusva/py-sdl2/downloads">https://bitbucket.org/marcusva/py-sdl2/downloads</a>. Download the most
|
||||
recent release, unpack it and make sure that you installed the relevant
|
||||
prerequisites before continuing with the installation.</p>
|
||||
</div>
|
||||
<div class="section" id="prerequisites">
|
||||
<h2>Prerequisites<a class="headerlink" href="#prerequisites" title="Permalink to this headline">¶</a></h2>
|
||||
<p>PySDL2 relies on some 3rd party packages to be fully usable and to
|
||||
provide you full access to all of its features.</p>
|
||||
<p>You must have at least one of the following Python versions installed:</p>
|
||||
<ul class="simple">
|
||||
<li>Python 2.7, 3.2+ (<a class="reference external" href="http://www.python.org">http://www.python.org</a>)</li>
|
||||
<li>PyPy 1.8.0+ (<a class="reference external" href="http://www.pypy.org">http://www.pypy.org</a>)</li>
|
||||
</ul>
|
||||
<p>Other Python versions or Python implementations might work, but are
|
||||
(currently) not officially tested or supported by the PySDL2
|
||||
distribution.</p>
|
||||
<p>You need to have a working SDL2 library on your target system. You can obtain
|
||||
the source code (to build it yourself) or a prebuilt version at
|
||||
<a class="reference external" href="http://www.libsdl.org">http://www.libsdl.org</a>.</p>
|
||||
<p>PySDL2 also offers support for the following SDL-related libraries:</p>
|
||||
<ul class="simple">
|
||||
<li>SDL2_image (<a class="reference external" href="http://www.libsdl.org/projects/SDL_image/">http://www.libsdl.org/projects/SDL_image/</a>)</li>
|
||||
<li>SDL2_mixer (<a class="reference external" href="http://www.libsdl.org/projects/SDL_mixer/">http://www.libsdl.org/projects/SDL_mixer/</a>)</li>
|
||||
<li>SDL2_ttf (<a class="reference external" href="http://www.libsdl.org/projects/SDL_ttf/">http://www.libsdl.org/projects/SDL_ttf/</a>)</li>
|
||||
<li>SDL2_gfx (<a class="reference external" href="http://www.ferzkopp.net/Software/SDL_gfx-2.0/">http://www.ferzkopp.net/Software/SDL_gfx-2.0/</a>)</li>
|
||||
</ul>
|
||||
<p>Those are optional though and only necessary, if you want to use
|
||||
<a class="reference internal" href="modules/sdl2_sdlimage.html#module-sdl2.sdlimage" title="sdl2.sdlimage: SDL2_image library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.sdlimage</span></code></a>, <a class="reference internal" href="modules/sdl2_sdlmixer.html#module-sdl2.sdlmixer" title="sdl2.sdlmixer: SDL2_mixer library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.sdlmixer</span></code></a>, <a class="reference internal" href="modules/sdl2_sdlttf.html#module-sdl2.sdlttf" title="sdl2.sdlttf: SDL2_ttf library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.sdlttf</span></code></a> or
|
||||
<a class="reference internal" href="modules/sdl2_sdlgfx.html#module-sdl2.sdlgfx" title="sdl2.sdlgfx: SDL2_gfx library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.sdlgfx</span></code></a>.</p>
|
||||
</div>
|
||||
<div class="section" id="installation">
|
||||
<h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
|
||||
<p>You can either use the python way of installing the package or the make
|
||||
command using the Makefile on POSIX-compatible platforms, such as Linux
|
||||
or BSD, or the make.bat batch file on Windows platforms.</p>
|
||||
<p>Simply type</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">install</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>for the traditional python way or</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">make</span> <span class="n">install</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>for using the Makefile or make.bat. Both will try to perform a default
|
||||
installation with as many features as possible.</p>
|
||||
<div class="section" id="trying-out">
|
||||
<h3>Trying out<a class="headerlink" href="#trying-out" title="Permalink to this headline">¶</a></h3>
|
||||
<p>You also can test out PySDL2 without actually installing it. You just
|
||||
need to set up your <code class="docutils literal"><span class="pre">PYTHONPATH</span></code> to point to the location of the
|
||||
source distribution package. On Windows-based platforms, you might use
|
||||
something like</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nb">set</span> <span class="n">PYTHONPATH</span><span class="o">=</span><span class="n">C</span><span class="p">:</span>\<span class="n">path</span>\<span class="n">to</span>\<span class="n">pysdl2</span>\<span class="p">:</span><span class="o">%</span><span class="n">PYTHONPATH</span><span class="o">%</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>to define the <code class="docutils literal"><span class="pre">PYTHONPATH</span></code> on a command shell. On Linux/Unix, use</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span>export PYTHONPATH=/path/to/pysdl2:$PYTHONPATH
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>for bourne shell compatibles or</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span>setenv PYTHONPATH /path/to/pysdl2:$PYTHONPATH
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>for C shell compatibles. You can omit the <cite>:$PYTHONPATH`</cite>, if you did not use
|
||||
it so far and if your environment settings do not define it.</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">If you are using IronPython, use <code class="docutils literal"><span class="pre">IRONPYTHONPATH</span></code> instead of
|
||||
<code class="docutils literal"><span class="pre">PYTHONPATH</span></code>.</p>
|
||||
</div>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">If you did not install SDL2 using the preferred way for your operation
|
||||
system, please read the information about <a class="reference internal" href="integration.html#importing-pysdl2"><span class="std std-ref">Importing</span></a> in the
|
||||
section <a class="reference internal" href="integration.html"><span class="doc">Integrating PySDL2</span></a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="notes-on-mercurial-usage">
|
||||
<h3>Notes on Mercurial usage<a class="headerlink" href="#notes-on-mercurial-usage" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The Mercurial version of PySDL2 is not intended to be used in a
|
||||
production environment. Interfaces may change from one checkin to
|
||||
another, methods, classes or modules can be broken and so on. If you
|
||||
want more reliable code, please refer to the official releases.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="index.html">Table Of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">Installing PySDL2</a><ul>
|
||||
<li><a class="reference internal" href="#getting-the-sources">Getting the sources</a></li>
|
||||
<li><a class="reference internal" href="#prerequisites">Prerequisites</a></li>
|
||||
<li><a class="reference internal" href="#installation">Installation</a><ul>
|
||||
<li><a class="reference internal" href="#trying-out">Trying out</a></li>
|
||||
<li><a class="reference internal" href="#notes-on-mercurial-usage">Notes on Mercurial usage</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="index.html"
|
||||
title="previous chapter">Welcome to PySDL2’s documentation!</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="integration.html"
|
||||
title="next chapter">Integrating PySDL2</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="_sources/install.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="integration.html" title="Integrating PySDL2"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="index.html" title="Welcome to PySDL2’s documentation!"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,196 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Integrating PySDL2 — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: './',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="index.html" />
|
||||
<link rel="next" title="Learn to fly - the tutorials" href="tutorial/index.html" />
|
||||
<link rel="prev" title="Installing PySDL2" href="install.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="tutorial/index.html" title="Learn to fly - the tutorials"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="install.html" title="Installing PySDL2"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="integrating-pysdl2">
|
||||
<h1>Integrating PySDL2<a class="headerlink" href="#integrating-pysdl2" title="Permalink to this headline">¶</a></h1>
|
||||
<p>PySDL2 consists of two packages, <a class="reference internal" href="modules/sdl2.html#module-sdl2" title="sdl2: SDL2 library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2</span></code></a>, which is a plain 1:1 API
|
||||
wrapper around the SDL2 API, and <a class="reference internal" href="modules/sdl2ext.html#module-sdl2.ext" title="sdl2.ext: Python extensions for SDL2"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.ext</span></code></a>, which offers enhanced
|
||||
functionality for <a class="reference internal" href="modules/sdl2.html#module-sdl2" title="sdl2: SDL2 library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2</span></code></a>.</p>
|
||||
<p>The <a class="reference internal" href="modules/sdl2.html#module-sdl2" title="sdl2: SDL2 library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2</span></code></a> package is implemented in a way that shall make it easy for
|
||||
you to integrate and deploy it with your own software projects. You can rely
|
||||
on PySDL2 as third-party package, so that the user needs to install it
|
||||
before he can use your software. Alternatively, you can just copy the
|
||||
whole package into your project to ship it within your own project
|
||||
bundle.</p>
|
||||
<div class="section" id="importing">
|
||||
<span id="importing-pysdl2"></span><h2>Importing<a class="headerlink" href="#importing" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The <a class="reference internal" href="modules/sdl2.html#module-sdl2" title="sdl2: SDL2 library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2</span></code></a> package relies on an external SDL2 library for creating the
|
||||
wrapper functions. This means that the user needs to have SDL2 installed or
|
||||
that you ship a SDL2 library with your project.</p>
|
||||
<p>If the user has a SDL2 library installed on the target system, the
|
||||
<a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a> hooks of <a class="reference internal" href="modules/sdl2.html#module-sdl2" title="sdl2: SDL2 library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2</span></code></a> try to find it in the OS-specific standard
|
||||
locations via <a class="reference external" href="http://docs.python.org/library/ctypes.html#ctypes.util.find_library" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">ctypes.util.find_library()</span></code></a>. If you are going to ship your
|
||||
own SDL2 library with the project or can not rely on the standard mechanism of
|
||||
<a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a>, it is also possible to set the environment variable
|
||||
<span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal"><span class="pre">PYSDL2_DLL_PATH</span></code>, which shall point to the directory of the SDL2
|
||||
library or consist of a list of directories, in which the SDL2 libraries can
|
||||
be found.</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last"><span class="target" id="index-1"></span><code class="xref std std-envvar docutils literal"><span class="pre">PYSDL2_DLL_PATH</span></code> is preferred over the standard
|
||||
mechanism. If the module finds a SDL2 library in <span class="target" id="index-2"></span><code class="xref std std-envvar docutils literal"><span class="pre">PYSDL2_DLL_PATH</span></code>,
|
||||
it will try to use that one in the first place, before using any SDL2
|
||||
library installed on the target system.</p>
|
||||
</div>
|
||||
<p>Let’s assume, you ship your own library <em>SDL2.dll</em> within your project
|
||||
location <em>fancy_project/third_party</em>. You can set the environment
|
||||
variable <span class="target" id="index-3"></span><code class="xref std std-envvar docutils literal"><span class="pre">PYSDL2_DLL_PATH</span></code> before starting Python.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># Win32 platforms</span>
|
||||
<span class="nb">set</span> <span class="n">PYSDL2_DLL_PATH</span><span class="o">=</span><span class="n">C</span><span class="p">:</span>\<span class="n">path</span>\<span class="n">to</span>\<span class="n">fancy_project</span>\<span class="n">third_party</span>
|
||||
|
||||
<span class="c1"># Unix/Posix-alike environments - bourne shells</span>
|
||||
<span class="n">export</span> <span class="n">PYSDL2_DLL_PATH</span><span class="o">=/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">fancy_project</span><span class="o">/</span><span class="n">third_party</span>
|
||||
|
||||
<span class="c1"># Unix/Posix-alike environments - C shells</span>
|
||||
<span class="n">setenv</span> <span class="n">PYSDL2_DLL_PATH</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">fancy_project</span><span class="o">/</span><span class="n">third_party</span>
|
||||
|
||||
<span class="c1"># Define multiple paths to search for the libraries - Win32</span>
|
||||
<span class="nb">set</span> <span class="n">PYSDL2_DLL_PATH</span><span class="o">=</span><span class="n">C</span><span class="p">:</span>\<span class="n">first</span>\<span class="n">path</span><span class="p">;</span><span class="n">C</span><span class="p">:</span>\<span class="n">second</span>\<span class="n">path</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>You also can set the environment variable within Python using
|
||||
<a class="reference external" href="http://docs.python.org/library/os.html#os.environ" title="(in Python v2.7)"><code class="xref py py-data docutils literal"><span class="pre">os.environ</span></code></a>.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"PYSDL2_DLL_PATH"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"C:</span><span class="se">\\</span><span class="s2">path</span><span class="se">\\</span><span class="s2">to</span><span class="se">\\</span><span class="s2">fancy_project</span><span class="se">\\</span><span class="s2">third_party"</span>
|
||||
<span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"PYSDL2_DLL_PATH"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"/path/to/fancy_project/third_party"</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">If you aim to integrate <code class="xref py py-mod docutils literal"><span class="pre">sdl</span></code> directly into your software and do
|
||||
not want or are not allowed to change the environment variables, you
|
||||
can also change the <code class="docutils literal"><span class="pre">os.getenv("PYSDL2_DLL_PATH")</span></code> query within the
|
||||
<em>sdl2/dll.py</em> (or <em>sdl2/sdlimage.py</em>, <em>sdl2/sdlttf.py</em>, <em>sdl2/sdlgfx.py</em>)
|
||||
file to point to the directory, in which you keep the DLL.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="using-different-sdl2-versions">
|
||||
<h2>Using different SDL2 versions<a class="headerlink" href="#using-different-sdl2-versions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>PySDL2 tries to provide interfaces to the most recent versions of the
|
||||
SDL2 libraries. Sometimes this means that PySDL2 tries to test for
|
||||
functions that might not be available for your very own project or that
|
||||
are not available on the target system due to a version of the specific
|
||||
library. To check, if the SDL2 libraries do not provide certain
|
||||
functions, you can enable the specific warnings for them.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">python</span> <span class="o">-</span><span class="n">W</span><span class="s2">"module"</span><span class="p">::</span><span class="ne">ImportWarning</span><span class="p">:</span><span class="n">sdl2</span><span class="o">.</span><span class="n">dll</span> <span class="n">yourfile</span><span class="o">.</span><span class="n">py</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="index.html">Table Of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">Integrating PySDL2</a><ul>
|
||||
<li><a class="reference internal" href="#importing">Importing</a></li>
|
||||
<li><a class="reference internal" href="#using-different-sdl2-versions">Using different SDL2 versions</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="install.html"
|
||||
title="previous chapter">Installing PySDL2</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="tutorial/index.html"
|
||||
title="next chapter">Learn to fly - the tutorials</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="_sources/integration.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="tutorial/index.html" title="Learn to fly - the tutorials"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="install.html" title="Installing PySDL2"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,154 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>API reference — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="next" title="sdl2 - SDL2 library wrapper" href="sdl2.html" />
|
||||
<link rel="prev" title="PySDL2 for Pygamers" href="../tutorial/pygamers.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2.html" title="sdl2 - SDL2 library wrapper"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="../tutorial/pygamers.html" title="PySDL2 for Pygamers"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="api-reference">
|
||||
<h1>API reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This is the core documentation of the various modules, classes and functions
|
||||
PySDL2 offers. If you want to have a quick overview about the modules, use the
|
||||
<a class="reference internal" href="../py-modindex.html"><span class="std std-ref">Module Index</span></a>. If you just want to look up a specific class, method or
|
||||
function, use the <a class="reference internal" href="../genindex.html"><span class="std std-ref">Index</span></a> or <a class="reference internal" href="../search.html"><span class="std std-ref">Search Page</span></a>.</p>
|
||||
<div class="toctree-wrapper compound">
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2.html">sdl2 - SDL2 library wrapper</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2.html#usage">Usage</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2.html#missing-interfaces">Missing interfaces</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2.html#additional-interfaces">Additional interfaces</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2_sdlgfx.html">sdl2.sdlgfx - SDL2_gfx library wrapper</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2_sdlimage.html">sdl2.sdlimage - SDL2_image library wrapper</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2_sdlmixer.html">sd2.sdlmixer - SDL2_mixer library wrapper</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2_sdlttf.html">sd2.sdlttf - SDL2_ttf library wrapper</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext.html">sdl2.ext - Python extensions for SDL2</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_algorithms.html">Common algorithms</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_array.html">Converting sequences</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_color.html">Color handling</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_colorpalettes.html">sdl2.ext.colorpalettes - predefined sets of colors</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_common.html">Initialization routines</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_compat.html">sdl2.ext.compat - Python compatibility helpers</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_draw.html">2D drawing routines for software surfaces</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_ebs.html">Working with component-based entities</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_events.html">General purpose event handling routines</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_font.html">Text rendering routines</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_gui.html">User interface elements</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_image.html">Image loaders</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_particles.html">sdl2.ext.particles - A simple particle system</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_pixelaccess.html">2D and 3D direct pixel access</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_resources.html">Resource management</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_sprite.html">Sprite, texture and pixel surface routines</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_surface.html">Software Surface manipulation</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="sdl2ext_window.html">Window routines to manage on-screen windows</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="../tutorial/pygamers.html"
|
||||
title="previous chapter">PySDL2 for Pygamers</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2.html"
|
||||
title="next chapter">sdl2 - SDL2 library wrapper</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/index.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2.html" title="sdl2 - SDL2 library wrapper"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="../tutorial/pygamers.html" title="PySDL2 for Pygamers"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,296 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>sdl2 - SDL2 library wrapper — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="API reference" href="index.html" />
|
||||
<link rel="next" title="sdl2.sdlgfx - SDL2_gfx library wrapper" href="sdl2_sdlgfx.html" />
|
||||
<link rel="prev" title="API reference" href="index.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlgfx.html" title="sdl2.sdlgfx - SDL2_gfx library wrapper"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="index.html" title="API reference"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<span class="target" id="module-sdl2"></span><div class="section" id="sdl2-sdl2-library-wrapper">
|
||||
<h1>sdl2 - SDL2 library wrapper<a class="headerlink" href="#sdl2-sdl2-library-wrapper" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The <a class="reference internal" href="#module-sdl2" title="sdl2: SDL2 library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2</span></code></a> package is a <a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a>-based wrapper around
|
||||
the SDL2 library. It wraps nearly all publicly accessible structures and
|
||||
functions of the SDL2 library to be accessible from Python code.</p>
|
||||
<p>A detailed documentation about the behaviour of the different functions
|
||||
can found within the <a class="reference external" href="http://wiki.libsdl.org/moin.cgi/CategoryAPI">SDL2 documentation</a>.</p>
|
||||
<div class="section" id="usage">
|
||||
<h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
|
||||
<p>You can use <a class="reference internal" href="#module-sdl2" title="sdl2: SDL2 library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2</span></code></a> in nearly exactly the same way as you would do with
|
||||
the SDL library and C code.</p>
|
||||
<p>A brief example in C code:</p>
|
||||
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="cp">#include</span> <span class="cpf"><SDL.h></span><span class="cp"></span>
|
||||
|
||||
<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> <span class="p">{</span>
|
||||
<span class="kt">int</span> <span class="n">running</span><span class="p">;</span>
|
||||
<span class="n">SDL_Window</span> <span class="o">*</span><span class="n">window</span><span class="p">;</span>
|
||||
<span class="n">SDL_Surface</span> <span class="o">*</span><span class="n">windowsurface</span><span class="p">;</span>
|
||||
<span class="n">SDL_Surface</span> <span class="o">*</span><span class="n">image</span><span class="p">;</span>
|
||||
<span class="n">SDL_Event</span> <span class="n">event</span><span class="p">;</span>
|
||||
|
||||
<span class="n">SDL_Init</span><span class="p">(</span><span class="n">SDL_INIT_VIDEO</span><span class="p">);</span>
|
||||
|
||||
<span class="n">window</span> <span class="o">=</span> <span class="n">SDL_CreateWindow</span><span class="p">(</span><span class="s">"Hello World"</span><span class="p">,</span>
|
||||
<span class="n">SDL_WINDOWPOS_CENTERED</span><span class="p">,</span> <span class="n">SDL_WINDOWPOS_CENTERED</span><span class="p">,</span>
|
||||
<span class="mi">592</span><span class="p">,</span> <span class="mi">460</span><span class="p">,</span> <span class="n">SDL_WINDOW_SHOWN</span><span class="p">);</span>
|
||||
<span class="n">windowsurface</span> <span class="o">=</span> <span class="n">SDL_GetWindowSurface</span><span class="p">(</span><span class="n">window</span><span class="p">);</span>
|
||||
|
||||
<span class="n">image</span> <span class="o">=</span> <span class="n">SDL_LoadBMP</span><span class="p">(</span><span class="s">"exampleimage.bmp"</span><span class="p">);</span>
|
||||
<span class="n">SDL_BlitSurface</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="n">windowsurface</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
|
||||
|
||||
<span class="n">SDL_UpdateWindowSurface</span><span class="p">(</span><span class="n">window</span><span class="p">);</span>
|
||||
<span class="n">SDL_FreeSurface</span><span class="p">(</span><span class="n">image</span><span class="p">);</span>
|
||||
|
||||
<span class="n">running</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
|
||||
<span class="k">while</span> <span class="p">(</span><span class="n">running</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">while</span> <span class="p">(</span><span class="n">SDL_PollEvent</span><span class="p">(</span><span class="o">&</span><span class="n">event</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="n">event</span><span class="p">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">SDL_QUIT</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="n">running</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
|
||||
<span class="k">break</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
<span class="n">SDL_DestroyWindow</span><span class="p">(</span><span class="n">window</span><span class="p">);</span>
|
||||
<span class="n">SDL_Quit</span><span class="p">();</span>
|
||||
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Doing the same in Python:</p>
|
||||
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">sys</span>
|
||||
<span class="kn">import</span> <span class="nn">ctypes</span>
|
||||
<span class="kn">from</span> <span class="nn">sdl2</span> <span class="kn">import</span> <span class="o">*</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">main</span><span class="p">():</span>
|
||||
<span class="n">SDL_Init</span><span class="p">(</span><span class="n">SDL_INIT_VIDEO</span><span class="p">)</span>
|
||||
<span class="n">window</span> <span class="o">=</span> <span class="n">SDL_CreateWindow</span><span class="p">(</span><span class="n">b</span><span class="s2">"Hello World"</span><span class="p">,</span>
|
||||
<span class="n">SDL_WINDOWPOS_CENTERED</span><span class="p">,</span> <span class="n">SDL_WINDOWPOS_CENTERED</span><span class="p">,</span>
|
||||
<span class="mi">592</span><span class="p">,</span> <span class="mi">460</span><span class="p">,</span> <span class="n">SDL_WINDOW_SHOWN</span><span class="p">)</span>
|
||||
<span class="n">windowsurface</span> <span class="o">=</span> <span class="n">SDL_GetWindowSurface</span><span class="p">(</span><span class="n">window</span><span class="p">)</span>
|
||||
|
||||
<span class="n">image</span> <span class="o">=</span> <span class="n">SDL_LoadBMP</span><span class="p">(</span><span class="n">b</span><span class="s2">"exampleimage.bmp"</span><span class="p">)</span>
|
||||
<span class="n">SDL_BlitSurface</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="n">windowsurface</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
|
||||
|
||||
<span class="n">SDL_UpdateWindowSurface</span><span class="p">(</span><span class="n">window</span><span class="p">)</span>
|
||||
<span class="n">SDL_FreeSurface</span><span class="p">(</span><span class="n">image</span><span class="p">)</span>
|
||||
|
||||
<span class="n">running</span> <span class="o">=</span> <span class="bp">True</span>
|
||||
<span class="n">event</span> <span class="o">=</span> <span class="n">SDL_Event</span><span class="p">()</span>
|
||||
<span class="k">while</span> <span class="n">running</span><span class="p">:</span>
|
||||
<span class="k">while</span> <span class="n">SDL_PollEvent</span><span class="p">(</span><span class="n">ctypes</span><span class="o">.</span><span class="n">byref</span><span class="p">(</span><span class="n">event</span><span class="p">))</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
|
||||
<span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">SDL_QUIT</span><span class="p">:</span>
|
||||
<span class="n">running</span> <span class="o">=</span> <span class="bp">False</span>
|
||||
<span class="k">break</span>
|
||||
|
||||
<span class="n">SDL_DestroyWindow</span><span class="p">(</span><span class="n">window</span><span class="p">)</span>
|
||||
<span class="n">SDL_Quit</span><span class="p">()</span>
|
||||
<span class="k">return</span> <span class="mi">0</span>
|
||||
|
||||
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
||||
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">main</span><span class="p">())</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>You can port code in a straightforward manner from one language to the other,
|
||||
though it is important to know about the limitations and slight differences
|
||||
mentioned below. Also, PySDL2 offers advanced functionality, which also feels
|
||||
more <em>‘pythonic’</em>, via the <a class="reference internal" href="sdl2ext.html#module-sdl2.ext" title="sdl2.ext: Python extensions for SDL2"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.ext</span></code></a> package.</p>
|
||||
</div>
|
||||
<div class="section" id="missing-interfaces">
|
||||
<h2>Missing interfaces<a class="headerlink" href="#missing-interfaces" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The following functions, classes, constants and macros of SDL2 are <em>not</em>
|
||||
available within <a class="reference internal" href="#module-sdl2" title="sdl2: SDL2 library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2</span></code></a>.</p>
|
||||
<ul class="simple">
|
||||
<li><code class="xref c c-data docutils literal"><span class="pre">SDL_REVISION</span></code> and <code class="xref c c-data docutils literal"><span class="pre">SDL_REVISION_NUMBER</span></code> from <code class="docutils literal"><span class="pre">SDL_revision.h</span></code></li>
|
||||
<li><code class="xref c c-data docutils literal"><span class="pre">SDL_NAME()</span></code> from <code class="docutils literal"><span class="pre">SDL_name.h</span></code></li>
|
||||
<li><code class="xref c c-func docutils literal"><span class="pre">SDL_MostSignificantBitIndex32()</span></code> from <code class="docutils literal"><span class="pre">SDL_bits.h</span></code></li>
|
||||
<li>Everything from <code class="docutils literal"><span class="pre">SDL_main.h</span></code></li>
|
||||
<li>Everything from <code class="docutils literal"><span class="pre">SDL_system.h</span></code></li>
|
||||
<li>Everything from <code class="docutils literal"><span class="pre">SDL_assert.h</span></code></li>
|
||||
<li>Everything from <code class="docutils literal"><span class="pre">SDL_thread.h</span></code></li>
|
||||
<li>Everything from <code class="docutils literal"><span class="pre">SDL_atomic.h</span></code></li>
|
||||
<li>Everything from <code class="docutils literal"><span class="pre">SDL_opengl.h</span></code></li>
|
||||
<li>Everything from <code class="docutils literal"><span class="pre">SDL_mutex.h</span></code></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="additional-interfaces">
|
||||
<h2>Additional interfaces<a class="headerlink" href="#additional-interfaces" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The following functions, classes, constants and macros are are <em>not</em> part of
|
||||
SDL2, but were introduced by <a class="reference internal" href="#module-sdl2" title="sdl2: SDL2 library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2</span></code></a>.</p>
|
||||
<dl class="data">
|
||||
<dt id="sdl2.ALL_PIXELFORMATS">
|
||||
<code class="descclassname">sdl2.</code><code class="descname">ALL_PIXELFORMATS</code><a class="headerlink" href="#sdl2.ALL_PIXELFORMATS" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Tuple containing all SDL2 pixel format constants (SDL_PIXELFORMAT_INDEX1LSB,
|
||||
..., SDL_PIXELFORMAT_RGB565, ...).</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="data">
|
||||
<dt id="sdl2.AUDIO_FORMATS">
|
||||
<code class="descclassname">sdl2.</code><code class="descname">AUDIO_FORMATS</code><a class="headerlink" href="#sdl2.AUDIO_FORMATS" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Set containing all SDL2 audio format constants (AUDIO_U8, AUDIO_S8,
|
||||
... AUDIO_F32LSB, ... ).</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.sdl2.rw_from_object">
|
||||
<code class="descclassname">sdl2.</code><code class="descname">rw_from_object</code><span class="sig-paren">(</span><em>obj : object</em><span class="sig-paren">)</span> → SDL_RWops<a class="headerlink" href="#sdl2.sdl2.rw_from_object" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates a SDL_RWops from any Python object. The Python object must at least
|
||||
support the following methods:</p>
|
||||
<p>read(length) -> data</p>
|
||||
<blockquote>
|
||||
<div>length is the size in bytes to be read. A call to len(data) must
|
||||
return the correct amount of bytes for the data, so that
|
||||
len(data) / [size in bytes for a single element from data] returns
|
||||
the amount of elements. Must raise an error on failure.</div></blockquote>
|
||||
<p>seek(offset, whence) -> int</p>
|
||||
<blockquote>
|
||||
<div><p>offset denotes the offset to move the read/write pointer of the
|
||||
object to. whence indicates the movement behaviour and can be one
|
||||
of the following values:</p>
|
||||
<ul class="simple">
|
||||
<li>RW_SEEK_SET - move to offset from the start of the file</li>
|
||||
<li>RW_SEEK_CUR - move by offset from the relative location</li>
|
||||
<li>RW_SEEK_END - move to offset from the end of the file</li>
|
||||
</ul>
|
||||
<p>If it could not move read/write pointer to the desired location,
|
||||
an error must be raised.</p>
|
||||
</div></blockquote>
|
||||
<p>tell() -> int</p>
|
||||
<blockquote>
|
||||
<div>Must return the current offset. This method must only be
|
||||
provided, if seek() does not return any value.</div></blockquote>
|
||||
<p>close() -> None</p>
|
||||
<blockquote>
|
||||
<div>Closes the object(or its internal data access methods). Must raise
|
||||
an error on failure.</div></blockquote>
|
||||
<p>write(data) -> None</p>
|
||||
<blockquote>
|
||||
<div><p>Writes the passed data(which is a string of bytes) to the object.
|
||||
Must raise an error on failure.</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">The write() method is optional and only necessary, if the passed
|
||||
object should be able to write data.</p>
|
||||
</div>
|
||||
</div></blockquote>
|
||||
<p>The returned <code class="xref py py-class docutils literal"><span class="pre">sdl2.SDL_RWops</span></code> is a pure Python object and
|
||||
<strong>must not</strong> be freed via <code class="xref py py-func docutils literal"><span class="pre">sdl2.SDL_FreeRW()</span></code>.</p>
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="../index.html">Table Of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">sdl2 - SDL2 library wrapper</a><ul>
|
||||
<li><a class="reference internal" href="#usage">Usage</a></li>
|
||||
<li><a class="reference internal" href="#missing-interfaces">Missing interfaces</a></li>
|
||||
<li><a class="reference internal" href="#additional-interfaces">Additional interfaces</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="index.html"
|
||||
title="previous chapter">API reference</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2_sdlgfx.html"
|
||||
title="next chapter">sdl2.sdlgfx - SDL2_gfx library wrapper</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlgfx.html" title="sdl2.sdlgfx - SDL2_gfx library wrapper"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="index.html" title="API reference"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,124 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>sdl2.sdlgfx - SDL2_gfx library wrapper — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="API reference" href="index.html" />
|
||||
<link rel="next" title="sdl2.sdlimage - SDL2_image library wrapper" href="sdl2_sdlimage.html" />
|
||||
<link rel="prev" title="sdl2 - SDL2 library wrapper" href="sdl2.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlimage.html" title="sdl2.sdlimage - SDL2_image library wrapper"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2.html" title="sdl2 - SDL2 library wrapper"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<span class="target" id="module-sdl2.sdlgfx"></span><div class="section" id="sdl2-sdlgfx-sdl2-gfx-library-wrapper">
|
||||
<h1>sdl2.sdlgfx - SDL2_gfx library wrapper<a class="headerlink" href="#sdl2-sdlgfx-sdl2-gfx-library-wrapper" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The <a class="reference internal" href="#module-sdl2.sdlgfx" title="sdl2.sdlgfx: SDL2_gfx library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.sdlgfx</span></code></a> module is a <a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a>-based wrapper
|
||||
around the SDL2_gfx library. It wraps nearly all publicly accessible
|
||||
structures and functions of the SDL2_gfx library to be accessible from
|
||||
Python code.</p>
|
||||
<p>A detailed documentation about the behaviour of the different functions
|
||||
can found on the <a class="reference external" href="http://www.ferzkopp.net/Software/SDL_gfx-2.0/">SDL2_gfx project website</a>.</p>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2.html"
|
||||
title="previous chapter">sdl2 - SDL2 library wrapper</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2_sdlimage.html"
|
||||
title="next chapter">sdl2.sdlimage - SDL2_image library wrapper</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2_sdlgfx.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlimage.html" title="sdl2.sdlimage - SDL2_image library wrapper"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2.html" title="sdl2 - SDL2 library wrapper"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,124 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>sdl2.sdlimage - SDL2_image library wrapper — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="API reference" href="index.html" />
|
||||
<link rel="next" title="sd2.sdlmixer - SDL2_mixer library wrapper" href="sdl2_sdlmixer.html" />
|
||||
<link rel="prev" title="sdl2.sdlgfx - SDL2_gfx library wrapper" href="sdl2_sdlgfx.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlmixer.html" title="sd2.sdlmixer - SDL2_mixer library wrapper"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlgfx.html" title="sdl2.sdlgfx - SDL2_gfx library wrapper"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<span class="target" id="module-sdl2.sdlimage"></span><div class="section" id="sdl2-sdlimage-sdl2-image-library-wrapper">
|
||||
<h1>sdl2.sdlimage - SDL2_image library wrapper<a class="headerlink" href="#sdl2-sdlimage-sdl2-image-library-wrapper" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The <a class="reference internal" href="#module-sdl2.sdlimage" title="sdl2.sdlimage: SDL2_image library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.sdlimage</span></code></a> module is a <a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a>-based wrapper
|
||||
around the SDL2_image library. It wraps nearly all publicly accessible
|
||||
structures and functions of the SDL2_image library to be accessible from
|
||||
Python code.</p>
|
||||
<p>A detailed documentation about the behaviour of the different functions
|
||||
can found within the <a class="reference external" href="http://www.libsdl.org/projects/SDL_image/docs/index.html">SDL2_image documentation</a>.</p>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2_sdlgfx.html"
|
||||
title="previous chapter">sdl2.sdlgfx - SDL2_gfx library wrapper</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2_sdlmixer.html"
|
||||
title="next chapter">sd2.sdlmixer - SDL2_mixer library wrapper</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2_sdlimage.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlmixer.html" title="sd2.sdlmixer - SDL2_mixer library wrapper"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlgfx.html" title="sdl2.sdlgfx - SDL2_gfx library wrapper"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,124 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>sd2.sdlmixer - SDL2_mixer library wrapper — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="API reference" href="index.html" />
|
||||
<link rel="next" title="sd2.sdlttf - SDL2_ttf library wrapper" href="sdl2_sdlttf.html" />
|
||||
<link rel="prev" title="sdl2.sdlimage - SDL2_image library wrapper" href="sdl2_sdlimage.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlttf.html" title="sd2.sdlttf - SDL2_ttf library wrapper"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlimage.html" title="sdl2.sdlimage - SDL2_image library wrapper"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<span class="target" id="module-sdl2.sdlmixer"></span><div class="section" id="sd2-sdlmixer-sdl2-mixer-library-wrapper">
|
||||
<h1>sd2.sdlmixer - SDL2_mixer library wrapper<a class="headerlink" href="#sd2-sdlmixer-sdl2-mixer-library-wrapper" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The <a class="reference internal" href="#module-sdl2.sdlmixer" title="sdl2.sdlmixer: SDL2_mixer library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.sdlmixer</span></code></a> module is a <a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a>-based wrapper around
|
||||
the SDL2_mixer library. It wraps nearly all publicly accessible
|
||||
structures and functions of the SDL2_mixer library to be accessible from
|
||||
Python code.</p>
|
||||
<p>A detailed documentation about the behaviour of the different functions
|
||||
can found within the <a class="reference external" href="http://www.libsdl.org/projects/SDL_mixer/docs/index.html">SDL2_mixer documentation</a>.</p>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2_sdlimage.html"
|
||||
title="previous chapter">sdl2.sdlimage - SDL2_image library wrapper</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2_sdlttf.html"
|
||||
title="next chapter">sd2.sdlttf - SDL2_ttf library wrapper</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2_sdlmixer.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlttf.html" title="sd2.sdlttf - SDL2_ttf library wrapper"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlimage.html" title="sdl2.sdlimage - SDL2_image library wrapper"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,124 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>sd2.sdlttf - SDL2_ttf library wrapper — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="API reference" href="index.html" />
|
||||
<link rel="next" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="prev" title="sd2.sdlmixer - SDL2_mixer library wrapper" href="sdl2_sdlmixer.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext.html" title="sdl2.ext - Python extensions for SDL2"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlmixer.html" title="sd2.sdlmixer - SDL2_mixer library wrapper"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<span class="target" id="module-sdl2.sdlttf"></span><div class="section" id="sd2-sdlttf-sdl2-ttf-library-wrapper">
|
||||
<h1>sd2.sdlttf - SDL2_ttf library wrapper<a class="headerlink" href="#sd2-sdlttf-sdl2-ttf-library-wrapper" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The <a class="reference internal" href="#module-sdl2.sdlttf" title="sdl2.sdlttf: SDL2_ttf library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.sdlttf</span></code></a> module is a <a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a>-based wrapper
|
||||
around the SDL2_ttf library. It wraps nearly all publicly accessible
|
||||
structures and functions of the SDL2_ttf library to be accessible from
|
||||
Python code.</p>
|
||||
<p>A detailed documentation about the behaviour of the different functions
|
||||
can found within the <a class="reference external" href="http://www.libsdl.org/projects/SDL_ttf/docs/index.html">SDL2_ttf documentation</a>.</p>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2_sdlmixer.html"
|
||||
title="previous chapter">sd2.sdlmixer - SDL2_mixer library wrapper</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext.html"
|
||||
title="next chapter">sdl2.ext - Python extensions for SDL2</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2_sdlttf.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext.html" title="sdl2.ext - Python extensions for SDL2"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlmixer.html" title="sd2.sdlmixer - SDL2_mixer library wrapper"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,145 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>sdl2.ext - Python extensions for SDL2 — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="API reference" href="index.html" />
|
||||
<link rel="next" title="Common algorithms" href="sdl2ext_algorithms.html" />
|
||||
<link rel="prev" title="sd2.sdlttf - SDL2_ttf library wrapper" href="sdl2_sdlttf.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_algorithms.html" title="Common algorithms"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlttf.html" title="sd2.sdlttf - SDL2_ttf library wrapper"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<span class="target" id="module-sdl2.ext"></span><div class="section" id="sdl2-ext-python-extensions-for-sdl2">
|
||||
<h1>sdl2.ext - Python extensions for SDL2<a class="headerlink" href="#sdl2-ext-python-extensions-for-sdl2" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The <a class="reference internal" href="#module-sdl2.ext" title="sdl2.ext: Python extensions for SDL2"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.ext</span></code></a> package provides advanced functionality for creating
|
||||
applications using SDL2 and Python. It offers a rich set of modules, classes
|
||||
and functions, such as easy image loading, basic user interface elements,
|
||||
resource management and sprite and (on-screen) scene systems.</p>
|
||||
<p>Learn more about</p>
|
||||
<div class="toctree-wrapper compound">
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_algorithms.html">Common algorithms</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_array.html">Converting sequences</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_color.html">Color handling</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_colorpalettes.html">sdl2.ext.colorpalettes - predefined sets of colors</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_common.html">Initialization routines</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_compat.html">sdl2.ext.compat - Python compatibility helpers</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_draw.html">2D drawing routines for software surfaces</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_ebs.html">Working with component-based entities</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_events.html">General purpose event handling routines</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_font.html">Text rendering routines</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_gui.html">User interface elements</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_image.html">Image loaders</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_particles.html">sdl2.ext.particles - A simple particle system</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_pixelaccess.html">2D and 3D direct pixel access</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_resources.html">Resource management</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_sprite.html">Sprite, texture and pixel surface routines</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_surface.html">Software Surface manipulation</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sdl2ext_window.html">Window routines to manage on-screen windows</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2_sdlttf.html"
|
||||
title="previous chapter">sd2.sdlttf - SDL2_ttf library wrapper</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_algorithms.html"
|
||||
title="next chapter">Common algorithms</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_algorithms.html" title="Common algorithms"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2_sdlttf.html" title="sd2.sdlttf - SDL2_ttf library wrapper"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,159 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Common algorithms — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="Converting sequences" href="sdl2ext_array.html" />
|
||||
<link rel="prev" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_array.html" title="Converting sequences"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext.html" title="sdl2.ext - Python extensions for SDL2"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="common-algorithms">
|
||||
<h1>Common algorithms<a class="headerlink" href="#common-algorithms" title="Permalink to this headline">¶</a></h1>
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.cohensutherland">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">cohensutherland</code><span class="sig-paren">(</span><em>left : int</em>, <em>top : int</em>, <em>right : int</em>, <em>bottom : int</em>, <em>x1 : int</em>, <em>y1 : int</em>, <em>x2 : int</em>, <em>y2 : int</em><span class="sig-paren">)</span> → int, int, int, int<a class="headerlink" href="#sdl2.ext.cohensutherland" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>This implements the Cohen-Sutherland line clipping
|
||||
algorithm. <em>left</em>, <em>top</em>, <em>right</em> and <em>bottom</em> denote the
|
||||
clipping area, into which the line defined by <em>x1</em>, <em>y1</em> (start
|
||||
point) and <em>x2</em>, <em>y2</em> (end point) will be clipped.</p>
|
||||
<p>If the line does not intersect with the rectangular clipping area,
|
||||
four <code class="docutils literal"><span class="pre">None</span></code> values will be returned as tuple. Otherwise a tuple of
|
||||
the clipped line points will be returned in the form <code class="docutils literal"><span class="pre">(cx1,</span> <span class="pre">cy1,</span>
|
||||
<span class="pre">cx2,</span> <span class="pre">cy2)</span></code>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.liangbarsky">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">liangbarsky</code><span class="sig-paren">(</span><em>left : int</em>, <em>top : int</em>, <em>right : int</em>, <em>bottom : int</em>, <em>x1 : int</em>, <em>y1 : int</em>, <em>x2 : int</em>, <em>y2 : int</em><span class="sig-paren">)</span> → int, int, int, int<a class="headerlink" href="#sdl2.ext.liangbarsky" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>This implements the Liang-Barsky line clipping algorithm. <em>left</em>,
|
||||
<em>top</em>, <em>right</em> and <em>bottom</em> denote the clipping area, into
|
||||
which the line defined by <em>x1</em>, <em>y1</em> (start point) and <em>x2</em>,
|
||||
<em>y2</em> (end point) will be clipped.</p>
|
||||
<p>If the line does not intersect with the rectangular clipping area,
|
||||
four <code class="docutils literal"><span class="pre">None</span></code> values will be returned as tuple. Otherwise a tuple of
|
||||
the clipped line points will be returned in the form <code class="docutils literal"><span class="pre">(cx1,</span> <span class="pre">cy1,</span>
|
||||
<span class="pre">cx2,</span> <span class="pre">cy2)</span></code>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.clipline">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">clipline</code><span class="sig-paren">(</span><em>left : int</em>, <em>top : int</em>, <em>right : int</em>, <em>bottom : int</em>, <em>x1 : int</em>, <em>y1 : int</em>, <em>x2 : int</em>, <em>y2 : int</em><span class="optional">[</span>, <em>method=liangbarsky</em><span class="optional">]</span><span class="sig-paren">)</span> → int, int, int, int<a class="headerlink" href="#sdl2.ext.clipline" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Clips a line to a rectangular area.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.point_on_line">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">point_on_line</code><span class="sig-paren">(</span><em>p1 : iterable</em>, <em>p2 : iterable</em>, <em>point : iterable</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#sdl2.ext.point_on_line" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Checks, if <em>point</em>, a two-value tuple, is on the line segment defined by <em>p1</em>
|
||||
and <em>p2</em>.</p>
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext.html"
|
||||
title="previous chapter">sdl2.ext - Python extensions for SDL2</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_array.html"
|
||||
title="next chapter">Converting sequences</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_algorithms.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_array.html" title="Converting sequences"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext.html" title="sdl2.ext - Python extensions for SDL2"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,433 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Converting sequences — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="Color handling" href="sdl2ext_color.html" />
|
||||
<link rel="prev" title="Common algorithms" href="sdl2ext_algorithms.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_color.html" title="Color handling"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_algorithms.html" title="Common algorithms"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="converting-sequences">
|
||||
<h1>Converting sequences<a class="headerlink" href="#converting-sequences" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This module provides various functions and classes to access sequences and
|
||||
buffer-style objects in different ways. It also provides conversion routines
|
||||
to improve the interoperability of sequences with <a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a> data types.</p>
|
||||
<div class="section" id="providing-read-write-access-for-sequential-data">
|
||||
<h2>Providing read-write access for sequential data<a class="headerlink" href="#providing-read-write-access-for-sequential-data" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Two classes allow you to access sequential data in different ways. The
|
||||
<a class="reference internal" href="#sdl2.ext.CTypesView" title="sdl2.ext.CTypesView"><code class="xref py py-class docutils literal"><span class="pre">CTypesView</span></code></a> provides byte-wise access to iterable objects and allows
|
||||
you to convert the object representation to matching byte-widths for
|
||||
<a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a> or other modules.</p>
|
||||
<p>Depending on the the underlying object and the chosen size of each particular
|
||||
item of the object, the <a class="reference internal" href="#sdl2.ext.CTypesView" title="sdl2.ext.CTypesView"><code class="xref py py-class docutils literal"><span class="pre">CTypesView</span></code></a> allows you to operate directly
|
||||
on different representations of the object’s contents.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">text</span> <span class="o">=</span> <span class="nb">bytearray</span><span class="p">(</span><span class="s2">"Hello, I am a simple ASCII string!"</span><span class="p">)</span>
|
||||
<span class="gp">>>> </span><span class="n">ctview</span> <span class="o">=</span> <span class="n">CTypesView</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">itemsize</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
|
||||
<span class="gp">>>> </span><span class="n">ctview</span><span class="o">.</span><span class="n">view</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mh">0x61</span>
|
||||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">text</span><span class="p">)</span>
|
||||
<span class="go">aello, I am a simple ASCII string!"</span>
|
||||
<span class="gp">>>> </span><span class="n">ctview</span><span class="o">.</span><span class="n">to_uint16</span><span class="p">()[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="mh">0x6554</span>
|
||||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">text</span><span class="p">)</span>
|
||||
<span class="go">aello,Te am a simple ASCII string!"</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The snippet above provides a single-byte sized view on a <a class="reference external" href="http://docs.python.org/library/functions.html#bytearray" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">bytearray()</span></code></a>
|
||||
object. Afterwards, the first item of the view is changed, which causes a
|
||||
change on the <a class="reference external" href="http://docs.python.org/library/functions.html#bytearray" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">bytearray()</span></code></a>, on the first item as well, since both, the
|
||||
<a class="reference internal" href="#sdl2.ext.CTypesView" title="sdl2.ext.CTypesView"><code class="xref py py-class docutils literal"><span class="pre">CTypesView</span></code></a> and the <a class="reference external" href="http://docs.python.org/library/functions.html#bytearray" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">bytearray()</span></code></a> provide a byte-wise access to
|
||||
the contents.</p>
|
||||
<p>By using <a class="reference internal" href="#sdl2.ext.CTypesView.to_uint16" title="sdl2.ext.CTypesView.to_uint16"><code class="xref py py-meth docutils literal"><span class="pre">CTypesView.to_uint16()</span></code></a>, we change the access representation to
|
||||
a 2-byte unsigned integer <a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a> pointer and change the fourth 2-byte
|
||||
value, <em>I</em> to something else.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span>>>> text = bytearray("Hello, I am a simple ASCII string!")
|
||||
>>> ctview = CTypesView(text, itemsize=2)
|
||||
>>> ctview.view[0] = 0x61
|
||||
>>> print(text)
|
||||
aello, I am a simple ASCII string!"
|
||||
>>> ctview.to_uint16()[3] = 0x6554
|
||||
>>> print(text) aello,Te am a simple ASCII string!"
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>If the encapsuled object does not provide a (writable) <a class="reference external" href="http://docs.python.org/library/functions.html#buffer" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">buffer()</span></code></a>
|
||||
interface, but is iterable, the <a class="reference internal" href="#sdl2.ext.CTypesView" title="sdl2.ext.CTypesView"><code class="xref py py-class docutils literal"><span class="pre">CTypesView</span></code></a> will create an
|
||||
internal copy of the object data using Python’s <a class="reference external" href="http://docs.python.org/library/array.html#module-array" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">array</span></code></a> module and
|
||||
perform all operations on that copy.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">mylist</span> <span class="o">=</span> <span class="p">[</span><span class="mi">18</span><span class="p">,</span> <span class="mi">52</span><span class="p">,</span> <span class="mi">86</span><span class="p">,</span> <span class="mi">120</span><span class="p">,</span> <span class="mi">154</span><span class="p">,</span> <span class="mi">188</span><span class="p">,</span> <span class="mi">222</span><span class="p">,</span> <span class="mi">240</span><span class="p">]</span>
|
||||
<span class="gp">>>> </span><span class="n">ctview</span> <span class="o">=</span> <span class="n">CTypesView</span><span class="p">(</span><span class="n">mylist</span><span class="p">,</span> <span class="n">itemsize</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">docopy</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">ctview</span><span class="o">.</span><span class="n">object</span><span class="p">)</span>
|
||||
<span class="go">array('B', [18, 52, 86, 120, 154, 188, 222, 240])</span>
|
||||
<span class="gp">>>> </span><span class="n">ctview</span><span class="o">.</span><span class="n">view</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="mh">0xFF</span>
|
||||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">mylist</span><span class="p">)</span>
|
||||
<span class="go">[18, 52, 86, 120, 154, 188, 222, 240]</span>
|
||||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">ctview</span><span class="o">.</span><span class="n">object</span><span class="p">)</span>
|
||||
<span class="go">array('B', [18, 52, 86, 255, 154, 188, 222, 240])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>As for directly accessible objects, you can define your own itemsize to
|
||||
be used. If the iterable does not provide a direct byte access to their
|
||||
contents, this won’t have any effect except for resizing the item
|
||||
widths.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">mylist</span> <span class="o">=</span> <span class="p">[</span><span class="mi">18</span><span class="p">,</span> <span class="mi">52</span><span class="p">,</span> <span class="mi">86</span><span class="p">,</span> <span class="mi">120</span><span class="p">,</span> <span class="mi">154</span><span class="p">,</span> <span class="mi">188</span><span class="p">,</span> <span class="mi">222</span><span class="p">,</span> <span class="mi">240</span><span class="p">]</span>
|
||||
<span class="gp">>>> </span><span class="n">ctview</span> <span class="o">=</span> <span class="n">CTypesView</span><span class="p">(</span><span class="n">mylist</span><span class="p">,</span> <span class="n">itemsize</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">docopy</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">ctview</span><span class="o">.</span><span class="n">object</span><span class="p">)</span>
|
||||
<span class="go">array('I', [18L, 52L, 86L, 120L, 154L, 188L, 222L, 240L])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="accessing-data-over-multiple-dimensions">
|
||||
<h2>Accessing data over multiple dimensions<a class="headerlink" href="#accessing-data-over-multiple-dimensions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The second class, <a class="reference internal" href="#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a> provides an interface to access
|
||||
data over multiple dimensions. You can layout and access a simple
|
||||
byte stream over e.g. two or more axes, providing a greater flexibility
|
||||
for functional operations and complex data.</p>
|
||||
<p>Let’s assume, we are reading image data from a file stream into some buffer
|
||||
object and want to access and manipulate the image data. Images feature two
|
||||
axes, one being the width, the other being the height, defining a rectangular
|
||||
graphics area.</p>
|
||||
<p>When we read all data from the file, we have an one-dimensional view of the
|
||||
image graphics. The <a class="reference internal" href="#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a> allows us to define a
|
||||
two-dimensional view over the image graphics, so that we can operate on
|
||||
both, rows and columns of the image.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">imagedata</span> <span class="o">=</span> <span class="nb">bytearray</span><span class="p">(</span><span class="s2">"some 1-byte graphics data"</span><span class="p">)</span>
|
||||
<span class="gp">>>> </span><span class="n">view</span> <span class="o">=</span> <span class="n">MemoryView</span><span class="p">(</span><span class="n">imagedata</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span>
|
||||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">view</span><span class="p">)</span>
|
||||
<span class="go">[[s, o, m, e, ], [1, -, b, y, t], [e, , g, r, a], [p, h, i, c, s], [ , d, a, t, a]]</span>
|
||||
<span class="gp">>>> </span><span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">view</span><span class="p">:</span>
|
||||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">row</span><span class="p">)</span>
|
||||
<span class="gp">...</span>
|
||||
<span class="go">[s, o, m, e, ]</span>
|
||||
<span class="go">[1, -, b, y, t]</span>
|
||||
<span class="go">[e, , g, r, a]</span>
|
||||
<span class="go">[p, h, i, c, s]</span>
|
||||
<span class="go">[ , d, a, t, a]</span>
|
||||
<span class="gp">>>> </span><span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">view</span><span class="p">:</span>
|
||||
<span class="gp">... </span> <span class="n">row</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"X"</span>
|
||||
<span class="gp">... </span> <span class="nb">print</span> <span class="n">row</span>
|
||||
<span class="gp">...</span>
|
||||
<span class="go">[s, X, m, e, ]</span>
|
||||
<span class="go">[1, X, b, y, t]</span>
|
||||
<span class="go">[e, X, g, r, a]</span>
|
||||
<span class="go">[p, X, i, c, s]</span>
|
||||
<span class="go">[ , X, a, t, a]</span>
|
||||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">imagedata</span><span class="p">)</span>
|
||||
<span class="go">sXme 1XbyteXgrapXics Xata</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>On accessing a particular dimension of a <a class="reference internal" href="#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a>, a new
|
||||
<a class="reference internal" href="#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a> is created, if it does not access a single
|
||||
element.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">firstrow</span> <span class="o">=</span> <span class="n">view</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
|
||||
<span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">firstrow</span><span class="p">)</span>
|
||||
<span class="go"><class 'sdl2.ext.array.MemoryView'></span>
|
||||
<span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">firstrow</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
|
||||
<span class="go"><type 'bytearray'></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>A <a class="reference internal" href="#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a> features, similar to Python’s builtin
|
||||
<a class="reference external" href="http://docs.python.org/library/stdtypes.html#memoryview" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">memoryview</span></code></a>, dimensions and strides, accessible via the
|
||||
<a class="reference internal" href="#sdl2.ext.MemoryView.ndim" title="sdl2.ext.MemoryView.ndim"><code class="xref py py-attr docutils literal"><span class="pre">MemoryView.ndim</span></code></a> and <a class="reference internal" href="#sdl2.ext.MemoryView.strides" title="sdl2.ext.MemoryView.strides"><code class="xref py py-attr docutils literal"><span class="pre">MemoryView.strides</span></code></a> attributes.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">view</span><span class="o">.</span><span class="n">ndim</span>
|
||||
<span class="go">2</span>
|
||||
<span class="gp">>>> </span><span class="n">view</span><span class="o">.</span><span class="n">strides</span>
|
||||
<span class="go">(5, 5)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The <a class="reference internal" href="#sdl2.ext.MemoryView.strides" title="sdl2.ext.MemoryView.strides"><code class="xref py py-attr docutils literal"><span class="pre">MemoryView.strides</span></code></a>, which have to be passed on creating a
|
||||
new <a class="reference internal" href="#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a>, define the layout of the data over different
|
||||
dimensions. In the example above, we created a 5x5 two-dimensional view
|
||||
to the image graphics.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">twobytes</span> <span class="o">=</span> <span class="n">MemoryView</span><span class="p">(</span><span class="n">imagedata</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
|
||||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">twobytes</span><span class="p">)</span>
|
||||
<span class="go">[[sX, me, 1, Xb, yt], [eX, gr, ap, Xi, cs]]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="array-api">
|
||||
<h2>Array API<a class="headerlink" href="#array-api" title="Permalink to this headline">¶</a></h2>
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.CTypesView">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">CTypesView</code><span class="sig-paren">(</span><em>obj : iterable</em><span class="optional">[</span>, <em>itemsize=1</em><span class="optional">[</span>, <em>docopy=False</em><span class="optional">[</span>, <em>objsize=None</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.CTypesView" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A proxy class for byte-wise accessible data types to be used in
|
||||
ctypes bindings. The CTypesView provides a read-write access to
|
||||
arbitrary objects that are iterable.</p>
|
||||
<p>In case the object does not provide a <a class="reference external" href="http://docs.python.org/library/functions.html#buffer" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">buffer()</span></code></a> interface for
|
||||
direct access, the CTypesView can copy the object’s contents into an
|
||||
internal buffer, from which data can be retrieved, once the necessary
|
||||
operations have been performed.</p>
|
||||
<p>Depending on the item type stored in the iterable object, you might
|
||||
need to provide a certain <em>itemsize</em>, which denotes the size per
|
||||
item in bytes. The <em>objsize</em> argument might be necessary of iterables,
|
||||
for which len() does not return the correct amount of objects or is not
|
||||
implemented.</p>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.CTypesView.bytesize">
|
||||
<code class="descname">bytesize</code><a class="headerlink" href="#sdl2.ext.CTypesView.bytesize" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns the length of the encapsuled object in bytes.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.CTypesView.is_shared">
|
||||
<code class="descname">is_shared</code><a class="headerlink" href="#sdl2.ext.CTypesView.is_shared" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Indicates, if changes on the CTypesView data effect the encapsuled
|
||||
object directly. if not, this means that the object was copied
|
||||
internally and needs to be updated by the user code outside of the
|
||||
CTypesView.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.CTypesView.object">
|
||||
<code class="descname">object</code><a class="headerlink" href="#sdl2.ext.CTypesView.object" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The encapsuled object.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.CTypesView.view">
|
||||
<code class="descname">view</code><a class="headerlink" href="#sdl2.ext.CTypesView.view" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Provides a read-write aware view of the encapsuled object data
|
||||
that is suitable for usage from <a class="reference external" href="http://docs.python.org/library/ctypes.html#module-ctypes" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.CTypesView.to_bytes">
|
||||
<code class="descname">to_bytes</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → ctypes.POINTER<a class="headerlink" href="#sdl2.ext.CTypesView.to_bytes" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns a byte representation of the encapsuled object. The return
|
||||
value allows a direct read-write access to the object data, if it
|
||||
is not copied. The <a class="reference external" href="http://docs.python.org/library/ctypes.html#ctypes.POINTER" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">ctypes.POINTER()</span></code></a> points to an array of
|
||||
<a class="reference external" href="http://docs.python.org/library/ctypes.html#ctypes.c_ubyte" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">ctypes.c_ubyte</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.CTypesView.to_uint16">
|
||||
<code class="descname">to_uint16</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → ctypes.POINTER<a class="headerlink" href="#sdl2.ext.CTypesView.to_uint16" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns a 16-bit representation of the encapsuled object. The return
|
||||
value allows a direct read-write access to the object data, if it
|
||||
is not copied. The <a class="reference external" href="http://docs.python.org/library/ctypes.html#ctypes.POINTER" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">ctypes.POINTER()</span></code></a> points to an array of
|
||||
<a class="reference external" href="http://docs.python.org/library/ctypes.html#ctypes.c_ushort" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">ctypes.c_ushort</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.CTypesView.to_uint32">
|
||||
<code class="descname">to_uint32</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → ctypes.POINTER<a class="headerlink" href="#sdl2.ext.CTypesView.to_uint32" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns a 32-bit representation of the encapsuled object. The return
|
||||
value allows a direct read-write access to the object data, if it
|
||||
is not copied. The <a class="reference external" href="http://docs.python.org/library/ctypes.html#ctypes.POINTER" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">ctypes.POINTER()</span></code></a> points to an array of
|
||||
<a class="reference external" href="http://docs.python.org/library/ctypes.html#ctypes.c_uint" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">ctypes.c_uint</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.CTypesView.to_uint64">
|
||||
<code class="descname">to_uint64</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → ctypes.POINTER<a class="headerlink" href="#sdl2.ext.CTypesView.to_uint64" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns a 64-bit representation of the encapsuled object. The return
|
||||
value allows a direct read-write access to the object data, if it
|
||||
is not copied. The <a class="reference external" href="http://docs.python.org/library/ctypes.html#ctypes.POINTER" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">ctypes.POINTER()</span></code></a> points to an array of
|
||||
<a class="reference external" href="http://docs.python.org/library/ctypes.html#ctypes.c_ulonglong" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">ctypes.c_ulonglong</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.MemoryView">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">MemoryView</code><span class="sig-paren">(</span><em>source : object</em>, <em>itemsize : int</em>, <em>strides : tuple</em><span class="optional">[</span>, <em>getfunc=None</em><span class="optional">[</span>, <em>setfunc=None</em><span class="optional">[</span>, <em>srcsize=None</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.MemoryView" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The <a class="reference internal" href="#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a> provides a read-write access to arbitrary
|
||||
data objects, which can be indexed.</p>
|
||||
<p><em>itemsize</em> denotes the size of a single item. <em>strides</em> defines
|
||||
the dimensions and the length (n items * <em>itemsize</em>) for each
|
||||
dimension. <em>getfunc</em> and <em>setfunc</em> are optional parameters to
|
||||
provide specialised read and write access to the underlying
|
||||
<em>source</em>. <em>srcsize</em> can be used to provide the correct source
|
||||
size, if <code class="docutils literal"><span class="pre">len(source)</span></code> does not return the absolute size of the
|
||||
source object in all dimensions.</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">The MemoryView is a pure Python-based implementation and makes
|
||||
heavy use of recursion for multi-dimensional access. If you aim
|
||||
for speed on accessing a n-dimensional object, you want to
|
||||
consider using a specialised library such as numpy. If you need
|
||||
n-dimensional access support, where such a library is not
|
||||
supported, or if you need to provide access to objects, which do
|
||||
not fulfill the requirements of that particular libray,
|
||||
<a class="reference internal" href="#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a> can act as solid fallback solution.</p>
|
||||
</div>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.MemoryView.itemsize">
|
||||
<code class="descname">itemsize</code><a class="headerlink" href="#sdl2.ext.MemoryView.itemsize" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The size of a single item in bytes.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.MemoryView.ndim">
|
||||
<code class="descname">ndim</code><a class="headerlink" href="#sdl2.ext.MemoryView.ndim" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The number of dimensions of the <a class="reference internal" href="#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.MemoryView.size">
|
||||
<code class="descname">size</code><a class="headerlink" href="#sdl2.ext.MemoryView.size" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The size in bytes of the underlying source object.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.MemoryView.source">
|
||||
<code class="descname">source</code><a class="headerlink" href="#sdl2.ext.MemoryView.source" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The underlying data source.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.MemoryView.strides">
|
||||
<code class="descname">strides</code><a class="headerlink" href="#sdl2.ext.MemoryView.strides" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A tuple defining the length in bytes for accessing all
|
||||
elements in each dimension of the <a class="reference internal" href="#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.to_ctypes">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">to_ctypes</code><span class="sig-paren">(</span><em>dataseq : iterable</em>, <em>dtype</em><span class="optional">[</span>, <em>mcount=0</em><span class="optional">]</span><span class="sig-paren">)</span> → array, int<a class="headerlink" href="#sdl2.ext.to_ctypes" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Converts an arbitrary sequence to a ctypes array of the specified
|
||||
<em>dtype</em> and returns the ctypes array and amount of items as
|
||||
two-value tuple.</p>
|
||||
<p>Raises a <code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code>, if one or more elements in the passed
|
||||
sequence do not match the passed <em>dtype</em>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.to_list">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">to_list</code><span class="sig-paren">(</span><em>dataseq : iterable</em><span class="sig-paren">)</span> → list<a class="headerlink" href="#sdl2.ext.to_list" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Converts a ctypes array to a list.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.to_tuple">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">to_tuple</code><span class="sig-paren">(</span><em>dataseq : iterable</em><span class="sig-paren">)</span> → tuple<a class="headerlink" href="#sdl2.ext.to_tuple" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Converts a ctypes array to a tuple.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.create_array">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">create_array</code><span class="sig-paren">(</span><em>obj : object</em>, <em>itemsize : int</em><span class="sig-paren">)</span> → array.array<a class="headerlink" href="#sdl2.ext.create_array" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates an <a class="reference external" href="http://docs.python.org/library/array.html#array.array" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">array.array</span></code></a> based copy of the passed object.
|
||||
<em>itemsize</em> denotes the size in bytes for a single element within
|
||||
<em>obj</em>.</p>
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="../index.html">Table Of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">Converting sequences</a><ul>
|
||||
<li><a class="reference internal" href="#providing-read-write-access-for-sequential-data">Providing read-write access for sequential data</a></li>
|
||||
<li><a class="reference internal" href="#accessing-data-over-multiple-dimensions">Accessing data over multiple dimensions</a></li>
|
||||
<li><a class="reference internal" href="#array-api">Array API</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_algorithms.html"
|
||||
title="previous chapter">Common algorithms</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_color.html"
|
||||
title="next chapter">Color handling</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_array.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_color.html" title="Color handling"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_algorithms.html" title="Common algorithms"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,299 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Color handling — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="sdl2.ext.colorpalettes - predefined sets of colors" href="sdl2ext_colorpalettes.html" />
|
||||
<link rel="prev" title="Converting sequences" href="sdl2ext_array.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_colorpalettes.html" title="sdl2.ext.colorpalettes - predefined sets of colors"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_array.html" title="Converting sequences"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="color-handling">
|
||||
<h1>Color handling<a class="headerlink" href="#color-handling" title="Permalink to this headline">¶</a></h1>
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.Color">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">Color</code><span class="sig-paren">(</span><em>r=255</em>, <em>g=255</em>, <em>b=255</em>, <em>a=255</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.Color" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A simple RGBA-based color implementation. The Color class uses a
|
||||
byte-wise representation of the 4 channels red, green, blue and alpha
|
||||
transparency, so that the values range from 0 to 255. It allows basic
|
||||
arithmetic operations, e.g. color addition or subtraction and
|
||||
conversions to other color spaces such as HSV or CMY.</p>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Color.r">
|
||||
<code class="descname">r</code><a class="headerlink" href="#sdl2.ext.Color.r" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The red channel value of the Color.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Color.g">
|
||||
<code class="descname">g</code><a class="headerlink" href="#sdl2.ext.Color.g" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The green channel value of the Color.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Color.b">
|
||||
<code class="descname">b</code><a class="headerlink" href="#sdl2.ext.Color.b" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The blue channel value of the Color.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Color.a">
|
||||
<code class="descname">a</code><a class="headerlink" href="#sdl2.ext.Color.a" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The alpha channel value of the Color.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Color.cmy">
|
||||
<code class="descname">cmy</code><a class="headerlink" href="#sdl2.ext.Color.cmy" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The CMY representation of the Color. The CMY components are in the
|
||||
ranges C = [0, 1], M = [0, 1], Y = [0, 1]. Note that this will not
|
||||
return the absolutely exact CMY values for the set RGB values in
|
||||
all cases. Due to the RGB mapping from 0-255 and the CMY mapping
|
||||
from 0-1 rounding errors may cause the CMY values to differ
|
||||
slightly from what you might expect.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Color.hsla">
|
||||
<code class="descname">hsla</code><a class="headerlink" href="#sdl2.ext.Color.hsla" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The HSLA representation of the Color. The HSLA components are in
|
||||
the ranges H = [0, 360], S = [0, 100], L = [0, 100], A = [0,
|
||||
100]. Note that this will not return the absolutely exact HSL
|
||||
values for the set RGB values in all cases. Due to the RGB mapping
|
||||
from 0-255 and the HSL mapping from 0-100 and 0-360 rounding
|
||||
errors may cause the HSL values to differ slightly from what you
|
||||
might expect.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Color.hsva">
|
||||
<code class="descname">hsva</code><a class="headerlink" href="#sdl2.ext.Color.hsva" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The HSVA representation of the Color. The HSVA components are in
|
||||
the ranges H = [0, 360], S = [0, 100], V = [0, 100], A = [0,
|
||||
100]. Note that this will not return the absolutely exact HSV
|
||||
values for the set RGB values in all cases. Due to the RGB mapping
|
||||
from 0-255 and the HSV mapping from 0-100 and 0-360 rounding
|
||||
errors may cause the HSV values to differ slightly from what you
|
||||
might expect.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Color.i1i2i3">
|
||||
<code class="descname">i1i2i3</code><a class="headerlink" href="#sdl2.ext.Color.i1i2i3" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The I1I2I3 representation of the Color. The I1I2I3 components are
|
||||
in the ranges I1 = [0, 1], I2 = [-0.5, 0.5], I3 = [-0.5,
|
||||
0.5]. Note that this will not return the absolutely exact I1I2I3
|
||||
values for the set RGB values in all cases. Due to the RGB mapping
|
||||
from 0-255 and the I1I2I3 from 0-1 rounding errors may cause the
|
||||
I1I2I3 values to differ slightly from what you might expect.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.Color.normalize">
|
||||
<code class="descname">normalize</code><span class="sig-paren">(</span><em>) -> (float</em>, <em>float</em>, <em>float</em>, <em>float</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.Color.normalize" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns the normalised RGBA values of the Color as floating point
|
||||
values in the range [0, 1].</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.Color.__add__">
|
||||
<code class="descname">__add__</code><span class="sig-paren">(</span><em>self</em>, <em>color</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.Color.__add__" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="sdl2.ext.Color.__sub__">
|
||||
<code class="descname">__sub__</code><span class="sig-paren">(</span><em>self</em>, <em>color</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.Color.__sub__" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="sdl2.ext.Color.__mul__">
|
||||
<code class="descname">__mul__</code><span class="sig-paren">(</span><em>self</em>, <em>color</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.Color.__mul__" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="sdl2.ext.Color.__div__">
|
||||
<code class="descname">__div__</code><span class="sig-paren">(</span><em>self</em>, <em>color</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.Color.__div__" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="sdl2.ext.Color.__truediv__">
|
||||
<code class="descname">__truediv__</code><span class="sig-paren">(</span><em>self</em>, <em>color</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.Color.__truediv__" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="sdl2.ext.Color.__mod__">
|
||||
<code class="descname">__mod__</code><span class="sig-paren">(</span><em>self</em>, <em>color</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.Color.__mod__" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Basic arithmetic functions for <a class="reference internal" href="#sdl2.ext.Color" title="sdl2.ext.Color"><code class="xref py py-class docutils literal"><span class="pre">Color</span></code></a> values. The arithmetic
|
||||
operations <code class="docutils literal"><span class="pre">+,</span> <span class="pre">-,</span> <span class="pre">*,</span> <span class="pre">/,</span> <span class="pre">%</span></code> are supported by the <a class="reference internal" href="#sdl2.ext.Color" title="sdl2.ext.Color"><code class="xref py py-class docutils literal"><span class="pre">Color</span></code></a> class
|
||||
and work on a per-channel basis. This means, that the operation</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">color</span> <span class="o">=</span> <span class="n">color1</span> <span class="o">+</span> <span class="n">color2</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>is the same as</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">color</span> <span class="o">=</span> <span class="n">Color</span><span class="p">()</span>
|
||||
<span class="n">color</span><span class="o">.</span><span class="n">r</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">color1</span><span class="o">.</span><span class="n">r</span> <span class="o">+</span> <span class="n">color2</span><span class="o">.</span><span class="n">r</span><span class="p">,</span> <span class="mi">255</span><span class="p">)</span>
|
||||
<span class="n">color</span><span class="o">.</span><span class="n">g</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">color1</span><span class="o">.</span><span class="n">g</span> <span class="o">+</span> <span class="n">color2</span><span class="o">.</span><span class="n">g</span><span class="p">,</span> <span class="mi">255</span><span class="p">)</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The operations guarantee that the channel values stay in the allowed
|
||||
range of [0, 255].</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.argb_to_color">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">argb_to_color</code><span class="sig-paren">(</span><em>v : int</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.argb_to_color" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="sdl2.ext.ARGB">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">ARGB</code><span class="sig-paren">(</span><em>v : int</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.ARGB" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Converts an integer value to a Color, assuming the integer represents
|
||||
a 32-bit ARGB value.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.convert_to_color">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">convert_to_color</code><span class="sig-paren">(</span><em>v : object</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.convert_to_color" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="sdl2.ext.COLOR">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">COLOR</code><span class="sig-paren">(</span><em>v : object</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.COLOR" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Tries to convert the passed value to a Color object. The value can be
|
||||
an arbitrary Python object, which is passed to the different other
|
||||
conversion functions. If one of them succeeds, the Color will be
|
||||
returned to the caller. If none succeeds, a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> will be
|
||||
raised.</p>
|
||||
<p>If the color is an integer value, it is assumed to be in ARGB layout.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.rgba_to_color">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">rgba_to_color</code><span class="sig-paren">(</span><em>v : int</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.rgba_to_color" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="sdl2.ext.RGBA">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">RGBA</code><span class="sig-paren">(</span><em>v : int</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.RGBA" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Converts an integer value to a Color, assuming the integer represents
|
||||
a 32-bit RGBA value.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.is_rgb_color">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">is_rgb_color</code><span class="sig-paren">(</span><em>v : object</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#sdl2.ext.is_rgb_color" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Checks, if the passed value is an item that could be converted to a
|
||||
RGB color.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.is_rgba_color">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">is_rgba_color</code><span class="sig-paren">(</span><em>v : object</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#sdl2.ext.is_rgba_color" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Checks, if the passed value is an item that could be converted to a
|
||||
RGBA color.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.string_to_color">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">string_to_color</code><span class="sig-paren">(</span><em>v : string</em><span class="sig-paren">)</span> → Color<a class="headerlink" href="#sdl2.ext.string_to_color" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Converts a hex color string or color name to a Color value. Supported
|
||||
hex values are:</p>
|
||||
<ul class="simple">
|
||||
<li>#RGB</li>
|
||||
<li>#RGBA</li>
|
||||
<li>#RRGGBB</li>
|
||||
<li>#RRGGBBAA</li>
|
||||
<li>0xRGB</li>
|
||||
<li>0xRGBA</li>
|
||||
<li>0xRRGGBB</li>
|
||||
<li>0xRRGGBBAA</li>
|
||||
</ul>
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_array.html"
|
||||
title="previous chapter">Converting sequences</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_colorpalettes.html"
|
||||
title="next chapter">sdl2.ext.colorpalettes - predefined sets of colors</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_color.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_colorpalettes.html" title="sdl2.ext.colorpalettes - predefined sets of colors"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_array.html" title="Converting sequences"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,168 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>sdl2.ext.colorpalettes - predefined sets of colors — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="Initialization routines" href="sdl2ext_common.html" />
|
||||
<link rel="prev" title="Color handling" href="sdl2ext_color.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_common.html" title="Initialization routines"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_color.html" title="Color handling"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<span class="target" id="module-sdl2.ext.colorpalettes"></span><div class="section" id="sdl2-ext-colorpalettes-predefined-sets-of-colors">
|
||||
<h1>sdl2.ext.colorpalettes - predefined sets of colors<a class="headerlink" href="#sdl2-ext-colorpalettes-predefined-sets-of-colors" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Indexed color palettes. Each palette is a tuple of
|
||||
<a class="reference internal" href="sdl2ext_color.html#sdl2.ext.Color" title="sdl2.ext.Color"><code class="xref py py-class docutils literal"><span class="pre">sdl2.ext.Color</span></code></a> objects.</p>
|
||||
<p>The following palettes are currently available:</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="26%" />
|
||||
<col width="74%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr class="row-odd"><th class="head">Palette Identifier</th>
|
||||
<th class="head">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr class="row-even"><td>MONOPALETTE</td>
|
||||
<td>1-bit monochrome palette (black and white).</td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td>GRAY2PALETTE</td>
|
||||
<td>2-bit grayscale palette with black, white and two
|
||||
shades of gray.</td>
|
||||
</tr>
|
||||
<tr class="row-even"><td>GRAY4PALETTE</td>
|
||||
<td>4-bit grayscale palette with black, white and 14
|
||||
shades shades of gray.</td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td>GRAY8PALETTE</td>
|
||||
<td>8-bit grayscale palette with black, white and 254
|
||||
shades shades of gray.</td>
|
||||
</tr>
|
||||
<tr class="row-even"><td>RGB3PALETTE</td>
|
||||
<td>3-bit RGB color palette with pure red, green and
|
||||
blue and their complementary colors as well as black
|
||||
and white.</td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td>CGAPALETTE</td>
|
||||
<td>CGA color palette.</td>
|
||||
</tr>
|
||||
<tr class="row-even"><td>EGAPALETTE</td>
|
||||
<td>EGA color palette.</td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td>VGAPALETTE</td>
|
||||
<td>8-bit VGA color palette.</td>
|
||||
</tr>
|
||||
<tr class="row-even"><td>WEBPALETTE</td>
|
||||
<td>“Safe” web color palette with 225 colors.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_color.html"
|
||||
title="previous chapter">Color handling</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_common.html"
|
||||
title="next chapter">Initialization routines</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_colorpalettes.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_common.html" title="Initialization routines"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_color.html" title="Color handling"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,174 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Initialization routines — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="sdl2.ext.compat - Python compatibility helpers" href="sdl2ext_compat.html" />
|
||||
<link rel="prev" title="sdl2.ext.colorpalettes - predefined sets of colors" href="sdl2ext_colorpalettes.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_compat.html" title="sdl2.ext.compat - Python compatibility helpers"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_colorpalettes.html" title="sdl2.ext.colorpalettes - predefined sets of colors"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="initialization-routines">
|
||||
<h1>Initialization routines<a class="headerlink" href="#initialization-routines" title="Permalink to this headline">¶</a></h1>
|
||||
<p>TODO</p>
|
||||
<div class="section" id="api">
|
||||
<h2>API<a class="headerlink" href="#api" title="Permalink to this headline">¶</a></h2>
|
||||
<dl class="exception">
|
||||
<dt id="sdl2.ext.SDLError">
|
||||
<em class="property">exception </em><code class="descclassname">sdl2.ext.</code><code class="descname">SDLError</code><span class="sig-paren">(</span><em>msg=None</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.SDLError" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>An SDL2 specific <code class="xref py py-class docutils literal"><span class="pre">Exception</span></code> class. if no <em>msg</em> is provided,
|
||||
the message will be set to the value of <code class="xref py py-func docutils literal"><span class="pre">sdl2.error.SDL_GetError()</span></code></p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.init">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">init</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.init" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Initialises the underlying SDL2 video subsystem. Raises a
|
||||
<a class="reference internal" href="#sdl2.ext.SDLError" title="sdl2.ext.SDLError"><code class="xref py py-exc docutils literal"><span class="pre">SDLError</span></code></a>, if the SDL2 video subsystem could not be
|
||||
initialised.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.quit">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">quit</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.quit" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Quits the underlying SDL2 video subysystem. If no other SDL2
|
||||
subsystems are active, this will also call <a class="reference internal" href="#sdl2.ext.quit" title="sdl2.ext.quit"><code class="xref py py-func docutils literal"><span class="pre">quit()</span></code></a>,
|
||||
<code class="xref py py-func docutils literal"><span class="pre">sdl2.sdlttf.TTF_Quit()</span></code> and <code class="xref py py-func docutils literal"><span class="pre">sdl2.sdlimage.IMG_Quit()</span></code>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.get_events">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">get_events</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → [SDL_Event, SDL_Event, ...]<a class="headerlink" href="#sdl2.ext.get_events" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Gets all SDL events that are currently on the event queue.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.TestEventProcessor">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">TestEventProcessor</code><a class="headerlink" href="#sdl2.ext.TestEventProcessor" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A simple event processor for testing purposes.</p>
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.TestEventProcessor.run">
|
||||
<code class="descname">run</code><span class="sig-paren">(</span><em>window : Window</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.TestEventProcessor.run" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Starts an event loop without actually processing any event. The method
|
||||
will run endlessly until a <code class="docutils literal"><span class="pre">SDL_QUIT</span></code> event occurs.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="../index.html">Table Of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">Initialization routines</a><ul>
|
||||
<li><a class="reference internal" href="#api">API</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_colorpalettes.html"
|
||||
title="previous chapter">sdl2.ext.colorpalettes - predefined sets of colors</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_compat.html"
|
||||
title="next chapter">sdl2.ext.compat - Python compatibility helpers</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_common.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_compat.html" title="sdl2.ext.compat - Python compatibility helpers"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_colorpalettes.html" title="sdl2.ext.colorpalettes - predefined sets of colors"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,235 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>sdl2.ext.compat - Python compatibility helpers — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="2D drawing routines for software surfaces" href="sdl2ext_draw.html" />
|
||||
<link rel="prev" title="Initialization routines" href="sdl2ext_common.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_draw.html" title="2D drawing routines for software surfaces"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_common.html" title="Initialization routines"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<span class="target" id="module-sdl2.ext.compat"></span><div class="section" id="sdl2-ext-compat-python-compatibility-helpers">
|
||||
<h1>sdl2.ext.compat - Python compatibility helpers<a class="headerlink" href="#sdl2-ext-compat-python-compatibility-helpers" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The <a class="reference internal" href="#module-sdl2.ext.compat" title="sdl2.ext.compat: Python compatibility helpers."><code class="xref py py-mod docutils literal"><span class="pre">sdl2.ext.compat</span></code></a> module is for internal purposes of the <a class="reference internal" href="sdl2.html#module-sdl2" title="sdl2: SDL2 library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2</span></code></a>
|
||||
package and should not be used outside of the package. Classes, methods and
|
||||
interfaces might change between versions and there is no guarantee of API
|
||||
compatibility on different platforms and python implementations or between
|
||||
releases.</p>
|
||||
<dl class="data">
|
||||
<dt id="sdl2.ext.compat.ISPYTHON2">
|
||||
<code class="descclassname">sdl2.ext.compat.</code><code class="descname">ISPYTHON2</code><a class="headerlink" href="#sdl2.ext.compat.ISPYTHON2" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p><code class="docutils literal"><span class="pre">True</span></code>, if executed in a Python 2.x compatible interpreter, <code class="docutils literal"><span class="pre">False</span></code>
|
||||
otherwise.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="data">
|
||||
<dt id="sdl2.ext.compat.ISPYTHON3">
|
||||
<code class="descclassname">sdl2.ext.compat.</code><code class="descname">ISPYTHON3</code><a class="headerlink" href="#sdl2.ext.compat.ISPYTHON3" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p><code class="docutils literal"><span class="pre">True</span></code>, if executed in a Python 3.x compatible interpreter, <code class="docutils literal"><span class="pre">False</span></code>
|
||||
otherwise.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.compat.long">
|
||||
<code class="descclassname">sdl2.ext.compat.</code><code class="descname">long</code><span class="sig-paren">(</span><span class="optional">[</span><em>x</em><span class="optional">[</span>, <em>base</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.compat.long" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">Only defined for Python 3.x, for which it is the same as <a class="reference external" href="http://docs.python.org/library/functions.html#int" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">int()</span></code></a>.</p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.compat.unichr">
|
||||
<code class="descclassname">sdl2.ext.compat.</code><code class="descname">unichr</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.compat.unichr" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">Only defined for Python 3.x, for which it is the same as <a class="reference external" href="http://docs.python.org/library/functions.html#chr" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">chr()</span></code></a>.</p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.compat.unicode">
|
||||
<code class="descclassname">sdl2.ext.compat.</code><code class="descname">unicode</code><span class="sig-paren">(</span><em>string</em><span class="optional">[</span>, <em>encoding</em><span class="optional">[</span>, <em>errors</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.compat.unicode" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">Only defined for Python 3.x, for which it is the same as <a class="reference external" href="http://docs.python.org/library/functions.html#str" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">str()</span></code></a>.</p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.compat.callable">
|
||||
<code class="descclassname">sdl2.ext.compat.</code><code class="descname">callable</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#sdl2.ext.compat.callable" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">Only defined for Python 3.x, for which it is the same as
|
||||
<code class="docutils literal"><span class="pre">isinstance(x,</span> <span class="pre">collections.Callable)</span></code></p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.compat.byteify">
|
||||
<code class="descclassname">sdl2.ext.compat.</code><code class="descname">byteify</code><span class="sig-paren">(</span><em>x : string</em>, <em>enc : string</em><span class="sig-paren">)</span> → bytes<a class="headerlink" href="#sdl2.ext.compat.byteify" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Converts a string to a <code class="xref py py-func docutils literal"><span class="pre">bytes()</span></code> object.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.compat.stringify">
|
||||
<code class="descclassname">sdl2.ext.compat.</code><code class="descname">stringify</code><span class="sig-paren">(</span><em>x : bytes</em>, <em>enc : string</em><span class="sig-paren">)</span> → string<a class="headerlink" href="#sdl2.ext.compat.stringify" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Converts a <code class="xref py py-func docutils literal"><span class="pre">bytes()</span></code> to a string object.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.compat.isiterable">
|
||||
<code class="descclassname">sdl2.ext.compat.</code><code class="descname">isiterable</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#sdl2.ext.compat.isiterable" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Shortcut for <code class="docutils literal"><span class="pre">isinstance(x,</span> <span class="pre">collections.Iterable)</span></code>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.compat.platform_is_64bit">
|
||||
<code class="descclassname">sdl2.ext.compat.</code><code class="descname">platform_is_64bit</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → bool<a class="headerlink" href="#sdl2.ext.compat.platform_is_64bit" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Checks, if the interpreter is 64-bit capable.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.compat.deprecated">
|
||||
<code class="descclassname">@</code><code class="descclassname">sdl2.ext.compat.</code><code class="descname">deprecated</code><a class="headerlink" href="#sdl2.ext.compat.deprecated" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A simple decorator to mark functions and methods as deprecated. This will
|
||||
print a deprecation message each time the function or method is invoked.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.compat.deprecation">
|
||||
<code class="descclassname">sdl2.ext.compat.</code><code class="descname">deprecation</code><span class="sig-paren">(</span><em>message : string</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.compat.deprecation" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Prints a deprecation message using the <a class="reference external" href="http://docs.python.org/library/warnings.html#warnings.warn" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">warnings.warn()</span></code></a> function.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="exception">
|
||||
<dt id="sdl2.ext.compat.UnsupportedError">
|
||||
<em class="property">exception </em><code class="descclassname">sdl2.ext.compat.</code><code class="descname">UnsupportedError</code><span class="sig-paren">(</span><em>obj : object</em><span class="optional">[</span>, <em>msg=None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.compat.UnsupportedError" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Indicates that a certain class, function or behaviour is not supported in
|
||||
the specific execution environment.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.compat.experimental">
|
||||
<code class="descclassname">@</code><code class="descclassname">sdl2.ext.compat.</code><code class="descname">experimental</code><a class="headerlink" href="#sdl2.ext.compat.experimental" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A simple decorator to mark functions and methods as
|
||||
experimental. This will print a warning each time the function or
|
||||
method is invoked.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="exception">
|
||||
<dt id="sdl2.ext.compat.ExperimentalWarning">
|
||||
<em class="property">exception </em><code class="descclassname">sdl2.ext.compat.</code><code class="descname">ExperimentalWarning</code><span class="sig-paren">(</span><em>obj : object</em><span class="optional">[</span>, <em>msg=None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.compat.ExperimentalWarning" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Indicates that a certain class, function or behaviour is in an
|
||||
experimental state.</p>
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_common.html"
|
||||
title="previous chapter">Initialization routines</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_draw.html"
|
||||
title="next chapter">2D drawing routines for software surfaces</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_compat.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_draw.html" title="2D drawing routines for software surfaces"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_common.html" title="Initialization routines"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,163 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>2D drawing routines for software surfaces — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="Working with component-based entities" href="sdl2ext_ebs.html" />
|
||||
<link rel="prev" title="sdl2.ext.compat - Python compatibility helpers" href="sdl2ext_compat.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_ebs.html" title="Working with component-based entities"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_compat.html" title="sdl2.ext.compat - Python compatibility helpers"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="d-drawing-routines-for-software-surfaces">
|
||||
<h1>2D drawing routines for software surfaces<a class="headerlink" href="#d-drawing-routines-for-software-surfaces" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">The drawing functions within this module are unoptimised and should not be
|
||||
considered fast. If you want improved drawing of 2D primitives, including
|
||||
hardware acceleration, you should use the methods of the
|
||||
<a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.Renderer" title="sdl2.ext.Renderer"><code class="xref py py-class docutils literal"><span class="pre">Renderer</span></code></a> instead.</p>
|
||||
</div>
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.prepare_color">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">prepare_color</code><span class="sig-paren">(</span><em>color : object</em>, <em>target : object</em><span class="sig-paren">)</span> → int<a class="headerlink" href="#sdl2.ext.prepare_color" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Prepares the passed <em>color</em> for a specific <em>target</em>. <em>color</em> can be any
|
||||
object type that can be processed by
|
||||
<a class="reference internal" href="sdl2ext_color.html#sdl2.ext.convert_to_color" title="sdl2.ext.convert_to_color"><code class="xref py py-func docutils literal"><span class="pre">convert_to_color()</span></code></a>. <em>target</em> can be any
|
||||
<code class="xref py py-class docutils literal"><span class="pre">sdl2.SDL_PixelFormat</span></code>, <code class="xref py py-class docutils literal"><span class="pre">sdl2.SDL_Surface</span></code> or
|
||||
<a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SoftwareSprite" title="sdl2.ext.SoftwareSprite"><code class="xref py py-class docutils literal"><span class="pre">SoftwareSprite</span></code></a> instance.</p>
|
||||
<p>The returned integer will be a color value matching the target’s pixel
|
||||
format.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.fill">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">fill</code><span class="sig-paren">(</span><em>target : object</em>, <em>color : object</em><span class="optional">[</span>, <em>area=None</em><span class="optional">]</span><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.fill" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Fills a certain area on the passed <em>target</em> with a <em>color</em>. If no <em>area</em> is
|
||||
provided, the entire target will be filled with the passed color. If an
|
||||
iterable item is provided as <em>area</em> (such as a list or tuple), it will be
|
||||
first checked, if the item denotes a single rectangular area
|
||||
(4 integer values) before assuming it to be a sequence of rectangular areas
|
||||
to fill with the color.</p>
|
||||
<p><em>target</em> can be any <code class="xref py py-class docutils literal"><span class="pre">sdl2.SDL_Surface</span></code> or <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SoftwareSprite" title="sdl2.ext.SoftwareSprite"><code class="xref py py-class docutils literal"><span class="pre">SoftwareSprite</span></code></a>
|
||||
instance.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.line">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">line</code><span class="sig-paren">(</span><em>target : object</em>, <em>color : object</em><span class="optional">[</span>, <em>width=1</em><span class="optional">]</span><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.line" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Draws one or multiple lines on the passed <em>target</em>. <em>line</em> can be a
|
||||
sequence of four integers for a single line in the form <code class="docutils literal"><span class="pre">(x1,</span> <span class="pre">y1,</span>
|
||||
<span class="pre">x2,</span> <span class="pre">y2)</span></code> or a sequence of a multiple of 4 for drawing multiple lines
|
||||
at once, e.g. <code class="docutils literal"><span class="pre">(x1,</span> <span class="pre">y1,</span> <span class="pre">x2,</span> <span class="pre">y2,</span> <span class="pre">x3,</span> <span class="pre">y3,</span> <span class="pre">x4,</span> <span class="pre">y4,</span> <span class="pre">...)</span></code>.</p>
|
||||
<p><em>target</em> can be any <code class="xref py py-class docutils literal"><span class="pre">sdl2.SDL_Surface</span></code> or <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SoftwareSprite" title="sdl2.ext.SoftwareSprite"><code class="xref py py-class docutils literal"><span class="pre">SoftwareSprite</span></code></a>
|
||||
instance.</p>
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_compat.html"
|
||||
title="previous chapter">sdl2.ext.compat - Python compatibility helpers</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_ebs.html"
|
||||
title="next chapter">Working with component-based entities</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_draw.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_ebs.html" title="Working with component-based entities"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_compat.html" title="sdl2.ext.compat - Python compatibility helpers"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,572 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Working with component-based entities — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="General purpose event handling routines" href="sdl2ext_events.html" />
|
||||
<link rel="prev" title="2D drawing routines for software surfaces" href="sdl2ext_draw.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_events.html" title="General purpose event handling routines"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_draw.html" title="2D drawing routines for software surfaces"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="working-with-component-based-entities">
|
||||
<span id="ref-ebs"></span><h1>Working with component-based entities<a class="headerlink" href="#working-with-component-based-entities" title="Permalink to this headline">¶</a></h1>
|
||||
<p><a class="reference internal" href="sdl2ext.html#module-sdl2.ext" title="sdl2.ext: Python extensions for SDL2"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.ext</span></code></a> supports a component oriented programming pattern to separate
|
||||
object instances, carried data and processing logic within applications
|
||||
or games. It uses an entity based approach, in which object instances are
|
||||
unique identifiers, while their data is managed within components, which
|
||||
are stored separately. For each individual component type a processing
|
||||
system will take care of all necessary updates on running the application.</p>
|
||||
<div class="section" id="component-based-patterns">
|
||||
<h2>Component-based patterns<a class="headerlink" href="#component-based-patterns" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Component-based means that - instead of a traditional OOP approach - object
|
||||
information are split up into separate data bags for reusability and that those
|
||||
data bags are separated from any application logic.</p>
|
||||
<div class="section" id="behavioural-design">
|
||||
<h3>Behavioural design<a class="headerlink" href="#behavioural-design" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Imagine a car class in traditional OOP, which might look like</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Car</span><span class="p">:</span>
|
||||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="s2">"red"</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">position</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">velocity</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">sprite</span> <span class="o">=</span> <span class="n">get_some_car_image</span><span class="p">()</span>
|
||||
<span class="o">...</span>
|
||||
<span class="k">def</span> <span class="nf">drive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timedelta</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">position</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocity</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">timedelta</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">position</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocity</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">timedelta</span>
|
||||
<span class="o">...</span>
|
||||
<span class="k">def</span> <span class="nf">stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">velocity</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
|
||||
<span class="o">...</span>
|
||||
<span class="k">def</span> <span class="nf">render</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">screen</span><span class="p">):</span>
|
||||
<span class="n">screen</span><span class="o">.</span><span class="n">display</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sprite</span><span class="p">)</span>
|
||||
|
||||
<span class="n">mycar</span> <span class="o">=</span> <span class="n">new</span> <span class="n">Car</span><span class="p">()</span>
|
||||
<span class="n">mycar</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="s2">"green"</span>
|
||||
<span class="n">mycar</span><span class="o">.</span><span class="n">velocity</span> <span class="o">=</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">0</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The car features information stored in attributes (<code class="docutils literal"><span class="pre">color</span></code>, <code class="docutils literal"><span class="pre">position</span></code>,
|
||||
...) and behaviour (application logic, <code class="docutils literal"><span class="pre">drive()</span></code>, <code class="docutils literal"><span class="pre">stop()</span></code> ...).</p>
|
||||
<p>A component-based approach aims to split and reduce the car to a set of
|
||||
information and external systems providing the application logic.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Car</span><span class="p">:</span>
|
||||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="s2">"red"</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">position</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">velocity</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">sprite</span> <span class="o">=</span> <span class="n">get_some_car_image</span><span class="p">()</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CarMovement</span><span class="p">:</span>
|
||||
<span class="k">def</span> <span class="nf">drive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">car</span><span class="p">,</span> <span class="n">timedelta</span><span class="p">):</span>
|
||||
<span class="n">car</span><span class="o">.</span><span class="n">position</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">car</span><span class="o">.</span><span class="n">velocity</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">timedelta</span>
|
||||
<span class="n">car</span><span class="o">.</span><span class="n">position</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">car</span><span class="o">.</span><span class="n">velocity</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">timedelta</span>
|
||||
<span class="o">...</span>
|
||||
<span class="k">def</span> <span class="nf">stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="n">car</span><span class="o">.</span><span class="n">velocity</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CarRenderer</span><span class="p">:</span>
|
||||
<span class="k">def</span> <span class="nf">render</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">car</span><span class="p">,</span> <span class="n">screen</span><span class="p">):</span>
|
||||
<span class="n">screen</span><span class="o">.</span><span class="n">display</span><span class="p">(</span><span class="n">car</span><span class="o">.</span><span class="n">sprite</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>At this point of time, there is no notable difference between both approaches,
|
||||
except that the latter one adds additional overhead.</p>
|
||||
<p>The benefit comes in, when you</p>
|
||||
<ul class="simple">
|
||||
<li>use subclassing in your OOP design</li>
|
||||
<li>want to change behavioural patterns on a global scale or based on states</li>
|
||||
<li>want to refactor code logic in central locations</li>
|
||||
<li>want to cascade application behaviours</li>
|
||||
</ul>
|
||||
<p>The initial <code class="docutils literal"><span class="pre">Car</span></code> class from above defines, how it should be displayed
|
||||
on the screen. If you now want to add a feature for rescaling the screen
|
||||
size after the user activates the magnifier mode, you need to refactor
|
||||
the <code class="docutils literal"><span class="pre">Car</span></code> and all other classes that render things on the screen, have
|
||||
to consider all subclasses that override the method and so on.
|
||||
Refactoring the <code class="docutils literal"><span class="pre">CarRenderer</span></code> code by adding a check for the magnifier
|
||||
mode sounds quite simple in contrast to that, not?</p>
|
||||
<p>The same applies to the movement logic - inverting the movement logic
|
||||
requires you to refactor all your classes instead of a single piece of
|
||||
application code.</p>
|
||||
</div>
|
||||
<div class="section" id="information-design">
|
||||
<h3>Information design<a class="headerlink" href="#information-design" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Subclassing with traditional OOP for behavioural changes also might
|
||||
bloat your classes with unnecessary information, causing the memory
|
||||
footprint for your application to rise without any need. Let’s assume
|
||||
you have a <code class="docutils literal"><span class="pre">Truck</span></code> class that inherits from <code class="docutils literal"><span class="pre">Car</span></code>. Let’s further
|
||||
assume that all trucks in your application look the same. Why should any
|
||||
of those carry a <code class="docutils literal"><span class="pre">sprite</span></code> or <code class="docutils literal"><span class="pre">color</span></code> attribute? You would need to
|
||||
refactor your <code class="docutils literal"><span class="pre">Car</span></code> class to get rid of those superfluous information,
|
||||
adding another level of subclassing. If at a later point of time you
|
||||
decide to give your trucks different colors, you need to refactor
|
||||
everything again.</p>
|
||||
<p>Wouldn’t it be easier to deal with colors, if they are available on the
|
||||
truck and leave them out, if they are not? We initially stated that the
|
||||
component-based approach aims to separate data (information) from code
|
||||
logic. That said, if the truck has a color, we can handle it easily, if
|
||||
it has not, we will do as usual.</p>
|
||||
<p>Also, checking for the color of an object (regardless, if it is a truck,
|
||||
car, aeroplane or death star) allows us to apply the same or similar
|
||||
behaviour for every object. If the information is available, we will
|
||||
process it, if it is not, we will not do anything.</p>
|
||||
</div>
|
||||
<div class="section" id="all-in-all">
|
||||
<h3>All in all<a class="headerlink" href="#all-in-all" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Once we split up the previously OOP-style classes into pure data containers and
|
||||
some separate processing code for the behaviour, we are talking about components
|
||||
and (processing) systems. A component is a data container, ideally grouping
|
||||
related information on a granular level, so that it is easy to (re)use.
|
||||
When you combine different components to build your in-application objects and
|
||||
instantiate those, we are talking about entities.</p>
|
||||
<img alt="../_images/ebs.png" src="../_images/ebs.png" />
|
||||
<dl class="docutils">
|
||||
<dt><em>Component</em></dt>
|
||||
<dd>provides information (data bag)</dd>
|
||||
<dt><em>Entity</em></dt>
|
||||
<dd>In-application instance that consists of <em>component</em> items</dd>
|
||||
<dt><em>System</em></dt>
|
||||
<dd>Application logic for working with <em>Entity</em> items and their
|
||||
<em>component</em> data</dd>
|
||||
<dt><em>World</em></dt>
|
||||
<dd>The environment that contains the different <em>System</em> instances and
|
||||
all <em>Entity</em> items with their <em>component</em> data</dd>
|
||||
</dl>
|
||||
<p>Within a strict COP design, the application logic (ideally) only knows about
|
||||
data to process. It does not know anything about entities or complex classes
|
||||
and only operates on the data.</p>
|
||||
<img alt="../_images/copprocessing.png" src="../_images/copprocessing.png" />
|
||||
<p>To keep things simple, modular and easy to maintain and change, you usually
|
||||
create small processing systems, which perform the necessary operations on the
|
||||
data they shall handle. That said, a <code class="docutils literal"><span class="pre">MovementSystem</span></code> for our car entity would
|
||||
only operate on the position and velocity component of the car entity. It does
|
||||
not know anything about the the car’s sprite or sounds that the car makes,
|
||||
since <em>this is nothing it has to deal with</em>.</p>
|
||||
<p>To display the car on the screen, a <code class="docutils literal"><span class="pre">RenderingSystem</span></code> might pick up the
|
||||
sprite component of the car, maybe along with the position information (so it
|
||||
knows, where to place the sprite) and render it on the screen.</p>
|
||||
<p>If you want the car to play sounds, you would add an audio playback system,
|
||||
that can perform the task. Afterwards you can add the necessary audio
|
||||
information via a sound component to the car and it will make noise.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="component-based-design-with-sdl2-ext">
|
||||
<h2>Component-based design with sdl2.ext<a class="headerlink" href="#component-based-design-with-sdl2-ext" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">This section will deal with the specialities of COP patterns and
|
||||
provide the bare minimum of information. If you are just starting with
|
||||
such a design, it is recommended to read through the <a class="reference internal" href="../tutorial/pong.html#pong-tutorial"><span class="std std-ref">The Pong Game</span></a>
|
||||
tutorial.</p>
|
||||
</div>
|
||||
<p><a class="reference internal" href="sdl2ext.html#module-sdl2.ext" title="sdl2.ext: Python extensions for SDL2"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.ext</span></code></a> provides a <a class="reference internal" href="#sdl2.ext.World" title="sdl2.ext.World"><code class="xref py py-class docutils literal"><span class="pre">World</span></code></a> class in which all other objects
|
||||
will reside. The <a class="reference internal" href="#sdl2.ext.World" title="sdl2.ext.World"><code class="xref py py-class docutils literal"><span class="pre">World</span></code></a> will maintain both, <a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a> and
|
||||
component items, and allows you to set up the processing logic via
|
||||
the <a class="reference internal" href="#sdl2.ext.System" title="sdl2.ext.System"><code class="xref py py-class docutils literal"><span class="pre">System</span></code></a> and <a class="reference internal" href="#sdl2.ext.Applicator" title="sdl2.ext.Applicator"><code class="xref py py-class docutils literal"><span class="pre">Applicator</span></code></a> classes.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">appworld</span> <span class="o">=</span> <span class="n">World</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Components can be created from any class that inherits from the
|
||||
<code class="xref py py-class docutils literal"><span class="pre">object</span></code> type and represent the data bag of information for the
|
||||
entity and application world. Ideally, they should avoid any
|
||||
application logic (except from getter and setter properties).</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Position2D</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">x</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">y</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p><a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a> objects define the in-application objects and only consist of
|
||||
component-based attributes. They also require a <a class="reference internal" href="#sdl2.ext.World" title="sdl2.ext.World"><code class="xref py py-class docutils literal"><span class="pre">World</span></code></a> at
|
||||
object instantiation time.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CarEntity</span><span class="p">(</span><span class="n">Entity</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">world</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">position2d</span> <span class="o">=</span> <span class="n">Position2D</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">The <em>world</em> argument in <code class="docutils literal"><span class="pre">__init__()</span></code> is necessary. It will be
|
||||
passed to the internal <code class="docutils literal"><span class="pre">__new__()</span></code> constructor of the
|
||||
<a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a> and stores a reference to the <a class="reference internal" href="#sdl2.ext.World" title="sdl2.ext.World"><code class="xref py py-class docutils literal"><span class="pre">World</span></code></a> and also
|
||||
allows the <a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a> to store its information in the
|
||||
<a class="reference internal" href="#sdl2.ext.World" title="sdl2.ext.World"><code class="xref py py-class docutils literal"><span class="pre">World</span></code></a>.</p>
|
||||
</div>
|
||||
<p>The <a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a> also requries its attributes to be named exactly as
|
||||
their component class name, but in lowercase letters. If you name a
|
||||
component <code class="docutils literal"><span class="pre">MyAbsolutelyAwesomeDataContainer</span></code>, an <a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a> will
|
||||
force you to write the following:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">SomeEntity</span><span class="p">(</span><span class="n">Entity</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">world</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">myabsolutelyawesomedatacontainer</span> <span class="o">=</span> <span class="n">MyAbsolutelyAwesomeDataContainer</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p>This is not entirely true. A reference of the object will be stored on a
|
||||
per-class-in-mro basis. This means that if <code class="docutils literal"><span class="pre">MyAbsolutelyAwesomeDataContainer</span></code>
|
||||
inherits from <code class="docutils literal"><span class="pre">ShortName</span></code>, you can also do:</p>
|
||||
<div class="last highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">SomeEntity</span><span class="p">(</span><span class="n">Entity</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">world</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="n">MyAbsolutelyAwesomeDataContainer</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<p>Components should be as atomic as possible and avoid complex
|
||||
inheritance. Since each value of an <a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a> is stored per class
|
||||
in its mro list, components inheriting from the same class(es) will
|
||||
overwrite each other on conflicting classes:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Vector</span><span class="p">(</span><span class="n">Position2D</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">z</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
||||
<span class="nb">super</span><span class="p">(</span><span class="n">Vector</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
|
||||
|
||||
|
||||
<span class="k">class</span> <span class="nc">SomeEntity</span><span class="p">(</span><span class="n">Entity</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">world</span><span class="p">):</span>
|
||||
<span class="c1"># This will associate self.position2d with the new Position2D</span>
|
||||
<span class="c1"># value, while the previous Vector association is overwritten</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">position2d</span> <span class="o">=</span> <span class="n">Position2D</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
|
||||
|
||||
<span class="c1"># self.vector will also associate a self.position2d attribute</span>
|
||||
<span class="c1"># with the Entity, since Vector inherits from Position2D. The</span>
|
||||
<span class="c1"># original association will vanish, and each call to</span>
|
||||
<span class="c1"># entity.position2d will effectively manipulate the vector!</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">vector</span> <span class="o">=</span> <span class="n">Vector</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="api">
|
||||
<h2>API<a class="headerlink" href="#api" title="Permalink to this headline">¶</a></h2>
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.Entity">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">Entity</code><span class="sig-paren">(</span><em>world : World</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.Entity" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><blockquote>
|
||||
<div><p>An entity is a specific object living in the application world. It
|
||||
does not carry any data or application logic, but merely acts as
|
||||
identifier label for data that is maintained in the application
|
||||
world itself.</p>
|
||||
<p>As such, it is a composition of components, which would not exist
|
||||
without the entity identifier. The entity itself is non-existent to
|
||||
the application world as long as it does not carry any data that can
|
||||
be processed by a system within the application world.</p>
|
||||
</div></blockquote>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Entity.id">
|
||||
<code class="descname">id</code><a class="headerlink" href="#sdl2.ext.Entity.id" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The id of the Entity. Every Entity has a unique id, that is
|
||||
represented by a <a class="reference external" href="http://docs.python.org/library/uuid.html#uuid.UUID" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">uuid.UUID</span></code></a> instance.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Entity.world">
|
||||
<code class="descname">world</code><a class="headerlink" href="#sdl2.ext.Entity.world" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The <a class="reference internal" href="#sdl2.ext.World" title="sdl2.ext.World"><code class="xref py py-class docutils literal"><span class="pre">World</span></code></a> the entity resides in.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.Entity.delete">
|
||||
<code class="descname">delete</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.Entity.delete" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Deletes the <a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a> from its <a class="reference internal" href="#sdl2.ext.World" title="sdl2.ext.World"><code class="xref py py-class docutils literal"><span class="pre">World</span></code></a>. This
|
||||
basically calls <a class="reference internal" href="#sdl2.ext.World.delete" title="sdl2.ext.World.delete"><code class="xref py py-meth docutils literal"><span class="pre">World.delete()</span></code></a> with the <a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.Applicator">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">Applicator</code><a class="headerlink" href="#sdl2.ext.Applicator" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A processing system for combined data sets. The <a class="reference internal" href="#sdl2.ext.Applicator" title="sdl2.ext.Applicator"><code class="xref py py-class docutils literal"><span class="pre">Applicator</span></code></a>
|
||||
is an enhanced <a class="reference internal" href="#sdl2.ext.System" title="sdl2.ext.System"><code class="xref py py-class docutils literal"><span class="pre">System</span></code></a> that receives combined data sets based
|
||||
on its set <a class="reference internal" href="#sdl2.ext.System.componenttypes" title="sdl2.ext.System.componenttypes"><code class="xref py py-attr docutils literal"><span class="pre">System.componenttypes</span></code></a></p>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Applicator.is_applicator">
|
||||
<code class="descname">is_applicator</code><a class="headerlink" href="#sdl2.ext.Applicator.is_applicator" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A boolean flag indicating that this class operates on combined data sets.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.Applicator.componenttypes">
|
||||
<code class="descname">componenttypes</code><a class="headerlink" href="#sdl2.ext.Applicator.componenttypes" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A tuple of class identifiers that shall be processed by the
|
||||
<a class="reference internal" href="#sdl2.ext.Applicator" title="sdl2.ext.Applicator"><code class="xref py py-class docutils literal"><span class="pre">Applicator</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.Applicator.process">
|
||||
<code class="descname">process</code><span class="sig-paren">(</span><em>world : World</em>, <em>componentsets : iterable</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.Applicator.process" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Processes tuples of component items. <em>componentsets</em> will
|
||||
contain object tuples, that match the <a class="reference internal" href="#sdl2.ext.Applicator.componenttypes" title="sdl2.ext.Applicator.componenttypes"><code class="xref py py-attr docutils literal"><span class="pre">componenttypes</span></code></a>
|
||||
of the <a class="reference internal" href="#sdl2.ext.Applicator" title="sdl2.ext.Applicator"><code class="xref py py-class docutils literal"><span class="pre">Applicator</span></code></a>. If, for example, the <a class="reference internal" href="#sdl2.ext.Applicator" title="sdl2.ext.Applicator"><code class="xref py py-class docutils literal"><span class="pre">Applicator</span></code></a>
|
||||
is defined as</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyApplicator</span><span class="p">(</span><span class="n">Applicator</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">componenttypes</span> <span class="o">=</span> <span class="p">(</span><span class="n">Foo</span><span class="p">,</span> <span class="n">Bar</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>its process method will receive <code class="docutils literal"><span class="pre">(Foo,</span> <span class="pre">Bar)</span></code> tuples</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">process</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">world</span><span class="p">,</span> <span class="n">componentsets</span><span class="p">):</span>
|
||||
<span class="k">for</span> <span class="n">foo_item</span><span class="p">,</span> <span class="n">bar_item</span> <span class="ow">in</span> <span class="n">componentsets</span><span class="p">:</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Additionally, the <a class="reference internal" href="#sdl2.ext.Applicator" title="sdl2.ext.Applicator"><code class="xref py py-class docutils literal"><span class="pre">Applicator</span></code></a> will not process all possible
|
||||
combinations of valid components, but only those, which are associated
|
||||
with the same <a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a>. That said, an <a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a> <em>must</em>
|
||||
contain a <code class="docutils literal"><span class="pre">Foo</span></code> as well as a <code class="docutils literal"><span class="pre">Bar</span></code> component in order to
|
||||
have them both processed by the <a class="reference internal" href="#sdl2.ext.Applicator" title="sdl2.ext.Applicator"><code class="xref py py-class docutils literal"><span class="pre">Applicator</span></code></a> (while a
|
||||
<a class="reference internal" href="#sdl2.ext.System" title="sdl2.ext.System"><code class="xref py py-class docutils literal"><span class="pre">System</span></code></a> with the same <code class="docutils literal"><span class="pre">componenttypes</span></code> would pick either of
|
||||
them, depending on their availability).</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.System">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">System</code><a class="headerlink" href="#sdl2.ext.System" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A processing system within an application world consumes the
|
||||
components of all entities, for which it was set up. At time of
|
||||
processing, the system does not know about any other component type
|
||||
that might be bound to any entity.</p>
|
||||
<p>Also, the processing system does not know about any specific entity,
|
||||
but only is aware of the data carried by all entities.</p>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.System.componenttypes">
|
||||
<code class="descname">componenttypes</code><a class="headerlink" href="#sdl2.ext.System.componenttypes" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A tuple of class identifiers that shall be processed by the
|
||||
<a class="reference internal" href="#sdl2.ext.System" title="sdl2.ext.System"><code class="xref py py-class docutils literal"><span class="pre">System</span></code></a></p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.System.process">
|
||||
<code class="descname">process</code><span class="sig-paren">(</span><em>world : World</em>, <em>components : iterable</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.System.process" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Processes component items.</p>
|
||||
<p>This method has to be implemented by inheriting classes.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.World">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">World</code><a class="headerlink" href="#sdl2.ext.World" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>An application world defines the combination of application data and
|
||||
processing logic and how the data will be processed. As such, it is a
|
||||
container object in which the application is defined.</p>
|
||||
<p>The application world maintains a set of entities and their related
|
||||
components as well as a set of systems that process the data of the
|
||||
entities. Each processing system within the application world only
|
||||
operates on a certain set of components, but not all components of an
|
||||
entity at once.</p>
|
||||
<p>The order in which data is processed depends on the order of the
|
||||
added systems.</p>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.World.systems">
|
||||
<code class="descname">systems</code><a class="headerlink" href="#sdl2.ext.World.systems" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The processing system objects bound to the world.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.World.add_system">
|
||||
<code class="descname">add_system</code><span class="sig-paren">(</span><em>system : object</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.World.add_system" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Adds a processing system to the world. The system will be
|
||||
added as last item in the processing order.</p>
|
||||
<p>The passed system does not have to inherit from <a class="reference internal" href="#sdl2.ext.System" title="sdl2.ext.System"><code class="xref py py-class docutils literal"><span class="pre">System</span></code></a>, but
|
||||
must feature a <code class="docutils literal"><span class="pre">componenttypes</span></code> attribute and a <code class="docutils literal"><span class="pre">process()</span></code> method,
|
||||
which match the signatures of the <a class="reference internal" href="#sdl2.ext.System" title="sdl2.ext.System"><code class="xref py py-class docutils literal"><span class="pre">System</span></code></a> class</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MySystem</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="c1"># componenttypes can be any iterable as long as it</span>
|
||||
<span class="c1"># contains the classes the system should take care of</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">componenttypes</span> <span class="o">=</span> <span class="p">[</span><span class="n">AClass</span><span class="p">,</span> <span class="n">AnotherClass</span><span class="p">,</span> <span class="o">...</span><span class="p">]</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">process</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">world</span><span class="p">,</span> <span class="n">components</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>If the system shall operate on combined component sets as specified
|
||||
by the <a class="reference internal" href="#sdl2.ext.Applicator" title="sdl2.ext.Applicator"><code class="xref py py-class docutils literal"><span class="pre">Applicator</span></code></a>, the class instance must contain a
|
||||
<code class="docutils literal"><span class="pre">is_applicator</span></code> property, that evaluates to <code class="docutils literal"><span class="pre">True</span></code></p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyApplicator</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">is_applicator</span> <span class="o">=</span> <span class="kc">True</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">componenttypes</span> <span class="o">=</span> <span class="p">[</span><span class="o">...</span><span class="p">]</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">process</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">world</span><span class="p">,</span> <span class="n">components</span><span class="p">):</span>
|
||||
<span class="k">pass</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The behaviour can be changed at run-time. The <code class="docutils literal"><span class="pre">is_applicator</span></code> attribute
|
||||
is evaluated for every call to <a class="reference internal" href="#sdl2.ext.World.process" title="sdl2.ext.World.process"><code class="xref py py-meth docutils literal"><span class="pre">World.process()</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.World.delete">
|
||||
<code class="descname">delete</code><span class="sig-paren">(</span><em>entity : Entity</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.World.delete" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Removes an <a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a> from the World, including all its
|
||||
component data.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.World.delete_entities">
|
||||
<code class="descname">delete_entities</code><span class="sig-paren">(</span><em>entities : iterable</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.World.delete_entities" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Removes a set of <a class="reference internal" href="#sdl2.ext.Entity" title="sdl2.ext.Entity"><code class="xref py py-class docutils literal"><span class="pre">Entity</span></code></a> instances from the World,
|
||||
including all their component data.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.World.insert_system">
|
||||
<code class="descname">insert_system</code><span class="sig-paren">(</span><em>index : int</em>, <em>system : System</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.World.insert_system" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Adds a processing <a class="reference internal" href="#sdl2.ext.System" title="sdl2.ext.System"><code class="xref py py-class docutils literal"><span class="pre">System</span></code></a> to the world. The system will be
|
||||
added at the specified position in the processing order.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.World.get_entities">
|
||||
<code class="descname">get_entities</code><span class="sig-paren">(</span><em>component : object</em><span class="sig-paren">)</span> → [Entity, ...]<a class="headerlink" href="#sdl2.ext.World.get_entities" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Gets the entities using the passed component.</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">This will not perform an identity check on the component
|
||||
but rely on its <code class="docutils literal"><span class="pre">__eq__</span></code> implementation instead.</p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.World.process">
|
||||
<code class="descname">process</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.World.process" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Processes all component items within their corresponding
|
||||
<a class="reference internal" href="#sdl2.ext.System" title="sdl2.ext.System"><code class="xref py py-class docutils literal"><span class="pre">System</span></code></a> instances.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.World.remove_system">
|
||||
<code class="descname">remove_system</code><span class="sig-paren">(</span><em>system : System</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.World.remove_system" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Removes a processing <a class="reference internal" href="#sdl2.ext.System" title="sdl2.ext.System"><code class="xref py py-class docutils literal"><span class="pre">System</span></code></a> from the world.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="../index.html">Table Of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">Working with component-based entities</a><ul>
|
||||
<li><a class="reference internal" href="#component-based-patterns">Component-based patterns</a><ul>
|
||||
<li><a class="reference internal" href="#behavioural-design">Behavioural design</a></li>
|
||||
<li><a class="reference internal" href="#information-design">Information design</a></li>
|
||||
<li><a class="reference internal" href="#all-in-all">All in all</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference internal" href="#component-based-design-with-sdl2-ext">Component-based design with sdl2.ext</a></li>
|
||||
<li><a class="reference internal" href="#api">API</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_draw.html"
|
||||
title="previous chapter">2D drawing routines for software surfaces</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_events.html"
|
||||
title="next chapter">General purpose event handling routines</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_ebs.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_events.html" title="General purpose event handling routines"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_draw.html" title="2D drawing routines for software surfaces"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,209 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>General purpose event handling routines — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="Text rendering routines" href="sdl2ext_font.html" />
|
||||
<link rel="prev" title="Working with component-based entities" href="sdl2ext_ebs.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_font.html" title="Text rendering routines"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_ebs.html" title="Working with component-based entities"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="general-purpose-event-handling-routines">
|
||||
<h1>General purpose event handling routines<a class="headerlink" href="#general-purpose-event-handling-routines" title="Permalink to this headline">¶</a></h1>
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.EventHandler">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">EventHandler</code><span class="sig-paren">(</span><em>sender</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.EventHandler" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A simple event handling class, which manages callbacks to be
|
||||
executed.</p>
|
||||
<p>The EventHandler does not need to be kept as separate instance, but
|
||||
is mainly intended to be used as attribute in event-aware class
|
||||
objects.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">myfunc</span><span class="p">(</span><span class="n">sender</span><span class="p">):</span>
|
||||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">"event triggered by </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">sender</span><span class="p">)</span>
|
||||
<span class="gp">...</span>
|
||||
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">MyClass</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
|
||||
<span class="gp">... </span> <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">anevent</span> <span class="o">=</span> <span class="n">EventHandler</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
|
||||
<span class="gp">...</span>
|
||||
<span class="gp">>>> </span><span class="n">myobj</span> <span class="o">=</span> <span class="n">MyClass</span><span class="p">()</span>
|
||||
<span class="gp">>>> </span><span class="n">myobj</span><span class="o">.</span><span class="n">anevent</span> <span class="o">+=</span> <span class="n">myfunc</span>
|
||||
<span class="gp">>>> </span><span class="n">myobj</span><span class="o">.</span><span class="n">anevent</span><span class="p">()</span>
|
||||
<span class="go">event triggered by <__main__.MyClass object at 0x801864e50></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.EventHandler.callbacks">
|
||||
<code class="descname">callbacks</code><a class="headerlink" href="#sdl2.ext.EventHandler.callbacks" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A list of callbacks currently bound to the <a class="reference internal" href="#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.EventHandler.sender">
|
||||
<code class="descname">sender</code><a class="headerlink" href="#sdl2.ext.EventHandler.sender" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The responsible object that executes the <a class="reference internal" href="#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.EventHandler.add">
|
||||
<code class="descname">add</code><span class="sig-paren">(</span><em>callback : Callable</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.EventHandler.add" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Adds a callback to the <a class="reference internal" href="#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.EventHandler.remove">
|
||||
<code class="descname">remove</code><span class="sig-paren">(</span><em>callback : Callable</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.EventHandler.remove" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Removes a callback from the <a class="reference internal" href="#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.EventHandler.__call__">
|
||||
<code class="descname">__call__</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span> → [ ... ]<a class="headerlink" href="#sdl2.ext.EventHandler.__call__" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Executes all connected callbacks in the order of addition,
|
||||
passing the <a class="reference internal" href="#sdl2.ext.EventHandler.sender" title="sdl2.ext.EventHandler.sender"><code class="xref py py-attr docutils literal"><span class="pre">sender</span></code></a> of the <a class="reference internal" href="#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> as first
|
||||
argument and the optional args as second, third, ... argument to
|
||||
them.</p>
|
||||
<p>This will return a list containing the return values of the callbacks
|
||||
in the order of their execution.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.MPEventHandler">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">MPEventHandler</code><span class="sig-paren">(</span><em>sender</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.MPEventHandler" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>An asynchronous event handling class based on <a class="reference internal" href="#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a>,
|
||||
in which callbacks are executed in parallel. It is the responsibility
|
||||
of the caller code to ensure that every object used maintains a
|
||||
consistent state. The <a class="reference internal" href="#sdl2.ext.MPEventHandler" title="sdl2.ext.MPEventHandler"><code class="xref py py-class docutils literal"><span class="pre">MPEventHandler</span></code></a> class will not apply
|
||||
any locks, synchronous state changes or anything else to the
|
||||
arguments or callbacks being used. Consider it a “fire-and-forget” event
|
||||
handling strategy.</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p>The <a class="reference internal" href="#sdl2.ext.MPEventHandler" title="sdl2.ext.MPEventHandler"><code class="xref py py-class docutils literal"><span class="pre">MPEventHandler</span></code></a> relies on the <a class="reference external" href="http://docs.python.org/library/multiprocessing.html#module-multiprocessing" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">multiprocessing</span></code></a>
|
||||
module. If the module is not available in the target environment,
|
||||
a <a class="reference internal" href="sdl2ext_compat.html#sdl2.ext.compat.UnsupportedError" title="sdl2.ext.compat.UnsupportedError"><code class="xref py py-exc docutils literal"><span class="pre">sdl2.ext.compat.UnsupportedError</span></code></a> is raised.</p>
|
||||
<p class="last">Also, please be aware of the restrictions that apply to the
|
||||
<a class="reference external" href="http://docs.python.org/library/multiprocessing.html#module-multiprocessing" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">multiprocessing</span></code></a> module; arguments and callback functions for
|
||||
example have to be pickable, etc.</p>
|
||||
</div>
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.MPEventHandler.__call__">
|
||||
<code class="descname">__call__</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span> → AsyncResult<a class="headerlink" href="#sdl2.ext.MPEventHandler.__call__" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Executes all connected callbacks within a
|
||||
<code class="xref py py-class docutils literal"><span class="pre">multiprocessing.pool.Pool</span></code>, passing the <code class="xref py py-attr docutils literal"><span class="pre">sender</span></code> as first
|
||||
argument and the optional <em>args</em> as second, third, ... argument to them.</p>
|
||||
<p>This will return a <a class="reference external" href="http://docs.python.org/library/multiprocessing.html#multiprocessing.pool.AsyncResult" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">multiprocessing.pool.AsyncResult</span></code></a> containing
|
||||
the return values of the callbacks in the order of their execution.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_ebs.html"
|
||||
title="previous chapter">Working with component-based entities</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_font.html"
|
||||
title="next chapter">Text rendering routines</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_events.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_font.html" title="Text rendering routines"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_ebs.html" title="Working with component-based entities"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,261 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Text rendering routines — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="User interface elements" href="sdl2ext_gui.html" />
|
||||
<link rel="prev" title="General purpose event handling routines" href="sdl2ext_events.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_gui.html" title="User interface elements"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_events.html" title="General purpose event handling routines"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="text-rendering-routines">
|
||||
<h1>Text rendering routines<a class="headerlink" href="#text-rendering-routines" title="Permalink to this headline">¶</a></h1>
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.BitmapFont">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">BitmapFont</code><span class="sig-paren">(</span><em>surface : Sprite, size : iterable[, mapping=None</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.BitmapFont" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A bitmap graphics to character mapping. The <a class="reference internal" href="#sdl2.ext.BitmapFont" title="sdl2.ext.BitmapFont"><code class="xref py py-class docutils literal"><span class="pre">BitmapFont</span></code></a> class
|
||||
uses an image <em>surface</em> to find and render font character glyphs for
|
||||
text. It requires a mapping table, which denotes the characters
|
||||
available on the image.</p>
|
||||
<p>The mapping table is a list of strings, where each string reflects a
|
||||
<em>line</em> of characters on the image. Each character within each line
|
||||
has the same size as specified by the size argument.</p>
|
||||
<p>A typical mapping table might look like</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">[</span> <span class="s1">'0123456789'</span><span class="p">,</span>
|
||||
<span class="s1">'ABCDEFGHIJ'</span><span class="p">,</span>
|
||||
<span class="s1">'KLMNOPQRST'</span><span class="p">,</span>
|
||||
<span class="s1">'UVWXYZ '</span><span class="p">,</span>
|
||||
<span class="s1">'abcdefghij'</span><span class="p">,</span>
|
||||
<span class="s1">'klmnopqrst'</span><span class="p">,</span>
|
||||
<span class="s1">'uvwxyz '</span><span class="p">,</span>
|
||||
<span class="s1">',;.:!?+-()'</span> <span class="p">]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.BitmapFont.surface">
|
||||
<code class="descname">surface</code><a class="headerlink" href="#sdl2.ext.BitmapFont.surface" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The <code class="xref py py-class docutils literal"><span class="pre">sdl2.SDL_Surface</span></code> containing the character bitmaps.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.BitmapFont.offsets">
|
||||
<code class="descname">offsets</code><a class="headerlink" href="#sdl2.ext.BitmapFont.offsets" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A dict containing the character offsets on the <a class="reference internal" href="#sdl2.ext.BitmapFont.surface" title="sdl2.ext.BitmapFont.surface"><code class="xref py py-attr docutils literal"><span class="pre">surface</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.BitmapFont.mapping">
|
||||
<code class="descname">mapping</code><a class="headerlink" href="#sdl2.ext.BitmapFont.mapping" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The character mapping table, a list of strings.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.BitmapFont.size">
|
||||
<code class="descname">size</code><a class="headerlink" href="#sdl2.ext.BitmapFont.size" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The size of an individual glyph bitmap on the font.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.BitmapFont.render">
|
||||
<code class="descname">render</code><span class="sig-paren">(</span><em>text : string</em><span class="optional">[</span>, <em>bpp=None</em><span class="optional">]</span><span class="sig-paren">)</span> → Sprite<a class="headerlink" href="#sdl2.ext.BitmapFont.render" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Renders the passed text on a new <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.Sprite" title="sdl2.ext.Sprite"><code class="xref py py-class docutils literal"><span class="pre">Sprite</span></code></a> and returns it.
|
||||
If no explicit <em>bpp</em> are provided, the bpp settings of the
|
||||
<a class="reference internal" href="#sdl2.ext.BitmapFont.surface" title="sdl2.ext.BitmapFont.surface"><code class="xref py py-attr docutils literal"><span class="pre">surface</span></code></a> are used.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.BitmapFont.render_on">
|
||||
<code class="descname">render_on</code><span class="sig-paren">(</span><em>surface : Sprite, text : string[, offset=(0, 0)]) -> (int, int, int, int</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.BitmapFont.render_on" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Renders a text on the passed sprite, starting at a specific
|
||||
offset. The top-left start position of the text will be the
|
||||
passed <em>offset</em> and a 4-value tuple with the changed area will be
|
||||
returned.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.BitmapFont.contains">
|
||||
<code class="descname">contains</code><span class="sig-paren">(</span><em>c : string</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#sdl2.ext.BitmapFont.contains" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Checks, whether a certain character exists in the font.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.BitmapFont.can_render">
|
||||
<code class="descname">can_render</code><span class="sig-paren">(</span><em>text : string</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#sdl2.ext.BitmapFont.can_render" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Checks, whether all characters in the passed <em>text</em> can be rendered.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.FontManager">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">FontManager</code><span class="sig-paren">(</span><em>font_path : str</em><span class="optional">[</span>, <em>alias=None</em><span class="optional">[</span>, <em>size=16</em><span class="optional">[</span>, <em>color=Color(255</em>, <em>255</em>, <em>255)</em><span class="optional">[</span>, <em>bg_color=Color(0</em>, <em>0</em>, <em>0)</em><span class="optional">[</span>, <em>index=0</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.FontManager" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Manage fonts and rendering of text.</p>
|
||||
<p>One font path must be given to initialise the FontManager.
|
||||
<a class="reference internal" href="#sdl2.ext.FontManager.default_font" title="sdl2.ext.FontManager.default_font"><code class="xref py py-attr docutils literal"><span class="pre">default_font</span></code></a> will be set to this font. <em>size</em> is the default
|
||||
font size in pixels. <em>color</em> and <em>bg_color</em> will give the FontManager
|
||||
a default color. <em>index</em> will select a specific font face from a file
|
||||
containing multiple font faces. The first face is always at index 0. It can
|
||||
be used for TTC (TrueType Font Collection) fonts.</p>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.FontManager.bg_color">
|
||||
<code class="descname">bg_color</code><a class="headerlink" href="#sdl2.ext.FontManager.bg_color" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The <a class="reference internal" href="sdl2ext_color.html#sdl2.ext.Color" title="sdl2.ext.Color"><code class="xref py py-class docutils literal"><span class="pre">sdl2.ext.Color</span></code></a> to be used as background color.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.FontManager.color">
|
||||
<code class="descname">color</code><a class="headerlink" href="#sdl2.ext.FontManager.color" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The <a class="reference internal" href="sdl2ext_color.html#sdl2.ext.Color" title="sdl2.ext.Color"><code class="xref py py-class docutils literal"><span class="pre">sdl2.ext.Color</span></code></a> to be used for rendering text.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.FontManager.default_font">
|
||||
<code class="descname">default_font</code><a class="headerlink" href="#sdl2.ext.FontManager.default_font" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns the name of the current default font being used by the
|
||||
<a class="reference internal" href="#sdl2.ext.FontManager" title="sdl2.ext.FontManager"><code class="xref py py-class docutils literal"><span class="pre">FontManager</span></code></a>. On assigning <a class="reference internal" href="#sdl2.ext.FontManager.default_font" title="sdl2.ext.FontManager.default_font"><code class="xref py py-attr docutils literal"><span class="pre">default_font</span></code></a>,
|
||||
the value must be a loaded font alias.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.FontManager.size">
|
||||
<code class="descname">size</code><a class="headerlink" href="#sdl2.ext.FontManager.size" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The default font size in pixels.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.FontManager.add">
|
||||
<code class="descname">add</code><span class="sig-paren">(</span><em>font_path : str[, alias=None[, size=None[, index=0]]])</em><span class="sig-paren">)</span> → sdl2.sdlttf.TTF_Font<a class="headerlink" href="#sdl2.ext.FontManager.add" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Add a font to the <a class="reference internal" href="#sdl2.ext.FontManager" title="sdl2.ext.FontManager"><code class="xref py py-class docutils literal"><span class="pre">FontManager</span></code></a>. <em>alias</em> is by default the
|
||||
font name, any other name can be passed, <em>size</em> is the font size
|
||||
in pixels and defaults to <a class="reference internal" href="#sdl2.ext.FontManager.size" title="sdl2.ext.FontManager.size"><code class="xref py py-attr docutils literal"><span class="pre">size</span></code></a>. <em>index</em> selects a specific font
|
||||
face from a TTC (TrueType Font Collection) file. Returns the font pointer
|
||||
stored in <code class="xref py py-attr docutils literal"><span class="pre">fonts</span></code>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.FontManager.close">
|
||||
<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.FontManager.close" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Closes all fonts used by the <a class="reference internal" href="#sdl2.ext.FontManager" title="sdl2.ext.FontManager"><code class="xref py py-class docutils literal"><span class="pre">FontManager</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.FontManager.render">
|
||||
<code class="descname">render</code><span class="sig-paren">(</span><em>text : str</em><span class="optional">[</span>, <em>alias=None</em><span class="optional">[</span>, <em>size=None</em><span class="optional">[</span>, <em>width=None</em><span class="optional">[</span>, <em>color=None</em><span class="optional">[</span>, <em>bg_color=None</em><span class="optional">[</span>, <em>**kwargs</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span> → sdl2.SDL_Surface<a class="headerlink" href="#sdl2.ext.FontManager.render" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Renders text to a surface. This method uses the font designated by
|
||||
the passed <em>alias</em> or, if <em>alias</em> is omitted, by the set
|
||||
<a class="reference internal" href="#sdl2.ext.FontManager.default_font" title="sdl2.ext.FontManager.default_font"><code class="xref py py-attr docutils literal"><span class="pre">default_font</span></code></a>. A <em>size</em> can be passed even if the font was
|
||||
not loaded with this size. A <em>width</em> can be given for automatic line
|
||||
wrapping. If no <em>bg_color</em> or <em>color</em> are given, it will default to
|
||||
the FontManager’s <a class="reference internal" href="#sdl2.ext.FontManager.bg_color" title="sdl2.ext.FontManager.bg_color"><code class="xref py py-attr docutils literal"><span class="pre">bg_color</span></code></a> and <a class="reference internal" href="#sdl2.ext.FontManager.color" title="sdl2.ext.FontManager.color"><code class="xref py py-attr docutils literal"><span class="pre">color</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_events.html"
|
||||
title="previous chapter">General purpose event handling routines</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_gui.html"
|
||||
title="next chapter">User interface elements</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_font.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_gui.html" title="User interface elements"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_events.html" title="General purpose event handling routines"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,435 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>User interface elements — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="Image loaders" href="sdl2ext_image.html" />
|
||||
<link rel="prev" title="Text rendering routines" href="sdl2ext_font.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_image.html" title="Image loaders"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_font.html" title="Text rendering routines"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="user-interface-elements">
|
||||
<h1>User interface elements<a class="headerlink" href="#user-interface-elements" title="Permalink to this headline">¶</a></h1>
|
||||
<p>User interface elements within <a class="reference internal" href="sdl2ext.html#module-sdl2.ext" title="sdl2.ext: Python extensions for SDL2"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.ext</span></code></a> are simple
|
||||
<a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.Sprite" title="sdl2.ext.Sprite"><code class="xref py py-class docutils literal"><span class="pre">Sprite</span></code></a> objects, which are enhanced by certain input hooks; as such,
|
||||
they are not classes on their own, but implemented as mixins. The user input
|
||||
itself is handled by an <a class="reference internal" href="#sdl2.ext.UIProcessor" title="sdl2.ext.UIProcessor"><code class="xref py py-class docutils literal"><span class="pre">UIProcessor</span></code></a> object, which takes care of
|
||||
delegating input events, such as mouse movements, clicks and keyboard input,
|
||||
to the correct UI element.</p>
|
||||
<p>Depending on the event type (e.g. pressing a mouse button), the UIProcessor
|
||||
will execute its matching method (e.g. <code class="docutils literal"><span class="pre">mousedown()</span></code>) with only those UI
|
||||
elements, which support the event type.</p>
|
||||
<img alt="../_images/uiprocessing.png" src="../_images/uiprocessing.png" />
|
||||
<div class="section" id="ui-element-types">
|
||||
<span id="ui-elem-types"></span><h2>UI element types<a class="headerlink" href="#ui-element-types" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Every <a class="reference internal" href="sdl2ext.html#module-sdl2.ext" title="sdl2.ext: Python extensions for SDL2"><code class="xref py py-class docutils literal"><span class="pre">sdl2.ext</span></code></a> UI element is a simple <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.Sprite" title="sdl2.ext.Sprite"><code class="xref py py-class docutils literal"><span class="pre">Sprite</span></code></a> object, to
|
||||
which additional attributes and methods are bound.</p>
|
||||
<p>Every UI element features the following attributes</p>
|
||||
<p><code class="docutils literal"><span class="pre">element.uitype</span></code></p>
|
||||
<blockquote>
|
||||
<div><p>The <code class="docutils literal"><span class="pre">uitype</span></code> attribute can have one of the following values,
|
||||
identifying the UI element:</p>
|
||||
<ul class="simple">
|
||||
<li><code class="docutils literal"><span class="pre">BUTTON</span></code> - a UI element, which can react on mouse input</li>
|
||||
<li><code class="docutils literal"><span class="pre">CHECKBUTTON</span></code> - as <code class="docutils literal"><span class="pre">BUTTON</span></code>, but it retains its state on clicks</li>
|
||||
<li><code class="docutils literal"><span class="pre">TEXTENTRY</span></code> - a UI element that reacts on keyboard input</li>
|
||||
</ul>
|
||||
</div></blockquote>
|
||||
<p><code class="docutils literal"><span class="pre">element.events</span></code></p>
|
||||
<blockquote>
|
||||
<div>A dictionary containing the SDL2 event mappings. Each supported SDL2 event
|
||||
(e.g. <code class="docutils literal"><span class="pre">SDL_MOUSEMOTION</span></code>) is associated with a bound
|
||||
<a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> acting as callback for user code
|
||||
(e.g. <code class="docutils literal"><span class="pre">mousemotion()</span></code>).</div></blockquote>
|
||||
<p>Depending on the exact type of the element, it will feature additional methods
|
||||
and attributes explained below.</p>
|
||||
<div class="section" id="button-elements">
|
||||
<h3>Button elements<a class="headerlink" href="#button-elements" title="Permalink to this headline">¶</a></h3>
|
||||
<p><code class="docutils literal"><span class="pre">BUTTON</span></code> UI elements feature a <code class="docutils literal"><span class="pre">state</span></code> attribute, which can be one of the
|
||||
following values.</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="10%" />
|
||||
<col width="90%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr class="row-odd"><th class="head">state</th>
|
||||
<th class="head">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr class="row-even"><td>RELEASED</td>
|
||||
<td>Indicates that the UI element is not pressed.</td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td>HOVERED</td>
|
||||
<td>Indicates that the mouse cursor is currently hovering the UI element.</td>
|
||||
</tr>
|
||||
<tr class="row-even"><td>PRESSED</td>
|
||||
<td>Indicates that a mouse button is pressed on the UI element.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p><code class="docutils literal"><span class="pre">BUTTON</span></code> UI elements react with the following event handlers on events:</p>
|
||||
<p><code class="docutils literal"><span class="pre">button.motion(event</span> <span class="pre">:</span> <span class="pre">sdl2.events.SDL_Event)</span></code></p>
|
||||
<blockquote>
|
||||
<div>An <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> that is invoked, if the mouse moves around while
|
||||
being over the <code class="docutils literal"><span class="pre">BUTTON</span></code>.</div></blockquote>
|
||||
<p><code class="docutils literal"><span class="pre">button.pressed(event</span> <span class="pre">:</span> <span class="pre">sdl2.events.SDL_Event)</span></code></p>
|
||||
<blockquote>
|
||||
<div>An <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> that is invoked, if a mouse button is pressed on
|
||||
the <code class="docutils literal"><span class="pre">BUTTON</span></code>.</div></blockquote>
|
||||
<p><code class="docutils literal"><span class="pre">button.released(event</span> <span class="pre">:</span> <span class="pre">sdl2.events.SDL_Event)</span></code></p>
|
||||
<blockquote>
|
||||
<div>An <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> that is invoked, if a mouse button is released on
|
||||
the <code class="docutils literal"><span class="pre">BUTTON</span></code>.</div></blockquote>
|
||||
<p><code class="docutils literal"><span class="pre">button.click(event</span> <span class="pre">:</span> <span class="pre">sdl2.events.SDL_Event)</span></code></p>
|
||||
<blockquote>
|
||||
<div>An <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> that is invoked, if a mouse button is pressed and
|
||||
released on the <code class="docutils literal"><span class="pre">BUTTON</span></code>.</div></blockquote>
|
||||
<p>Besides the <code class="docutils literal"><span class="pre">BUTTON</span></code> a special <code class="docutils literal"><span class="pre">CHECKBUTTON</span></code> UI element type exists,
|
||||
which enhances the <code class="docutils literal"><span class="pre">BUTTON</span></code> bindings by an additional <code class="docutils literal"><span class="pre">checked</span></code> attribute.
|
||||
The <code class="docutils literal"><span class="pre">checked</span></code> attribute switches its status (<code class="docutils literal"><span class="pre">False</span></code> to <code class="docutils literal"><span class="pre">True</span></code> and
|
||||
<code class="docutils literal"><span class="pre">True</span></code> to <code class="docutils literal"><span class="pre">False</span></code>) every time the UI element is clicked.</p>
|
||||
</div>
|
||||
<div class="section" id="text-input-elements">
|
||||
<h3>Text input elements<a class="headerlink" href="#text-input-elements" title="Permalink to this headline">¶</a></h3>
|
||||
<p><code class="docutils literal"><span class="pre">TEXTENTRY</span></code> elements react on text input, once they are activated. Text being
|
||||
input, once a <code class="docutils literal"><span class="pre">TEXTENTRY</span></code> has been activated, is stored in its <code class="docutils literal"><span class="pre">text</span></code>
|
||||
attribute.</p>
|
||||
<p>The <code class="docutils literal"><span class="pre">TEXTENTRY</span></code> reacts with the following event handlers on events:</p>
|
||||
<p><code class="docutils literal"><span class="pre">textentry.motion(event</span> <span class="pre">:</span> <span class="pre">sdl2.events.SDL_Event)</span></code></p>
|
||||
<blockquote>
|
||||
<div>An <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> that is invoked, if the mouse moves around while
|
||||
being over the <code class="docutils literal"><span class="pre">TEXTENTRY</span></code>.</div></blockquote>
|
||||
<p><code class="docutils literal"><span class="pre">textentry.pressed(event</span> <span class="pre">:</span> <span class="pre">sdl2.events.SDL_Event)</span></code></p>
|
||||
<blockquote>
|
||||
<div>An <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> that is invoked, if a mouse button is pressed on
|
||||
the <code class="docutils literal"><span class="pre">TEXTENTRY</span></code>.</div></blockquote>
|
||||
<p><code class="docutils literal"><span class="pre">textentry.released(event</span> <span class="pre">:</span> <span class="pre">sdl2.events.SDL_Event)</span></code></p>
|
||||
<blockquote>
|
||||
<div>An <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> that is invoked, if a mouse button is released on
|
||||
the <code class="docutils literal"><span class="pre">TEXTENTRY</span></code>.</div></blockquote>
|
||||
<p><code class="docutils literal"><span class="pre">textentry.keydown(event</span> <span class="pre">:</span> <span class="pre">sdl2.events.SDL_Event)</span></code></p>
|
||||
<blockquote>
|
||||
<div>An <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> that is invoked on pressing a key.</div></blockquote>
|
||||
<p><code class="docutils literal"><span class="pre">textentry.keyup(event</span> <span class="pre">:</span> <span class="pre">sdl2.events.SDL_Event)</span></code></p>
|
||||
<blockquote>
|
||||
<div>An <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> that is invoked on releasing a key.</div></blockquote>
|
||||
<p><code class="docutils literal"><span class="pre">textentry.input(event</span> <span class="pre">:</span> <span class="pre">sdl2.events.SDL_Event)</span></code></p>
|
||||
<blockquote>
|
||||
<div>An <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> that is invoked on text input events.
|
||||
Text input events are automatically created, once the <a class="reference internal" href="#sdl2.ext.UIProcessor" title="sdl2.ext.UIProcessor"><code class="xref py py-class docutils literal"><span class="pre">UIProcessor</span></code></a>
|
||||
activates a <code class="docutils literal"><span class="pre">TEXTENTRY</span></code> UI element.</div></blockquote>
|
||||
<p><code class="docutils literal"><span class="pre">textentry.editing(event</span> <span class="pre">:</span> <span class="pre">sdl2.events.SDL_Event)</span></code></p>
|
||||
<blockquote>
|
||||
<div><p>An <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> that is invoked on text editing events. Text
|
||||
editing events are automatically created, once the <a class="reference internal" href="#sdl2.ext.UIProcessor" title="sdl2.ext.UIProcessor"><code class="xref py py-class docutils literal"><span class="pre">UIProcessor</span></code></a>
|
||||
activates a <code class="docutils literal"><span class="pre">TEXTENTRY</span></code> UI element.</p>
|
||||
<p>Text editing events are however only raised, if an IME system is involved,
|
||||
which combines glyphs and symbols to characters or word fragments.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="api">
|
||||
<h2>API<a class="headerlink" href="#api" title="Permalink to this headline">¶</a></h2>
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.UIFactory">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">UIFactory</code><span class="sig-paren">(</span><em>spritefactory : SpriteFactory</em><span class="optional">[</span>, <em>**kwargs</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.UIFactory" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A factory class for creating UI elements. The <a class="reference internal" href="#sdl2.ext.UIFactory" title="sdl2.ext.UIFactory"><code class="xref py py-class docutils literal"><span class="pre">UIFactory</span></code></a>
|
||||
allows you to create UI elements based on the
|
||||
<a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.Sprite" title="sdl2.ext.Sprite"><code class="xref py py-class docutils literal"><span class="pre">Sprite</span></code></a> class. To do this, it requires a <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SpriteFactory" title="sdl2.ext.SpriteFactory"><code class="xref py py-class docutils literal"><span class="pre">SpriteFactory</span></code></a>,
|
||||
which will create the sprites, to which the <a class="reference internal" href="#sdl2.ext.UIFactory" title="sdl2.ext.UIFactory"><code class="xref py py-class docutils literal"><span class="pre">UIFactory</span></code></a> then binds
|
||||
the additional methods and attributes.</p>
|
||||
<p>The additional <em>kwargs</em> are used as default arguments for creating
|
||||
<strong>sprites</strong> within the factory methods.</p>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.UIFactory.default_args">
|
||||
<code class="descname">default_args</code><a class="headerlink" href="#sdl2.ext.UIFactory.default_args" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A dictionary containing the default arguments to be passed to the
|
||||
sprite creation methods of the bound <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SpriteFactory" title="sdl2.ext.SpriteFactory"><code class="xref py py-class docutils literal"><span class="pre">SpriteFactory</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.UIFactory.spritefactory">
|
||||
<code class="descname">spritefactory</code><a class="headerlink" href="#sdl2.ext.UIFactory.spritefactory" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SpriteFactory" title="sdl2.ext.SpriteFactory"><code class="xref py py-class docutils literal"><span class="pre">SpriteFactory</span></code></a> being used for creating new <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.Sprite" title="sdl2.ext.Sprite"><code class="xref py py-class docutils literal"><span class="pre">Sprite</span></code></a>
|
||||
objects.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIFactory.create_button">
|
||||
<code class="descname">create_button</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span> → Sprite<a class="headerlink" href="#sdl2.ext.UIFactory.create_button" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates a new button UI element.</p>
|
||||
<p><em>kwargs</em> are the arguments to be passed for the sprite
|
||||
construction and can vary depending on the sprite type.
|
||||
See <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SpriteFactory.create_sprite" title="sdl2.ext.SpriteFactory.create_sprite"><code class="xref py py-meth docutils literal"><span class="pre">SpriteFactory.create_sprite()</span></code></a> for further details.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIFactory.create_check_button">
|
||||
<code class="descname">create_check_button</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span> → Sprite<a class="headerlink" href="#sdl2.ext.UIFactory.create_check_button" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates a new checkbutton UI element.</p>
|
||||
<p><em>kwargs</em> are the arguments to be passed for the sprite
|
||||
construction and can vary depending on the sprite type.
|
||||
See <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SpriteFactory.create_sprite" title="sdl2.ext.SpriteFactory.create_sprite"><code class="xref py py-meth docutils literal"><span class="pre">SpriteFactory.create_sprite()</span></code></a> for further details.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIFactory.create_text_entry">
|
||||
<code class="descname">create_text_entry</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span> → Sprite<a class="headerlink" href="#sdl2.ext.UIFactory.create_text_entry" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates a new textentry UI element.</p>
|
||||
<p><em>kwargs</em> are the arguments to be passed for the sprite
|
||||
construction and can vary depending on the sprite type.
|
||||
See <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SpriteFactory.create_sprite" title="sdl2.ext.SpriteFactory.create_sprite"><code class="xref py py-meth docutils literal"><span class="pre">SpriteFactory.create_sprite()</span></code></a> for further details.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIFactory.from_color">
|
||||
<code class="descname">from_color</code><span class="sig-paren">(</span><em>color : object</em>, <em>size</em><span class="sig-paren">)</span> → Sprite<a class="headerlink" href="#sdl2.ext.UIFactory.from_color" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates a UI element with a specific color.</p>
|
||||
<p><em>uitype</em> must be one of the supported <a class="reference internal" href="#ui-elem-types"><span class="std std-ref">UI element types</span></a> classifying
|
||||
the type of UI element to be created.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIFactory.from_image">
|
||||
<code class="descname">from_image</code><span class="sig-paren">(</span><em>uitype : int</em>, <em>fname : str</em><span class="sig-paren">)</span> → Sprite<a class="headerlink" href="#sdl2.ext.UIFactory.from_image" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates a UI element from an image file. The image must be
|
||||
loadable via <a class="reference internal" href="sdl2ext_image.html#sdl2.ext.load_image" title="sdl2.ext.load_image"><code class="xref py py-func docutils literal"><span class="pre">load_image()</span></code></a>.</p>
|
||||
<p><em>uitype</em> must be one of the supported <a class="reference internal" href="#ui-elem-types"><span class="std std-ref">UI element types</span></a> classifying
|
||||
the type of UI element to be created.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIFactory.from_object">
|
||||
<code class="descname">from_object</code><span class="sig-paren">(</span><em>uitype : int</em>, <em>obj: object</em><span class="sig-paren">)</span> → Sprite<a class="headerlink" href="#sdl2.ext.UIFactory.from_object" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates a UI element from an object. The object will be passed through
|
||||
<code class="xref py py-func docutils literal"><span class="pre">sdl2.rwops_from_object()</span></code> in order to try to load image data from
|
||||
it.</p>
|
||||
<p><em>uitype</em> must be one of the supported <a class="reference internal" href="#ui-elem-types"><span class="std std-ref">UI element types</span></a> classifying
|
||||
the type of UI element to be created.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIFactory.from_surface">
|
||||
<code class="descname">from_surface</code><span class="sig-paren">(</span><em>uitype : int</em>, <em>surface : SDL_Surface</em><span class="optional">[</span>, <em>free=False</em><span class="optional">]</span><span class="sig-paren">)</span> → Sprite<a class="headerlink" href="#sdl2.ext.UIFactory.from_surface" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates a UI element from the passed
|
||||
<code class="xref py py-class docutils literal"><span class="pre">sdl2.surface.SDL_Surface</span></code>. If <em>free</em> is set to
|
||||
<code class="docutils literal"><span class="pre">True</span></code>, the passed <em>surface</em> will be freed automatically.</p>
|
||||
<p><em>uitype</em> must be one of the supported <a class="reference internal" href="#ui-elem-types"><span class="std std-ref">UI element types</span></a> classifying
|
||||
the type of UI element to be created.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.UIProcessor">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">UIProcessor</code><a class="headerlink" href="#sdl2.ext.UIProcessor" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A processing system for user interface elements and events.</p>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.UIProcessor.handlers">
|
||||
<code class="descname">handlers</code><a class="headerlink" href="#sdl2.ext.UIProcessor.handlers" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A dict containing the mapping of SDL2 events to the available
|
||||
<a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> bindings of the <a class="reference internal" href="#sdl2.ext.UIProcessor" title="sdl2.ext.UIProcessor"><code class="xref py py-class docutils literal"><span class="pre">UIProcessor</span></code></a>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIProcessor.activate">
|
||||
<code class="descname">activate</code><span class="sig-paren">(</span><em>component : object</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.UIProcessor.activate" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Activates a UI control to receive text input.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIProcessor.deactivate">
|
||||
<code class="descname">deactivate</code><span class="sig-paren">(</span><em>component : object</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.UIProcessor.deactivate" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Deactivate the currently active UI control.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIProcessor.passevent">
|
||||
<code class="descname">passevent</code><span class="sig-paren">(</span><em>component : object</em>, <em>event : SDL_Event</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.UIProcessor.passevent" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Passes the <em>event</em> to a <em>component</em> without any additional checks or
|
||||
restrictions.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIProcessor.mousemotion">
|
||||
<code class="descname">mousemotion</code><span class="sig-paren">(</span><em>component : object</em>, <em>event : SDL_Event</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.UIProcessor.mousemotion" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Checks, if the event’s motion position is on the <em>component</em> and
|
||||
executes the component’s event handlers on demand. If the motion event
|
||||
position is not within the area of the <em>component</em>, nothing will be
|
||||
done. In case the component is a <code class="docutils literal"><span class="pre">BUTTON</span></code>, its <code class="xref py py-attr docutils literal"><span class="pre">state</span></code> will be
|
||||
adjusted to reflect, if it is currently hovered or not.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIProcessor.mousedown">
|
||||
<code class="descname">mousedown</code><span class="sig-paren">(</span><em>component : object</em>, <em>event : SDL_Event</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.UIProcessor.mousedown" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Checks, if the event’s button press position is on the <em>component</em> and
|
||||
executes the component’s event handlers on demand. If the button press
|
||||
position is not within the area of the component, nothing will be done.</p>
|
||||
<p>In case the component is a <code class="docutils literal"><span class="pre">BUTTON</span></code>, its <code class="xref py py-attr docutils literal"><span class="pre">state</span></code>
|
||||
will be adjusted to reflect, if it is currently pressed or not.</p>
|
||||
<p>In case the component is a <code class="docutils literal"><span class="pre">TEXTENTRY</span></code> and the pressed button is
|
||||
the primary mouse button, the component will be marked as the next
|
||||
control to activate for text input.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIProcessor.mouseup">
|
||||
<code class="descname">mouseup</code><span class="sig-paren">(</span><em>self</em>, <em>component</em>, <em>event</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.UIProcessor.mouseup" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Checks, if the event’s button release position is on the <em>component</em> and
|
||||
executes the component’s event handlers on demand. If the button release
|
||||
position is not within the area of the component, nothing will be done.</p>
|
||||
<p>In case the component is a <code class="docutils literal"><span class="pre">BUTTON</span></code>, its <code class="xref py py-attr docutils literal"><span class="pre">state</span></code>
|
||||
will be adjusted to reflect, whether it is hovered or not.</p>
|
||||
<p>If the button release followed a button press on the same component and
|
||||
if the button is the primary button, the <code class="docutils literal"><span class="pre">click()</span></code> event handler is
|
||||
invoked, if the component is a <code class="docutils literal"><span class="pre">BUTTON</span></code>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIProcessor.dispatch">
|
||||
<code class="descname">dispatch</code><span class="sig-paren">(</span><em>obj : object</em>, <em>event : SDL_Event</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.UIProcessor.dispatch" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Passes an event to the given object. If <em>obj</em> is a
|
||||
<a class="reference internal" href="sdl2ext_ebs.html#sdl2.ext.World" title="sdl2.ext.World"><code class="xref py py-class docutils literal"><span class="pre">World</span></code></a> object, UI relevant components will receive
|
||||
the event, if they support the event type. If <em>obj</em> is a single object,
|
||||
<code class="docutils literal"><span class="pre">obj.events</span></code> <strong>must</strong> be a dict consisting of SDL event type
|
||||
identifiers and <a class="reference internal" href="sdl2ext_events.html#sdl2.ext.EventHandler" title="sdl2.ext.EventHandler"><code class="xref py py-class docutils literal"><span class="pre">EventHandler</span></code></a> instances bound
|
||||
to the object. If <em>obj</em> is a iterable, such as a list or set, every
|
||||
item within <em>obj</em> <strong>must</strong> feature an <code class="docutils literal"><span class="pre">events</span></code> attribute as
|
||||
described above.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.UIProcessor.process">
|
||||
<code class="descname">process</code><span class="sig-paren">(</span><em>world : World</em>, <em>components : iterable</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.UIProcessor.process" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The <a class="reference internal" href="#sdl2.ext.UIProcessor" title="sdl2.ext.UIProcessor"><code class="xref py py-class docutils literal"><span class="pre">UIProcessor</span></code></a> class does not implement the <cite>process()</cite>
|
||||
method by default. Instead it uses <a class="reference internal" href="#sdl2.ext.UIProcessor.dispatch" title="sdl2.ext.UIProcessor.dispatch"><code class="xref py py-meth docutils literal"><span class="pre">dispatch()</span></code></a> to send events
|
||||
around to components. <a class="reference internal" href="#sdl2.ext.UIProcessor.process" title="sdl2.ext.UIProcessor.process"><code class="xref py py-meth docutils literal"><span class="pre">process()</span></code></a> does nothing.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="../index.html">Table Of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">User interface elements</a><ul>
|
||||
<li><a class="reference internal" href="#ui-element-types">UI element types</a><ul>
|
||||
<li><a class="reference internal" href="#button-elements">Button elements</a></li>
|
||||
<li><a class="reference internal" href="#text-input-elements">Text input elements</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference internal" href="#api">API</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_font.html"
|
||||
title="previous chapter">Text rendering routines</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_image.html"
|
||||
title="next chapter">Image loaders</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_gui.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_image.html" title="Image loaders"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_font.html" title="Text rendering routines"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,144 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Image loaders — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="sdl2.ext.particles - A simple particle system" href="sdl2ext_particles.html" />
|
||||
<link rel="prev" title="User interface elements" href="sdl2ext_gui.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_particles.html" title="sdl2.ext.particles - A simple particle system"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_gui.html" title="User interface elements"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="image-loaders">
|
||||
<h1>Image loaders<a class="headerlink" href="#image-loaders" title="Permalink to this headline">¶</a></h1>
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.get_image_formats">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">get_image_formats</code><span class="sig-paren">(</span><em>) -> (str</em>, <em>str</em>, <em>...</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.get_image_formats" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Gets the formats supported by PySDL2 in the default installation.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.load_image">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">load_image</code><span class="sig-paren">(</span><em>fname : str</em><span class="optional">[</span>, <em>enforce=None</em><span class="optional">]</span><span class="sig-paren">)</span> → sdl2.SDL_Surface<a class="headerlink" href="#sdl2.ext.load_image" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates a <code class="xref py py-class docutils literal"><span class="pre">sdl2.SDL_Surface</span></code> from an image file.</p>
|
||||
<p>This function makes use of the <a class="reference external" href="http://www.pythonware.com/products/pil/">Python Imaging Library</a>, if it is available on the
|
||||
target execution environment. The function will try to load the file via
|
||||
<a class="reference internal" href="sdl2.html#module-sdl2" title="sdl2: SDL2 library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2</span></code></a> first. If the file could not be loaded, it will try to load it
|
||||
via <a class="reference internal" href="sdl2_sdlimage.html#module-sdl2.sdlimage" title="sdl2.sdlimage: SDL2_image library wrapper"><code class="xref py py-mod docutils literal"><span class="pre">sdl2.sdlimage</span></code></a> and PIL.</p>
|
||||
<p>You can force the function to use only one of them, by passing the
|
||||
<em>enforce</em> as either <code class="docutils literal"><span class="pre">"PIL"</span></code> or <code class="docutils literal"><span class="pre">"SDL"</span></code>.</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">This will call <code class="xref py py-func docutils literal"><span class="pre">sdl2.sdlimage.IMG_Init()</span></code> implicitly with the
|
||||
default arguments, if the module is available and if
|
||||
<code class="xref py py-func docutils literal"><span class="pre">sdl2.SDL_LoadBMP()</span></code> failed to load the image.</p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_gui.html"
|
||||
title="previous chapter">User interface elements</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_particles.html"
|
||||
title="next chapter">sdl2.ext.particles - A simple particle system</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_image.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_particles.html" title="sdl2.ext.particles - A simple particle system"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_gui.html" title="User interface elements"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,233 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>sdl2.ext.particles - A simple particle system — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="2D and 3D direct pixel access" href="sdl2ext_pixelaccess.html" />
|
||||
<link rel="prev" title="Image loaders" href="sdl2ext_image.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_pixelaccess.html" title="2D and 3D direct pixel access"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_image.html" title="Image loaders"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<span class="target" id="module-sdl2.ext.particles"></span><div class="section" id="sdl2-ext-particles-a-simple-particle-system">
|
||||
<h1>sdl2.ext.particles - A simple particle system<a class="headerlink" href="#sdl2-ext-particles-a-simple-particle-system" title="Permalink to this headline">¶</a></h1>
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.particles.ParticleEngine">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.particles.</code><code class="descname">ParticleEngine</code><a class="headerlink" href="#sdl2.ext.particles.ParticleEngine" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A simple particle processing system. The <a class="reference internal" href="#sdl2.ext.particles.ParticleEngine" title="sdl2.ext.particles.ParticleEngine"><code class="xref py py-class docutils literal"><span class="pre">ParticleEngine</span></code></a>
|
||||
takes care of creating, updating and deleting particles via callback
|
||||
functions. It only decreases the life of the particles by itself and
|
||||
marks them as dead, once the particle’s life attribute has reached 0
|
||||
or below.</p>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.particles.ParticleEngine.createfunc">
|
||||
<code class="descname">createfunc</code><a class="headerlink" href="#sdl2.ext.particles.ParticleEngine.createfunc" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Function for creating new particles. The function needs to take
|
||||
two arguments, the <code class="docutils literal"><span class="pre">world</span></code> argument passed to <a class="reference internal" href="#sdl2.ext.particles.ParticleEngine.process" title="sdl2.ext.particles.ParticleEngine.process"><code class="xref py py-meth docutils literal"><span class="pre">process()</span></code></a>
|
||||
and a list of the particles considered dead (<a class="reference internal" href="#sdl2.ext.particles.Particle.life" title="sdl2.ext.particles.Particle.life"><code class="xref py py-attr docutils literal"><span class="pre">Particle.life</span></code></a>
|
||||
<= 0).</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">creation_func</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">deadparticles</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.particles.ParticleEngine.updatefunc">
|
||||
<code class="descname">updatefunc</code><a class="headerlink" href="#sdl2.ext.particles.ParticleEngine.updatefunc" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Function for updating existing, living particles. The function
|
||||
needs to take two arguments, the <code class="docutils literal"><span class="pre">world</span></code> argument passed to
|
||||
<a class="reference internal" href="#sdl2.ext.particles.ParticleEngine.process" title="sdl2.ext.particles.ParticleEngine.process"><code class="xref py py-meth docutils literal"><span class="pre">process()</span></code></a> and a <a class="reference external" href="http://docs.python.org/library/stdtypes.html#set" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">set</span></code></a> of the still living
|
||||
particles.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">update_func</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">livingparticles</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.particles.ParticleEngine.deletefunc">
|
||||
<code class="descname">deletefunc</code><a class="headerlink" href="#sdl2.ext.particles.ParticleEngine.deletefunc" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Function for deleting dead particles. The function needs to take
|
||||
two arguments, the <code class="docutils literal"><span class="pre">world</span></code> argument passed to <a class="reference internal" href="#sdl2.ext.particles.ParticleEngine.process" title="sdl2.ext.particles.ParticleEngine.process"><code class="xref py py-meth docutils literal"><span class="pre">process()</span></code></a>
|
||||
and a list of the particles considered dead (<a class="reference internal" href="#sdl2.ext.particles.Particle.life" title="sdl2.ext.particles.Particle.life"><code class="xref py py-attr docutils literal"><span class="pre">Particle.life</span></code></a>
|
||||
<= 0).</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">deletion_func</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">deadparticles</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.particles.ParticleEngine.process">
|
||||
<code class="descname">process</code><span class="sig-paren">(</span><em>world : World</em>, <em>components : iterable</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#sdl2.ext.particles.ParticleEngine.process" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Processes all particle components, decreasing their life by 1.</p>
|
||||
<p>Once the life of all particle components has been decreased
|
||||
properly and the particles considered dead (life <= 0) are
|
||||
identified, the creation, update and deletion callbacks are
|
||||
invoked.</p>
|
||||
<p>The creation callback takes the passed world as first and the
|
||||
list of dead particles as second argument.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">particle_createfunc</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">list_of_dead_ones</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Afterwards the still living particles are passed to the update
|
||||
callback, which also take the passed world as first and the
|
||||
living particles as set as second argument.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">particle_updatefunc</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">set_of_living_ones</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Finally, the dead particles need to be deleted in some way or
|
||||
another, which is done by the deletion callback, taking the
|
||||
passed world as first and the list of dead particles as second
|
||||
argument.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">particle_deletefunc</span><span class="p">(</span><span class="n">world</span><span class="p">,</span> <span class="n">list_of_dead_ones</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.particles.Particle">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.particles.</code><code class="descname">Particle</code><span class="sig-paren">(</span><em>x</em>, <em>y</em>, <em>life : int</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.particles.Particle" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A simple particle component type. It only contains information about
|
||||
a x- and y-coordinate and its current life time. The life time will
|
||||
be decreased by 1, every time the particle is processed by the
|
||||
<a class="reference internal" href="#sdl2.ext.particles.ParticleEngine" title="sdl2.ext.particles.ParticleEngine"><code class="xref py py-class docutils literal"><span class="pre">ParticleEngine</span></code></a>.</p>
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.particles.Particle.x">
|
||||
<code class="descname">x</code><a class="headerlink" href="#sdl2.ext.particles.Particle.x" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The x coordinate of the particle.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.particles.Particle.y">
|
||||
<code class="descname">y</code><a class="headerlink" href="#sdl2.ext.particles.Particle.y" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The y coordinate of the particle.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.particles.Particle.life">
|
||||
<code class="descname">life</code><a class="headerlink" href="#sdl2.ext.particles.Particle.life" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The remaining life time of the particle.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="sdl2.ext.particles.Particle.position">
|
||||
<code class="descname">position</code><a class="headerlink" href="#sdl2.ext.particles.Particle.position" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The x- and y-coordinate of the particle as tuple.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_image.html"
|
||||
title="previous chapter">Image loaders</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_pixelaccess.html"
|
||||
title="next chapter">2D and 3D direct pixel access</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_particles.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_pixelaccess.html" title="2D and 3D direct pixel access"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_image.html" title="Image loaders"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,176 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>2D and 3D direct pixel access — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="Resource management" href="sdl2ext_resources.html" />
|
||||
<link rel="prev" title="sdl2.ext.particles - A simple particle system" href="sdl2ext_particles.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_resources.html" title="Resource management"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_particles.html" title="sdl2.ext.particles - A simple particle system"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="d-and-3d-direct-pixel-access">
|
||||
<h1>2D and 3D direct pixel access<a class="headerlink" href="#d-and-3d-direct-pixel-access" title="Permalink to this headline">¶</a></h1>
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.PixelView">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">PixelView</code><span class="sig-paren">(</span><em>source : object</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.PixelView" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>2D <a class="reference internal" href="sdl2ext_array.html#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a> for <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SoftwareSprite" title="sdl2.ext.SoftwareSprite"><code class="xref py py-class docutils literal"><span class="pre">SoftwareSprite</span></code></a> and
|
||||
<code class="xref py py-class docutils literal"><span class="pre">sdl2.SDL_surface</span></code> pixel access.</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<blockquote>
|
||||
<div>If necessary, the <em>source</em> surface will be locked for accessing its
|
||||
pixel data. The lock will be removed once the <a class="reference internal" href="#sdl2.ext.PixelView" title="sdl2.ext.PixelView"><code class="xref py py-class docutils literal"><span class="pre">PixelView</span></code></a> is
|
||||
garbage-collected or deleted.</div></blockquote>
|
||||
<p>The <a class="reference internal" href="#sdl2.ext.PixelView" title="sdl2.ext.PixelView"><code class="xref py py-class docutils literal"><span class="pre">PixelView</span></code></a> uses a y/x-layout. Accessing <code class="docutils literal"><span class="pre">view[N]</span></code> will
|
||||
operate on the Nth row of the underlying surface. To access a specific
|
||||
column within that row, <code class="docutils literal"><span class="pre">view[N][C]</span></code> has to be used.</p>
|
||||
<div class="last admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last"><a class="reference internal" href="#sdl2.ext.PixelView" title="sdl2.ext.PixelView"><code class="xref py py-class docutils literal"><span class="pre">PixelView</span></code></a> is implemented on top of the <a class="reference internal" href="sdl2ext_array.html#sdl2.ext.MemoryView" title="sdl2.ext.MemoryView"><code class="xref py py-class docutils literal"><span class="pre">MemoryView</span></code></a>
|
||||
class. As such it makes heavy use of recursion to access rows and
|
||||
columns and can be considered as slow in contrast to optimised
|
||||
ndim-array solutions such as <code class="xref py py-mod docutils literal"><span class="pre">numpy</span></code>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.pixels2d">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">pixels2d</code><span class="sig-paren">(</span><em>source : object</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.pixels2d" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates a 2D pixel array, based on <code class="docutils literal"><span class="pre">numpy.ndarray</span></code>, from the passed
|
||||
<em>source</em>. <em>source</em> can be a <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SoftwareSprite" title="sdl2.ext.SoftwareSprite"><code class="xref py py-class docutils literal"><span class="pre">SoftwareSprite</span></code></a> or
|
||||
<code class="xref py py-class docutils literal"><span class="pre">sdl2.SDL_Surface</span></code>. The <code class="docutils literal"><span class="pre">SDL_Surface</span></code> of the <em>source</em> will be
|
||||
locked and unlocked automatically.</p>
|
||||
<p>The <em>source</em> pixels will be accessed and manipulated directly.</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last"><a class="reference internal" href="#sdl2.ext.pixels2d" title="sdl2.ext.pixels2d"><code class="xref py py-func docutils literal"><span class="pre">pixels2d()</span></code></a> is only usable, if the numpy package is available
|
||||
within the target environment. If numpy could not be imported, a
|
||||
<a class="reference internal" href="sdl2ext_compat.html#sdl2.ext.compat.UnsupportedError" title="sdl2.ext.compat.UnsupportedError"><code class="xref py py-exc docutils literal"><span class="pre">sdl2.ext.compat.UnsupportedError</span></code></a> will be raised.</p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.pixels3d">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">pixels3d</code><span class="sig-paren">(</span><em>source : object</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.pixels3d" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Creates a 3D pixel array, based on <code class="docutils literal"><span class="pre">numpy.ndarray</span></code>, from the passed
|
||||
<em>source</em>. <em>source</em> can be a <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.SoftwareSprite" title="sdl2.ext.SoftwareSprite"><code class="xref py py-class docutils literal"><span class="pre">SoftwareSprite</span></code></a>
|
||||
or <code class="xref py py-class docutils literal"><span class="pre">sdl2.SDL_Surface</span></code>. The <code class="docutils literal"><span class="pre">SDL_Surface</span></code> of the <em>source</em>
|
||||
will be locked and unlocked automatically.</p>
|
||||
<p>The <em>source</em> pixels will be accessed and manipulated directly.</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last"><a class="reference internal" href="#sdl2.ext.pixels3d" title="sdl2.ext.pixels3d"><code class="xref py py-func docutils literal"><span class="pre">pixels3d()</span></code></a> is only usable, if the numpy package is available
|
||||
within the target environment. If numpy could not be imported, a
|
||||
<a class="reference internal" href="sdl2ext_compat.html#sdl2.ext.compat.UnsupportedError" title="sdl2.ext.compat.UnsupportedError"><code class="xref py py-exc docutils literal"><span class="pre">sdl2.ext.compat.UnsupportedError</span></code></a> will be raised.</p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_particles.html"
|
||||
title="previous chapter">sdl2.ext.particles - A simple particle system</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_resources.html"
|
||||
title="next chapter">Resource management</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_pixelaccess.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_resources.html" title="Resource management"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_particles.html" title="sdl2.ext.particles - A simple particle system"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,312 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Resource management — PySDL2 0.9.5 documentation</title>
|
||||
|
||||
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.9.5',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
|
||||
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
|
||||
<link rel="next" title="Sprite, texture and pixel surface routines" href="sdl2ext_sprite.html" />
|
||||
<link rel="prev" title="2D and 3D direct pixel access" href="sdl2ext_pixelaccess.html" />
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
accesskey="I">index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_sprite.html" title="Sprite, texture and pixel surface routines"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_pixelaccess.html" title="2D and 3D direct pixel access"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="resource-management">
|
||||
<h1>Resource management<a class="headerlink" href="#resource-management" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Every application usually ships with various resources, such as image and data
|
||||
files, configuration files and so on. Accessing those files in the folder
|
||||
hierarchy or in a bundled format for various platforms can become a complex
|
||||
task. The <a class="reference internal" href="#sdl2.ext.Resources" title="sdl2.ext.Resources"><code class="xref py py-class docutils literal"><span class="pre">Resources</span></code></a> class allows you to manage different application
|
||||
data in a certain directory, providing a dictionary-style access functionality
|
||||
for your in-application resources.</p>
|
||||
<p>Let’s assume, your application has the following installation layout</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">Application</span> <span class="n">Directory</span>
|
||||
<span class="n">Application</span><span class="o">.</span><span class="n">exe</span>
|
||||
<span class="n">Application</span><span class="o">.</span><span class="n">conf</span>
|
||||
<span class="n">data</span><span class="o">/</span>
|
||||
<span class="n">background</span><span class="o">.</span><span class="n">jpg</span>
|
||||
<span class="n">button1</span><span class="o">.</span><span class="n">jpg</span>
|
||||
<span class="n">button2</span><span class="o">.</span><span class="n">jpg</span>
|
||||
<span class="n">info</span><span class="o">.</span><span class="n">dat</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Within the <code class="docutils literal"><span class="pre">Application.exe</span></code> code, you can - completely system-agnostic -
|
||||
define a new resource that keeps track of all <code class="docutils literal"><span class="pre">data</span></code> items.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">apppath</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">__file__</span><span class="p">))</span>
|
||||
<span class="n">appresources</span> <span class="o">=</span> <span class="n">Resources</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">apppath</span><span class="p">,</span> <span class="s2">"data"</span><span class="p">))</span>
|
||||
<span class="c1"># Access some images</span>
|
||||
<span class="n">bgimage</span> <span class="o">=</span> <span class="n">appresources</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"background.jpg"</span><span class="p">)</span>
|
||||
<span class="n">btn1image</span> <span class="o">=</span> <span class="n">appresources</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"button1.jpg"</span><span class="p">)</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>To access individual files, you do not need to concat paths the whole
|
||||
time and regardless of the current directory, your application operates
|
||||
on, you can access your resource files at any time through the
|
||||
<a class="reference internal" href="#sdl2.ext.Resources" title="sdl2.ext.Resources"><code class="xref py py-class docutils literal"><span class="pre">Resources</span></code></a> instance, you created initially.</p>
|
||||
<p>The <a class="reference internal" href="#sdl2.ext.Resources" title="sdl2.ext.Resources"><code class="xref py py-class docutils literal"><span class="pre">Resources</span></code></a> class is also able to scan an index archived files,
|
||||
compressed via ZIP or TAR (gzip or bzip2 compression), and subdiectories
|
||||
automatically.</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">Application</span> <span class="n">Directory</span>
|
||||
<span class="n">Application</span><span class="o">.</span><span class="n">exe</span>
|
||||
<span class="n">Application</span><span class="o">.</span><span class="n">conf</span>
|
||||
<span class="n">data</span><span class="o">/</span>
|
||||
<span class="n">audio</span><span class="o">/</span>
|
||||
<span class="n">example</span><span class="o">.</span><span class="n">wav</span>
|
||||
<span class="n">background</span><span class="o">.</span><span class="n">jpg</span>
|
||||
<span class="n">button1</span><span class="o">.</span><span class="n">jpg</span>
|
||||
<span class="n">button2</span><span class="o">.</span><span class="n">jpg</span>
|
||||
<span class="n">graphics</span><span class="o">.</span><span class="n">zip</span>
|
||||
<span class="p">[</span><span class="n">tileset1</span><span class="o">.</span><span class="n">bmp</span>
|
||||
<span class="n">tileset2</span><span class="o">.</span><span class="n">bmp</span>
|
||||
<span class="n">tileset3</span><span class="o">.</span><span class="n">bmp</span>
|
||||
<span class="p">]</span>
|
||||
<span class="n">info</span><span class="o">.</span><span class="n">dat</span>
|
||||
|
||||
<span class="n">tilesimage</span> <span class="o">=</span> <span class="n">appresources</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"tileset1.bmp"</span><span class="p">)</span>
|
||||
<span class="n">audiofile</span> <span class="o">=</span> <span class="n">appresources</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"example.wav"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>If you request an indexed file via <a class="reference internal" href="#sdl2.ext.Resources.get" title="sdl2.ext.Resources.get"><code class="xref py py-meth docutils literal"><span class="pre">Resources.get()</span></code></a>, you will receive
|
||||
a <a class="reference external" href="http://docs.python.org/library/io.html#io.BytesIO" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">io.BytesIO</span></code></a> stream, containing the file data, for further processing.</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">The scanned files act as keys within the <a class="reference internal" href="#sdl2.ext.Resources" title="sdl2.ext.Resources"><code class="xref py py-class docutils literal"><span class="pre">Resources</span></code></a> class. This
|
||||
means that two files, that have the same name, but are located in different
|
||||
directories, will not be indexed. Only one of them will be accessible
|
||||
through the <a class="reference internal" href="#sdl2.ext.Resources" title="sdl2.ext.Resources"><code class="xref py py-class docutils literal"><span class="pre">Resources</span></code></a> class.</p>
|
||||
</div>
|
||||
<div class="section" id="api">
|
||||
<h2>API<a class="headerlink" href="#api" title="Permalink to this headline">¶</a></h2>
|
||||
<dl class="class">
|
||||
<dt id="sdl2.ext.Resources">
|
||||
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">Resources</code><span class="sig-paren">(</span><span class="optional">[</span><em>path=None</em><span class="optional">[</span>, <em>subdir=None</em><span class="optional">[</span>, <em>excludepattern=None</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.Resources" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The Resources class manages a set of file resources and eases
|
||||
accessing them by using relative paths, scanning archives
|
||||
automatically and so on.</p>
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.Resources.add">
|
||||
<code class="descname">add</code><span class="sig-paren">(</span><em>filename : string</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.Resources.add" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Adds a file to the resource container. Depending on the
|
||||
file type (determined by the file suffix or name) the file will be
|
||||
automatically scanned (if it is an archive) or checked for
|
||||
availability (if it is a stream or network resource).</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.Resources.add_archive">
|
||||
<code class="descname">add_archive</code><span class="sig-paren">(</span><em>filename : string</em><span class="optional">[</span>, <em>typehint="zip"</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.Resources.add_archive" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Adds an archive file to the resource container. This will scan the
|
||||
passed archive and add its contents to the list of available and
|
||||
accessible resources.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.Resources.add_file">
|
||||
<code class="descname">add_file</code><span class="sig-paren">(</span><em>filename : string</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.Resources.add_file" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Adds a file to the resource container. This will only add the
|
||||
passed file and do not scan an archive or check the file for
|
||||
availability.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.Resources.get">
|
||||
<code class="descname">get</code><span class="sig-paren">(</span><em>filename : string</em><span class="sig-paren">)</span> → BytesIO<a class="headerlink" href="#sdl2.ext.Resources.get" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Gets a specific file from the resource container.</p>
|
||||
<p>Raises a <code class="xref py py-exc docutils literal"><span class="pre">KeyError</span></code>, if the <em>filename</em> could not be found.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.Resources.get_filelike">
|
||||
<code class="descname">get_filelike</code><span class="sig-paren">(</span><em>filename : string</em><span class="sig-paren">)</span> → file object<a class="headerlink" href="#sdl2.ext.Resources.get_filelike" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Similar to <a class="reference internal" href="#sdl2.ext.Resources.get" title="sdl2.ext.Resources.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a>, but tries to return the original file
|
||||
handle, if possible. If the found file is only available within an
|
||||
archive, a <a class="reference external" href="http://docs.python.org/library/io.html#io.BytesIO" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">io.BytesIO</span></code></a> instance will be returned.</p>
|
||||
<p>Raises a <code class="xref py py-exc docutils literal"><span class="pre">KeyError</span></code>, if the <em>filename</em> could not be found.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.Resources.get_path">
|
||||
<code class="descname">get_path</code><span class="sig-paren">(</span><em>filename : string</em><span class="sig-paren">)</span> → string<a class="headerlink" href="#sdl2.ext.Resources.get_path" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Gets the path of the passed <em>filename</em>. If <em>filename</em> is only
|
||||
available within an archive, a string in the form
|
||||
<code class="docutils literal"><span class="pre">filename@archivename</span></code> will be returned.</p>
|
||||
<p>Raises a <code class="xref py py-exc docutils literal"><span class="pre">KeyError</span></code>, if the <em>filename</em> could not be found.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="sdl2.ext.Resources.scan">
|
||||
<code class="descname">scan</code><span class="sig-paren">(</span><em>path : string[, subdir=None[, excludepattern=None]</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.Resources.scan" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Scans a path and adds all found files to the resource
|
||||
container. If a file within the path is a supported archive (ZIP
|
||||
or TAR), its contents will be indexed aut added automatically.</p>
|
||||
<p>The method will consider the directory part (<code class="docutils literal"><span class="pre">os.path.dirname</span></code>)
|
||||
of the provided <em>path</em> as path to scan, if the path is not a
|
||||
directory. If <em>subdir</em> is provided, it will be appended to the
|
||||
path and used as starting point for adding files to the resource
|
||||
container.</p>
|
||||
<p><em>excludepattern</em> can be a regular expression to skip
|
||||
directories, which match the pattern.</p>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.open_tarfile">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">open_tarfile</code><span class="sig-paren">(</span><em>archive : string</em>, <em>filename : string</em><span class="optional">[</span>, <em>directory=None</em><span class="optional">[</span>, <em>ftype=None</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span> → BytesIO<a class="headerlink" href="#sdl2.ext.open_tarfile" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Opens and reads a certain file from a TAR archive. The result is
|
||||
returned as <code class="xref py py-class docutils literal"><span class="pre">BytesIO</span></code> stream. <em>filename</em> can be a relative
|
||||
or absolute path within the TAR archive. The optional <em>directory</em>
|
||||
argument can be used to supply a relative directory path, under which
|
||||
<em>filename</em> will be searched.</p>
|
||||
<p><em>ftype</em> is used to supply additional compression information, in
|
||||
case the system cannot determine the compression type itself, and can
|
||||
be either <strong>“gz”</strong> for gzip compression or <strong>“bz2”</strong> for bzip2
|
||||
compression.</p>
|
||||
<p>If the filename could not be found or an error occurred on reading it,
|
||||
<code class="docutils literal"><span class="pre">None</span></code> will be returned.</p>
|
||||
<p>Raises a <code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code>, if <em>archive</em> is not a valid TAR archive or
|
||||
if <em>ftype</em> is not a valid value of (“gz”, “bz2”).</p>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">If <em>ftype</em> is supplied, the compression mode will be enforced for
|
||||
opening and reading.</p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.open_url">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">open_url</code><span class="sig-paren">(</span><em>filename : string</em><span class="optional">[</span>, <em>basepath=None</em><span class="optional">]</span><span class="sig-paren">)</span> → file object<a class="headerlink" href="#sdl2.ext.open_url" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Opens and reads a certain file from a web or remote location. This
|
||||
function utilizes the <a class="reference external" href="http://docs.python.org/library/urllib2.html#module-urllib2" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">urllib2</span></code></a> module for Python 2.7 and
|
||||
<a class="reference external" href="http://docs.python.org/library/urllib.html#module-urllib" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">urllib</span></code></a> for Python 3.x, which means that it is restricted to
|
||||
the types of remote locations supported by the module.</p>
|
||||
<p><em>basepath</em> can be used to supply an additional location prefix.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="sdl2.ext.open_zipfile">
|
||||
<code class="descclassname">sdl2.ext.</code><code class="descname">open_zipfile</code><span class="sig-paren">(</span><em>archive : string</em>, <em>filename : string</em><span class="optional">[</span>, <em>directory : string</em><span class="optional">]</span><span class="sig-paren">)</span> → BytesIO<a class="headerlink" href="#sdl2.ext.open_zipfile" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Opens and reads a certain file from a ZIP archive. The result is
|
||||
returned as <code class="xref py py-class docutils literal"><span class="pre">BytesIO</span></code> stream. <em>filename</em> can be a relative
|
||||
or absolute path within the ZIP archive. The optional <em>directory</em>
|
||||
argument can be used to supply a relative directory path, under which
|
||||
<em>filename</em> will be searched.</p>
|
||||
<p>If the filename could not be found, a <code class="xref py py-exc docutils literal"><span class="pre">KeyError</span></code> will be raised.
|
||||
Raises a <code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code>, if <em>archive</em> is not a valid ZIP archive.</p>
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="../index.html">Table Of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">Resource management</a><ul>
|
||||
<li><a class="reference internal" href="#api">API</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_pixelaccess.html"
|
||||
title="previous chapter">2D and 3D direct pixel access</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="sdl2ext_sprite.html"
|
||||
title="next chapter">Sprite, texture and pixel surface routines</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/modules/sdl2ext_resources.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3>Quick search</h3>
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div><input type="text" name="q" /></div>
|
||||
<div><input type="submit" value="Go" /></div>
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
<ul>
|
||||
<li class="right" style="margin-right: 10px">
|
||||
<a href="../genindex.html" title="General Index"
|
||||
>index</a></li>
|
||||
<li class="right" >
|
||||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_sprite.html" title="Sprite, texture and pixel surface routines"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="sdl2ext_pixelaccess.html" title="2D and 3D direct pixel access"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2013-2016, Marcus von Appen.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|