Prima::...bberBand(3)

πŸ“¦
version 1.74000 Β· 5 versions
, in opensuse-leap 16.0

πŸ’… NAME πŸ’…

Prima::Widget::RubberBand β€” dynamic rubberbands ✨

okay bestie, you're on the Prima::...bberBand(3) page from User Contributed Perl Documentation β€” yes the title looks like it got elbowed by a ..., but we move. This is all about rubberbands that are dynamic, no cap.


✨ DESCRIPTION ✨

The motivation for this module was literally that I was tired of seeing corrupted screens on Windows 7 when dragging rubberbands in Prima code. MS somewhere warned people not to do any specific hacks to circumvent the bug, but I decided to give it a go anyway. Iconic behavior, honestly.

So this module is a Prima::Widget/rect_focus with a safeguard. The only thing it can do is draw a static rubberband β€” but it also remembers the last coordinates drawn, so cleaning and animation come for free. Free! We love that for us. πŸ’–

The idea is that a rubberband object is meant to be a short-lived one: as soon as it gets instantiated it draws itself on the screen. When it is destroyed, the rubberband is erased too. Very main character energy: show up, make a little rectangle, leave. 🫢


πŸŽ€ SYNOPSIS πŸŽ€

Here's the whole vibe in code, bestie:

use strict;
use Prima qw(Application Widget::RubberBand);

sub xordraw
{
        my ($self, @new_rect) = @_;
        $::application-> rubberband( @new_rect ?
                ( rect => \@new_rect ) :
                ( destroy => 1 )
        );
}

Prima::MainWindow-> new(
        onMouseDown => sub {
                my ( $self, $btn, $mod, $x, $y) = @_;
                $self-> {anchor} = [$self-> client_to_screen( $x, $y)];
                xordraw( $self, @{$self-> {anchor}}, $self-> client_to_screen( $x, $y));
                $self-> capture(1);
        },
        onMouseMove => sub {
                my ( $self, $mod, $x, $y) = @_;
                xordraw( $self, @{$self-> {anchor}}, $self-> client_to_screen( $x, $y)) if $self-> {anchor};
        },
        onMouseUp => sub {
                my ( $self, $btn, $mod, $x, $y) = @_;
                xordraw if delete $self-> {anchor};
                $self-> capture(0);
        },
);

run Prima;

πŸ’– API πŸ’–

  • new %properties β€” creates a new RubberBand instance. See the description of its properties below. Yes, the properties are right there. Keep scrolling. πŸ’…

πŸ¦‹ Properties πŸ¦‹

  • breadth INTEGER = 1 β€” defines the rubberband breadth in pixels.
  • canvas = $::application β€” sets the painting surface, and also the widget (it must be a widget) used for drawing.
  • clipRect X1, Y1, X2, Y2 β€” defines the clipping rectangle in inclusive-inclusive coordinates. If set to [-1,-1,-1,-1], that means no clipping is needed.
  • rect X1, Y1, X2, Y2 β€” defines the band geometry in inclusive-inclusive coordinates. The band is drawn so that its body is always inside these coordinates, no matter what the breadth is.

🌸 Methods 🌸

  • hide β€” hides the band.
  • has_clip_rect β€” checks whether clipRect contains an actual clipping rectangle or it is empty.
  • set %profile β€” applies all properties.
  • left, right, top, bottom, width, height, origin, size β€” the same shortcuts as in Prima::Widget, but read-only.
  • show β€” shows the band.

πŸ‘‘ Prima::Widget interface πŸ‘‘

The module adds a single method to the Prima::Widget namespace, rubberband (see example of use in the synopsis). It's giving tiny API, big power. πŸ’œ

  • rubberband(%profile) β€” instantiates a Prima::RubberBand object with %profile, also sets canvas to $self (unless canvas is set explicitly).
  • rubberband() β€” returns the existing Prima::RubberBand object.
  • rubberband(destroy => 1) β€” destroys the existing Prima::Widget::RubberBand object.

πŸ’Œ AUTHOR πŸ’Œ

Dmitry Karasik, <dmitry@karasik.eu.org>. ✨


πŸ”₯ SEE ALSO πŸ”₯

  • "rect_focus" in Prima::Widget
  • "grip.pl" in examples

πŸͺŸ Windows 7 Aero mode πŸͺŸ

Quote from <http://blogs.msdn.com/b/greg_schechter/archive/2006/05/02/588934.aspx>:

"One particularly dangerous practice is writing to the screen, either
through the use of GetDC(NULL) and writing to that, or attempting to do
XOR rubber-band lines, etc  ...  Since the UCE doesn't know about it, it
may get cleared in the next frame refresh, or it may persist for a very
long time, depending on what else needs to be updated on the screen.
(We really don't allow direct writing to the primary anyhow, for that
very reason... if you try to access the DirectDraw primary, for
instance, the DWM will turn off until the accessing application exits)"

So this quote seems to explain the effect of why the screen sometimes gets badly corrupted when using a normal xor rubberband. UCE ( Update Compatibility Evaluator ?? ) seems to be hacky enough to recognize some situations, but not all. πŸ’€


okay that's the whole page, bestie β€” source/version check says perl v5.42.0, date 2024-08-20, and the manual is Prima::...bberBand(3). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from