File: cursors.rst

package info (click to toggle)
pygame 1.9.4.post1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,412 kB
  • sloc: ansic: 54,632; python: 28,791; objc: 334; php: 92; sh: 76; makefile: 36; cpp: 25
file content (128 lines) | stat: -rw-r--r-- 4,216 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
.. include:: common.txt

:mod:`pygame.cursors`
=====================

.. module:: pygame.cursors
   :synopsis: pygame module for cursor resources

| :sl:`pygame module for cursor resources`

Pygame offers control over the system hardware cursor. Pygame only supports
black and white cursors for the system. You control the cursor with functions
inside :mod:`pygame.mouse`.

This cursors module contains functions for loading and decoding various
cursor formats. These allow you to easily store your cursors in external files
or directly as encoded python strings.

The module includes several standard cursors. The ``pygame.mouse.set_cursor()``
function takes several arguments. All those arguments have been stored in a
single tuple you can call like this:

::

   >>> pygame.mouse.set_cursor(*pygame.cursors.arrow)

This module also contains a few cursors as formatted strings. You'll need to
pass these to ``pygame.cursors.compile()`` function before you can use them.
The example call would look like this:

::

   >>> cursor = pygame.cursors.compile(pygame.cursors.textmarker_strings)
   >>> pygame.mouse.set_cursor(*cursor)

The following variables are cursor bitmaps that can be used as cursor:

   * ``pygame.cursors.arrow``

   * ``pygame.cursors.diamond``

   * ``pygame.cursors.broken_x``

   * ``pygame.cursors.tri_left``

   * ``pygame.cursors.tri_right``

The following strings can be converted into cursor bitmaps with
``pygame.cursors.compile()`` :

   * ``pygame.cursors.thickarrow_strings``

   * ``pygame.cursors.sizer_x_strings``

   * ``pygame.cursors.sizer_y_strings``

   * ``pygame.cursors.sizer_xy_strings``

.. function:: compile

   | :sl:`create binary cursor data from simple strings`
   | :sg:`compile(strings, black='X', white='.', xor='o') -> data, mask`

   A sequence of strings can be used to create binary cursor data for the
   system cursor. The return values are the same format needed by
   ``pygame.mouse.set_cursor()``.

   If you are creating your own cursor strings, you can use any value represent
   the black and white pixels. Some system allow you to set a special toggle
   color for the system color, this is also called the xor color. If the system
   does not support xor cursors, that color will simply be black.

   The width of the strings must all be equal and be divisible by 8. An example
   set of cursor strings looks like this

   ::

       thickarrow_strings = (               #sized 24x24
         "XX                      ",
         "XXX                     ",
         "XXXX                    ",
         "XX.XX                   ",
         "XX..XX                  ",
         "XX...XX                 ",
         "XX....XX                ",
         "XX.....XX               ",
         "XX......XX              ",
         "XX.......XX             ",
         "XX........XX            ",
         "XX........XXX           ",
         "XX......XXXXX           ",
         "XX.XXX..XX              ",
         "XXXX XX..XX             ",
         "XX   XX..XX             ",
         "     XX..XX             ",
         "      XX..XX            ",
         "      XX..XX            ",
         "       XXXX             ",
         "       XX               ",
         "                        ",
         "                        ",
         "                        ")

   .. ## pygame.cursors.compile ##

.. function:: load_xbm

   | :sl:`load cursor data from an XBM file`
   | :sg:`load_xbm(cursorfile) -> cursor_args`
   | :sg:`load_xbm(cursorfile, maskfile) -> cursor_args`

   This loads cursors for a simple subset of ``XBM`` files. ``XBM`` files are
   traditionally used to store cursors on UNIX systems, they are an ASCII
   format used to represent simple images.

   Sometimes the black and white color values will be split into two separate
   ``XBM`` files. You can pass a second maskfile argument to load the two
   images into a single cursor.

   The cursorfile and maskfile arguments can either be filenames or file-like
   object with the readlines method.

   The return value cursor_args can be passed directly to the
   ``pygame.mouse.set_cursor()`` function.

   .. ## pygame.cursors.load_xbm ##

.. ## pygame.cursors ##