Debian Codegraph @

fltk/test/doublebuffer.py

raw symbols SCIP
1 # Double-buffering test program for the Python port of
2 # the Fast Light Tool Kit (pyFLTK).
3 #
4 # This demo shows how double buffering helps, by drawing the
5 # window in a particularily bad way.
6 #
7 # The single-buffered window will blink as it updates. The
8 # double buffered one will not. It will take just as long
9 # (or longer) to update, but often it will appear to be faster.
10 #
11 # This demo should work for both the GL and X versions of Fl,
12 # even though the double buffering mechanism is totally different.
13 #
14 #
15 # FLTk is Copyright 1998-2003 by Bill Spitzak and others.
16 # pyFLTK is Copyright 2003 by Andreas Held
17 #
18 # This library is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU Library General Public
20 # License, version 2.0 as published by the Free Software Foundation.
21 #
22 # This library is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 # Library General Public License for more details.
26 #
27 # You should have received a copy of the GNU Library General Public
28 # License along with this library; if not, write to the Free Software
29 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 # USA.
31 #
32 # Please report all bugs and problems to "[email protected]".
33 #
34
35 from fltk import *
36 import sys
37 import math
38
39 w01 = None
40 w1 = None
41 slider0 = None
42
43 # this purposely draws each line 10 times to be slow:
44 def star(w, h, n):
45 fl_push_matrix()
46 fl_translate(w/2, h/2)
47 fl_scale(w/2, h/2)
48
49 for i in range(n):
50 val_i = 2*math.pi*i/n+.1
51 j = i+1
52 while j < n:
53 val_j = 2*math.pi*j/n+.1
54 fl_begin_line();
55 fl_vertex(math.cos(val_i), math.sin(val_i))
56 fl_vertex(math.cos(val_j), math.sin(val_j))
57 fl_end_line()
58 j = j+1
59
60 fl_pop_matrix()
61
62
63 sides = [20,20]
64
65 def slider_cb(slider, v):
66 sides[v] = int(slider.value())
67 # redraw figure only
68 slider.parent().child(0).redraw()
69
70
71 def bad_draw(w,h,which):
72 fl_color(FL_BLACK)
73 fl_rectf(0,0,w,h)
74 fl_color(FL_WHITE)
75 star(w,h,sides[which]);
76
77
78 class single_blink_window(Fl_Single_Window):
79 def __init__(self, x, y, w, h, l):
80 Fl_Single_Window.__init__(self, x, y, w, h, l)
81 self.resizable(self)
82
83 def draw(self):
84 bad_draw(self.w(), self.h(), 0)
85
86 # def handle(self, event):
87 # print "event = ", event
88 # return 0
89
90 class double_blink_window(Fl_Double_Window):
91 def __init__(self, x, y, w, h, l):
92 Fl_Double_Window.__init__(self, x, y, w, h, l)
93 self.resizable(self)
94
95 def draw(self):
96 bad_draw(self.w(), self.h(), 1)
97
98
99 if __name__ == '__main__':
100 if Fl.visual(FL_DOUBLE) == 0:
101 print("Xdbe not supported, faking double buffer with pixmaps.")
102
103 w01 = Fl_Window(420,465,"Fl_Single_Window")
104 w01.box(FL_FLAT_BOX)
105 w01.thiswon = 0
106 w1 = single_blink_window(10,10,400,400,"Fl_Single_Window")
107 w1.box(FL_FLAT_BOX)
108 w1.color(FL_BLACK)
109 w1.end()
110 slider0 = Fl_Hor_Slider(30,420,360,25)
111 slider0.range(2,30)
112 slider0.step(1)
113 slider0.value(sides[0])
114 slider0.callback(slider_cb, 0)
115 w01.end()
116
117 w02 = Fl_Window(420,465,"Fl_Double_Window")
118 w02.box(FL_FLAT_BOX)
119 w2 = double_blink_window(10,10,400,400,"Fl_Double_Window")
120 w2.box(FL_FLAT_BOX)
121 w2.color(FL_BLACK)
122 w2.end()
123 slider1 = Fl_Hor_Slider(30,420,360,25)
124 slider1.range(2,30)
125 slider1.step(1)
126 slider1.value(sides[0])
127 slider1.callback(slider_cb, 1)
128 w02.end()
129
130 w01.show(len(sys.argv), sys.argv)
131 w02.show()
132
133 # w1.redraw()
134
135 Fl.run()
136
137
138
139