Tk_GetPixelsFromObj(3tk)

πŸ’– Tk_GetPixelsFromObj β€” bestie's guide to screen units πŸ’–

okay so. this is Tk_GetPixelsFromObj(3tk), a page from the Tk Library Procedures collection, and it's literally the group chat where strings meet screen distances. you bring a number, you bring a unit, and Tk hands you back pixels or millimeters. no cap. πŸŽ€


✨ NAME ✨

Tk_GetPixelsFromObj, Tk_GetPixels, Tk_GetMMFromObj, Tk_GetScreenMM, Tk_GetDoublePixelsFromObj β€” the whole squad that translates between strings and screen units πŸ¦‹


🌸 SYNOPSIS 🌸

#include <tk.h>

int
Tk_GetPixelsFromObj(interp, tkwin, objPtr, intPtr)

int
Tk_GetDoublePixelsFromObj(interp, tkwin, objPtr, doublePtr)

int
Tk_GetPixels(interp, tkwin, string, intPtr)

int
Tk_GetMMFromObj(interp, tkwin, objPtr, doublePtr)

int
Tk_GetScreenMM(interp, tkwin, string, doublePtr)

πŸ‘‘ ARGUMENTS πŸ‘‘

  • Tcl_Interp *interp (in) β€” the interpreter that handles error reporting. if something goes sideways, this is where the drama gets posted. πŸ’…
  • Tk_Window tkwin (in) β€” the window whose screen geometry is what decides how absolute units turn into pixels. geometry queen behavior. πŸ‘‘
  • Tcl_Obj *objPtr (in/out) β€” its string value says how far something is on screen; the internal rep gets modified so the converted distance is cached for later. glow-up of an object fr fr. ✨
  • const char *string (in) β€” same energy as objPtr, except the distance spec arrives as a plain string instead.
  • int *intPtr (out) β€” pointer to where the converted distance in pixels goes to live. 🏠
  • double *doublePtr (out) β€” pointer to where the converted distance in millimeters gets stored.

πŸ’œ DESCRIPTION πŸ’œ

so these procedures take a spec of a distance on screen (objPtr or string) and compute the matching distance, either as integer pixels or as floating-point millimeters. either way, objPtr or string describes a screen distance as a floating-point number followed by one of these little unit characters. the unit character is doing the main character work here:

  • <none> β€” no character? the number is just a distance in pixels. simple. iconic.
  • c β€” the number is a distance in centimeters on the screen.
  • i β€” the number is a distance in inches on the screen.
  • m β€” the number is a distance in millimeters on the screen.
  • p β€” the number is a distance in printer's points (1/72 inch) on the screen.

Tk_GetPixelsFromObj converts the value of objPtr to the nearest even number of pixels and stashes it at *intPtr. under normal circumstances it returns TCL_OK. but if an error happens β€” like, say, objPtr holds a number followed by a character that isn't one of the ones above 😭 β€” then TCL_ERROR comes back and an error message is left in interp's result, as long as interp isn't NULL. and because it's an overachiever, Tk_GetPixelsFromObj caches info about the return value in objPtr, which speeds up future calls to Tk_GetPixelsFromObj with that same objPtr. efficiency ate. πŸ’…

Tk_GetDoublePixelsFromObj is identical to Tk_GetPixelsFromObj, except it returns a double β€” not rounded to the nearest integer. no rounding, all precision, that's the vibe. 🌈

Tk_GetPixels is identical to Tk_GetPixelsFromObj, except the screen distance comes in as a string instead of an object. and because of that, it can't cache the return value, so Tk_GetPixels is less efficient than Tk_GetPixelsFromObj. ngl bestie, if you have the choice, take the object version. 🫢

Tk_GetMMFromObj and Tk_GetScreenMM are similar to Tk_GetPixelsFromObj and Tk_GetPixels (respectively, matching them up like a cute little buddy system 🧚), except they convert the screen distance to millimeters and store a double-precision floating-point result at *doublePtr.

heads up: if you hand over a number with a unit character that isn't <none>, c, i, m, or p, you're getting TCL_ERROR and an error message in interp's result. no silent nonsense here. πŸ’€

πŸ“ KEYWORDS πŸ“

centimeters, convert, inches, millimeters, pixels, points, screen units β€” that's the whole tag list, slay ⭐


and that's the page!! source is Tk, version 8.1, and the manual entry is Tk_GetPixelsFromObj(3tk). go forth and convert your units, bestie, you're gonna do amazing πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

πŸ“¦ where this page comes from