set_cursor_drawer(3)

πŸ“¦ version 1.6, in fedora 43, fedora 44

πŸ’– set_cursor_drawer πŸ’–

okay so bestie, welcome to the gstream manual, and today's main character is set_cursor_drawer β€” the glow-up your cursor has been waiting for ✨


🌸 NAME 🌸

set_cursor_drawer β€” like, literally the function that lets you pick who draws your cursor πŸŽ€


✨ SYNOPSIS ✨

#include <gstream.h>

void set_cursor_drawer(void (*cd)(BITMAP *, int, int, int, int, int,
bool));

πŸ¦‹ DESCRIPTION πŸ¦‹

so what this does is it sets the function that draws the cursor. it's giving "customize your cursor with your own fave little guy" energy β€” and yeah, that little guy can absolutely be a BITMAP if that's your vibe πŸ’…

but listen, no cap: before you can actually use that cursor for inputting, you also have to call set_cursor_dimensions with the width and height of your cursor β€” and you gotta do it for both insert mode and overwrite mode. both. don't skip one, i'm begging 😭

so here's the tea on the drawer function's parameters:

  • destination bitmap β€” the BITMAP you're drawing on πŸ–ΌοΈ
  • x-coordinate πŸ“
  • y-coordinate πŸ“
  • the width β€” and if you passed gbuf::DYNAMIC_CURSOR_SIZE, this is the width of the character under the cursor; otherwise it's the width you specified
  • the height β€” same deal as the width, ditto 🫢
  • the colour of the font β€” ⚠️ watch out for a -1! she's tricky!
  • whether in insert mode β€” true if so βœ…

here's a simple lil example of a standard console cursor, iconic behavior:

void cd_cons(BITMAP *bmp, int x, int y, int w, int h, int c, bool ins)
{
  int colour;

  // determine colour (defaults to black if no colour specified)
  if (c == -1)
    colour = makecol_depth(bitmap_color_depth(bmp), 0, 0, 0);
  else
    colour = c;

  if (ins)  // if it is the insert cursor
    rectfill(bmp, x, y + h - 2, x + w - 1, y + h - 1, colour);
  else      // else overwrite cursor
    rectfill(bmp, x, y, x + w - 1, y + h - 1, colour);
}

okay and here's the part where you can fully relax: you do not have to think about flashing the cursor or any of those other pecularities β€” the gstream handles all of that for you, bestie 🧚 all you gotta do is construct a function that draws something on the specified BITMAP, at the specified position, and doesn't go past the specified width and height. that's it. that's the whole job.

and yes, you are of course free to ignore the colour and the insert parameter β€” go off, do your thing πŸ™ˆ

⚠️ but fr fr: make sure you don't draw outside the given rectangle. if you do, the gstream can't recover the background and the result will be artifacts. and not the cute kind of artifacts. the bad kind. πŸ’€

little quality-of-life moment: there's a typedef, 'cursor_drawer', in 'gbuf', and it makes declaring pointers to this type of function sooo easy:

gbuf::cursor_drawer tmp_cd;

//...

tmp_cd = gs1.get_cursor_drawer();
gs1.set_cursor_drawer(gs2.get_cursor_drawer());
gs2.set_cursor_drawer(tmp_cd);

(not me writing a whole lil swap routine, we love to see it πŸ”₯)

and the default cursor drawer? that's 'cd_winconsole'. the OG. πŸ‘‘


🌈 SEE ALSO 🌈


and that's the whole page, bestie!! πŸ’œ this one's from the gstream manual, version 1.6, and it's the set_cursor_drawer(3) page β€” go forth and make your cursor absolutely stunning πŸŽ€βœ¨πŸ¦‹πŸŒΈπŸ‘‘

πŸ“¦ where this page comes from