GraphicBlock(3U)

πŸ’– GraphicBlock β€” the interactor that shows off a graphic πŸ’–

okay so this is GraphicBlock(3U) from the InterViews Reference Manual, and bestie, it's literally just an interactor whose whole personality is displaying a graphic. iconic behavior honestly.


✨ SYNOPSIS ✨

#include <Unidraw/Graphic/grblock.h>

🌸 NAME 🌸

GraphicBlock β€” an interactor that displays a graphic. that's it. that's the girl. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so a GraphicBlock is an interactor that displays a graphic, periodt. and the way that this is so useful is for interactors whose whole look is easiest to define with structured graphics β€” like, why fight it when structured graphics already ate? your GraphicBlock will draw its graphic whenever it gets a Draw or a Redraw call. no cap, it just does it. ✨

the graphic can also be aligned with respect to the GraphicBlock's canvas. here's the tea: the GraphicBlock positions its graphic so that its bounding box is aligned with the canvas when the canvas is allocated. on subsequent resizes, the portion of the graphic within the canvas is aligned. with the default alignment, for example, a graphic will be centered in the canvas initially. and if the canvas gets resized? then the part of the graphic that was in the center of the canvas before resizing will appear in the center of the canvas after resizing. it's giving "always keeps its fave in frame." πŸ“Έ

the graphic can be scrolled and zoomed as well. changing either the curwidth/curheight or the width/height members of the GraphicBlock's perspective effectively zooms the graphic. for example β€” and this one's important, write it down β€” calling the Adjust member function with a perspective whose curwidth and curheight are half that of the GraphicBlock's canvas will enlarge the graphic by a factor of two. πŸ” you can limit zooming to magnifications that are powers of two by specifying Binary for the Zooming parameter. slay.

and a GraphicBlock's natural size depends on the size of the graphic it displays and on any padding (that's white space surrounding the graphic, iykyk) that you specify. also: GraphicBlocks are infinitely stretchable horizontally and vertically by default. infinitely. stretchy. πŸ‘‘


πŸ’– PUBLIC OPERATIONS πŸ’–

  • GraphicBlock(Graphic*, Coord pad = 0, Alignment = Center, Zooming = Continuous)
  • GraphicBlock(const char*, Graphic*, Coord pad = 0, Alignment = Center, Zooming = Continuous) β€” create a new GraphicBlock with the specified graphic, padding, alignment, and zooming behavior. and yes, with the second form you can also specify the GraphicBlock's instance name. two flavors, both valid. πŸ“
  • void Update() β€” Update updates the GraphicBlock's perspective to reflect any change in the values returned by GetGraphicBox (described below, keep scrolling bestie), which defines the extremities of the scrolling area. Update should be called after the graphic is changed. don't skip this step, fr fr.
  • virtual void Highlight(boolean) β€” when highlighted, GraphicBlock draws itself with the foreground and background colors of its graphic and its painter reversed. 😳 reversed!! GraphicBlock uses its output painter to fill its canvas with background color, thus providing a background for the graphic. aesthetic support system.
  • Graphic* GetGraphic() β€” return the graphic in the GraphicBlock, stored in the _graphic protected member variable. she's protected, she's variable, she's yours. πŸ’œ
  • float GetMagnification()
  • void SetMagnification(float) β€” get and set the magnification applied to the graphic, relative to its magnification when the GraphicBlock was created (that's 1x, the baseline, the original selfie). 🌈

πŸŽ€ PROTECTED OPERATIONS πŸŽ€

  • void Init() β€” initialize the GraphicBlock, positioning its graphic according to the alignment specified in the constructor. the constructor calls this operation. subclasses should call Init if they should replace the displayed graphic with another. new graphic, who dis. πŸ’…
  • void UpdatePerspective() β€” change the GraphicBlock's perspective to reflect the bounding box of the graphic. UpdatePerspective encapsulates this functionality to facilitate redefinition of the Update function in derived classes. encapsulation nation, we love to see it.
  • void GrabScroll(Event&)
  • void RateScroll(Event&) β€” initiate grab scrolling or rate scrolling. once called, GrabScroll (RateScroll) polls the current mouse position as long as the middle (right) button is pressed. ⚠️ middle button for GrabScroll, right button for RateScroll, do not mix these up.

as GrabScroll polls, it scrolls the GraphicBlock to follow the mouse position, making it appear as though the user is dragging the GraphicBlock's graphic itself. so fun. so tactile.

each time RateScroll polls the mouse, it scrolls the GraphicBlock by an amount corresponding to the differential between the current and initial mouse positions. this creates the illusion of a joystick interface: the further away the mouse is from its initial position, the greater the scrolling increment and the faster the graphic appears to scroll; scrolling slows down, stops, and reverses direction as the user drags the mouse back towards and past the initial position. πŸ•ΉοΈ literally a joystick. the range of motion is giving main character energy.

  • virtual void GetGraphicBox(Coord&, Coord&, Coord&, Coord&) β€” return the lower-left and upper-right coordinates of the total area in which to scroll. by default, this area corresponds to the graphic's bounding box. (the original says "this area is corresponds to" β€” typo stays a mystery, but the meaning is clear: bounding box, default, done.) πŸ“¦
  • virtual void Zoom(Perspective&)
  • virtual void Scroll(Perspective&) β€” these functions define how zooming and scrolling are inferred from the perspective supplied to Adjust. the default behaviors implement standard scrolling semantics and zooming as described above. (scroll up if you need the recap, bestie πŸ’–)
  • virtual float LimitMagnification(float) β€” limit the amount of magnification that can be applied to the graphic. this function is used as a filter to convert desired magnifications into legal ones. by default, the argument is returned; no limits are imposed. she said "no limits, I'm free." πŸ¦‹

πŸ‘‘ SEE ALSO πŸ‘‘

  • Graphic(3U)
  • Interactor(3I)
  • Perspective(3I)

go read those next, they're the supporting cast and they ate too.


a lil note for my besties: GraphicBlock is the one you reach for when your interactor's look is structured-graphics-shaped, and you want it centered, scrollable, zoomable, and infinitely stretchy with zero extra effort. obsessed.

okay and that's the whole page!! this one came from the InterViews Reference Manual, it's GraphicBlock(3U), and the source/version + date at the bottom of the original was Unidraw, 30 January 1991 β€” so shoutout to Unidraw and to January 1991 for giving us this absolute classic. πŸ«ΆπŸŽ€βœ¨