1Prima::RubberBand(3) User Contributed Perl Documentation Prima::RubberBand(3)
2
3
4
6 Prima::RubberBand - draw rubberbands
7
9 The motivation for this module was that I was tired to see corrupted
10 screens on Windows 7 when dragging rubberbands in Prima code. Even
11 though MS somewhere warned of not doing any specific hacks to
12 circumvent the bug, I decided to give it a go anyway.
13
14 This module thus is a "Prima::Widget/rect_focus" with a safeguard. The
15 only thing it can do is to draw a static rubberband - but also remember
16 the last coordinates drawn, so cleaning comes for free.
17
18 The idea is that a rubberband object is meant to be a short-lived one:
19 as soon as it get instantiated it draws itself on the screen. When it
20 is destroyed, the rubberband is erased too.
21
23 use strict;
24 use Prima qw(Application RubberBand);
25
26 sub xordraw
27 {
28 my ($self, @new_rect) = @_;
29 $::application-> rubberband( @new_rect ?
30 ( rect => \@new_rect ) :
31 ( destroy => 1 )
32 );
33 }
34
35 Prima::MainWindow-> create(
36 onMouseDown => sub {
37 my ( $self, $btn, $mod, $x, $y) = @_;
38 $self-> {anchor} = [$self-> client_to_screen( $x, $y)];
39 xordraw( $self, @{$self-> {anchor}}, $self-> client_to_screen( $x, $y));
40 $self-> capture(1);
41 },
42 onMouseMove => sub {
43 my ( $self, $mod, $x, $y) = @_;
44 xordraw( $self, @{$self-> {anchor}}, $self-> client_to_screen( $x, $y)) if $self-> {anchor};
45 },
46 onMouseUp => sub {
47 my ( $self, $btn, $mod, $x, $y) = @_;
48 xordraw if delete $self-> {anchor};
49 $self-> capture(0);
50 },
51 );
52
53 run Prima;
54
56 new %properties
57 Creates a new RubberBand instance. See description of properties
58 below.
59
60 Properties
61 breadth INTEGER = 1
62 Defines rubberband breadth, in pixels.
63
64 canvas = $::application
65 Sets the painting surface, and also the widget (it must be a
66 widget) used for drawing.
67
68 clipRect X1, Y1, X2, Y2
69 Defines the clipping rectangle, in inclusive-inclusive coordinates.
70 If set to [-1,-1,-1,-1], means no clipping is done.
71
72 rect X1, Y1, X2, Y2
73 Defines the band geometry, in inclusive-inclusive coordinates. The
74 band is drawn so that its body is always inside these coordinates,
75 no matter what breadth is.
76
77 Methods
78 hide
79 Hides the band, if drawn
80
81 has_clip_rect
82 Checks whether clipRect contains an actual clippring rectange or it
83 is empty.
84
85 set %profile
86 Applies all properties
87
88 left, right, top, bottom, width, height, origin, size
89 Same shortcuts as in "Prima::Widget", but read-only.
90
91 show
92 Show the band, if invisible
93
95 The module adds a single method to "Prima::Widget" namespace,
96 "rubberband" (see example of use in the synopsis).
97
98 rubberband(%profile)
99 Instantiates a "Prima::RubberBand" with %profile, also sets
100 "canvas" to $self unless "canvas" is set explicitly.
101
102 rubberband()
103 Returns the existing "Prima::RubberBand" object
104
105 rubberband(destroy => 1)
106 Destroys the existing "Prima::RubberBand" object
107
109 Dmitry Karasik, <dmitry@karasik.eu.org>.
110
112 "rect_focus" in Prima::Widget, "grip.pl" in examples
113
114 Windows 7 Aero mode
115 Quote from
116 <http://blogs.msdn.com/b/greg_schechter/archive/2006/05/02/588934.aspx>
117 :
118
119 "One particularly dangerous practice is writing to the screen, either
120 through the use of GetDC(NULL) and writing to that, or attempting to do
121 XOR rubber-band lines, etc ... Since the UCE doesn't know about it,
122 it may get cleared in the next frame refresh, or it may persist for a
123 very long time, depending on what else needs to be updated on the
124 screen. (We really don't allow direct writing to the primary anyhow,
125 for that very reason... if you try to access the DirectDraw primary,
126 for instance, the DWM will turn off until the accessing application
127 exits)"
128
129 This quote seems to explain the effect why screen sometimes gets badly
130 corrupted when using a normal xor rubberband. UCE ( Update
131 Compatibility Evaluator ?? ) seems to be hacky enough to recognize some
132 situations, but not all.
133
134
135
136perl v5.34.1 2022-04-20 Prima::RubberBand(3)