github.com/256dpi/max-go@v0.7.0/lib/max/jgraphics.h (about) 1 #ifndef _JGRAPHICS_H_ 2 #define _JGRAPHICS_H_ 3 4 #include "ext_prefix.h" 5 #include "jpatcher_api.h" 6 7 BEGIN_USING_C_LINKAGE 8 9 #if C74_PRAGMA_STRUCT_PACKPUSH 10 #pragma pack(push, 2) 11 #elif C74_PRAGMA_STRUCT_PACK 12 #pragma pack(2) 13 #endif 14 15 // opaque types for the users of jgraphics 16 #ifdef __cplusplus 17 struct t_jgraphics; 18 struct t_jpath; 19 struct t_jpattern; 20 struct t_jfont; 21 struct t_jtextlayout; 22 struct t_jtransform; 23 struct t_jsurface; 24 struct t_jdesktopui; 25 struct t_jpopupmenu; 26 struct t_jsvg; 27 struct t_jsvg_remap; 28 struct t_dpi_awareness_context; 29 #else 30 typedef struct _jgraphics t_jgraphics; ///< An instance of a jgraphics drawing context. @ingroup jgraphics 31 typedef struct _jpath t_jpath; ///< An instance of a jgraphics path. @ingroup jgraphics 32 typedef struct _jpattern t_jpattern; ///< An instance of a jgraphics pattern. @ingroup jpattern 33 typedef struct _jfont t_jfont; ///< An instance of a jgraphics font. @ingroup jfont 34 typedef struct _jtextlayout t_jtextlayout; ///< An instance of a jgraphics text layout object. @ingroup jgraphics 35 typedef struct _jtransform t_jtransform; ///< An instance of a jgraphics transform. @ingroup jgraphics 36 typedef struct _jsurface t_jsurface; ///< An instance of a jgraphics surface. @ingroup jsurface 37 typedef struct _jdesktopui t_jdesktopui; ///< An instance of a transparent UI window on the desktop @ingroup jgraphics 38 typedef struct _jpopupmenu t_jpopupmenu; ///< An instance of a pop-up menu. @ingroup jgraphics 39 typedef struct _jsvg t_jsvg; ///< An instance of an SVG object. @ingroup jgraphics 40 typedef struct _jsvg_remap t_jsvg_remap; ///< An object used for remapping colors in a t_svg. @ingroup jgraphics 41 typedef struct _dpi_awareness_context t_dpi_awareness_context; 42 #endif 43 44 45 // pre-defined colors -- internal use only -- not exported from the kernel 46 47 extern t_jrgb s_jrgb_white; // White 48 extern t_jrgb s_jrgb_black; // Black 49 extern t_jrgb s_jrgb_red; // Red 50 extern t_jrgb s_jrgb_green; // Green 51 extern t_jrgb s_jrgb_blue; // Blue 52 extern t_jrgb s_jrgb_yellow; // Yellow 53 extern t_jrgb s_jrgb_cyan; // Cyan 54 extern t_jrgb s_jrgb_magenta; // Magenta 55 extern t_jrgb s_jrgb_gray; // Gray 56 extern t_jrgb s_jrgb_boxgray; // Box Gray 57 58 /** Determine the coordinate of the bottom of a rect. 59 @ingroup jgraphics */ 60 #define JGRAPHICS_RECT_BOTTOM(rect) (((rect)->y)+((rect)->height)) 61 62 /** Determine the coordinate of the right side of a rect. 63 @ingroup jgraphics */ 64 #define JGRAPHICS_RECT_RIGHT(rect) (((rect)->x)+((rect)->width)) 65 66 67 // misc utilities 68 69 /** Utility macro to return the value of Pi. @ingroup jgraphics */ 70 #define JGRAPHICS_PI (3.1415926535897932384626433832795028842) 71 72 /** Utility macro to return the value of twice Pi. @ingroup jgraphics */ 73 #define JGRAPHICS_2PI (2. * 3.1415926535897932384626433832795028842) 74 75 /** Utility macro to return the value of half of Pi. @ingroup jgraphics */ 76 #define JGRAPHICS_PIOVER2 (0.5 * 3.1415926535897932384626433832795028842) 77 78 /** Utility macro to return the 270ยบ Case. @ingroup jgraphics */ 79 #define JGRAPHICS_3PIOVER2 ((3.0 * JGRAPHICS_PI) / 2.0) 80 81 82 typedef enum _jgraphics_line_join { 83 JGRAPHICS_LINE_JOIN_MITER, 84 JGRAPHICS_LINE_JOIN_ROUND, 85 JGRAPHICS_LINE_JOIN_BEVEL 86 } t_jgraphics_line_join; 87 88 typedef enum _jgraphics_line_cap { 89 JGRAPHICS_LINE_CAP_BUTT, 90 JGRAPHICS_LINE_CAP_ROUND, 91 JGRAPHICS_LINE_CAP_SQUARE 92 } t_jgraphics_line_cap; 93 94 typedef enum _jgraphics_bubble_side { 95 JGRAPHICS_BUBBLE_SIDE_TOP, 96 JGRAPHICS_BUBBLE_SIDE_LEFT, 97 JGRAPHICS_BUBBLE_SIDE_BOTTOM, 98 JGRAPHICS_BUBBLE_SIDE_RIGHT 99 } t_jgraphics_bubble_side; 100 101 typedef enum _jgraphics_path_elemtype { 102 JGRAPHICS_PATH_STARTNEWSUBPATH, 103 JGRAPHICS_PATH_LINETO, 104 JGRAPHICS_PATH_QUADRATICTO, 105 JGRAPHICS_PATH_CUBICTO, 106 JGRAPHICS_PATH_CLOSEPATH 107 } t_jgraphics_path_type; 108 109 110 /** Utility for rounding a double to an int. 111 @ingroup jgraphics 112 @param d floating-point input. 113 @return rounded int output. */ 114 int jgraphics_round(double d); 115 116 // surfaces 117 118 /** Enumeration of color formats used by jgraphics surfaces. 119 @ingroup jgraphics */ 120 typedef enum _jgraphics_format { 121 JGRAPHICS_FORMAT_ARGB32, ///< Color is represented using 32 bits, 8 bits each for the components, and including an alpha component. 122 JGRAPHICS_FORMAT_RGB24, ///< Color is represented using 32 bits, 8 bits each for the components. There is no alpha component. 123 JGRAPHICS_FORMAT_A8 ///< The color is represented only as an 8-bit alpha mask. 124 // JGRAPHICS_FORMAT_A1 // not supported 125 } t_jgraphics_format; 126 127 128 /** Enumeration of file formats usable for jgraphics surfaces. 129 @ingroup jgraphics */ 130 typedef enum _jgraphics_fileformat { 131 JGRAPHICS_FILEFORMAT_PNG, ///< Portable Network Graphics (PNG) format 132 JGRAPHICS_FILEFORMAT_JPEG ///< JPEG format 133 } t_jgraphics_fileformat; 134 135 136 /** Create an image surface. 137 Use jgraphics_surface_destroy() to free it when you are done. 138 @ingroup jsurface 139 @param format Defines the color format for the new surface. 140 @param width Defines the width of the new surface. 141 @param height Defines the height of the new surface. 142 @return A pointer to the new surface. */ 143 t_jsurface* jgraphics_image_surface_create(t_jgraphics_format format, int width, int height); 144 145 146 /** Create an image surface, filling it with the contents of a file, and get a reference to the surface. 147 Use jgraphics_surface_destroy() to release your reference to the surface when you are done. 148 @ingroup jsurface 149 @param filename The name of the file. 150 @param path The path id of the file. 151 @return A pointer to the new surface. */ 152 t_jsurface *jgraphics_image_surface_create_referenced(const char *filename, short path); 153 154 155 /** Create an image surface, filling it with the contents of a file. 156 Use jgraphics_surface_destroy() to free it when you are done. 157 @ingroup jsurface 158 @param filename The name of the file. 159 @param path The path id of the file. 160 @return A pointer to the new surface. */ 161 t_jsurface* jgraphics_image_surface_create_from_file(const char *filename, short path); 162 163 164 /** Create an image surface from given pixel data. 165 Data should point to start of top line of bitmap, stride tells how to get to next line. 166 For upside down windows bitmaps, data = (pBits-(height-1)*stride) and stride is a negative number. 167 @ingroup jsurface 168 @param data The data. For example, an RGBA image loaded in memory. 169 @param format The format of the data. 170 @param width The width of the new surface. 171 @param height The height of the new surface. 172 @param stride The number of bytes between the start of rows in the dat buffer. 173 @param freefun If not NULL, freefun will be called when the surface is destroyed 174 @param freearg This will be passed to freefun if/when freefun is called. 175 @return A pointer to the new surface. */ 176 t_jsurface* jgraphics_image_surface_create_for_data(unsigned char *data, t_jgraphics_format format, 177 int width, int height, int stride, 178 method freefun, void *freearg); 179 180 // Internal Use Only 181 t_jsurface* jgraphics_image_surface_create_for_data_premult(unsigned char *data, t_jgraphics_format format, 182 int width, int height, int stride, 183 method freefun, void *freearg); 184 185 /** Create a new surface from file data. 186 @ingroup jsurface 187 @param data A pointer to the raw PNG or JPG bits. 188 @param datalen The number of bytes in data. 189 @return The new surface. 190 @see jgraphics_write_image_surface_to_filedata() */ 191 t_jsurface* jgraphics_image_surface_create_from_filedata(const void *data, unsigned long datalen); 192 193 194 /** Create a new surface from a resource in your external. 195 @ingroup jsurface 196 @param moduleRef A pointer to your external's module, 197 which is passed to your external's main() function when the class is loaded. 198 @param resname The name of the resource in the external. 199 @remark The following example shows an example of how this might be used in an external. 200 @code 201 static s_my_surface = NULL; 202 203 int main(void *moduleRef) 204 { 205 // (Do typical class initialization here) 206 207 // now create the surface from a resource that we added to the Xcode/VisualStudio project 208 s_my_surface = jgraphics_image_surface_create_from_resource(moduleRef, "myCoolImage"); 209 210 return 0; 211 } 212 @endcode */ 213 t_jsurface* jgraphics_image_surface_create_from_resource(const void* moduleRef, const char *resname); 214 215 /** Low-level routine to access an object's resource data. 216 @ingroup jsurface 217 @param moduleRef A pointer to your external's module, which is passed to your external's main() function when the class is loaded. 218 @param resname Base name of the resource data (without an extension) 219 @param extcount Count of possible extensions (ignored on Windows) 220 @param exts Array of symbol atoms containing possible filename extensions (ignored on Windows) 221 @param data Returned resource data assigned to a pointer you supply 222 @param datasize Size of the data returned 223 @remark You are responsible for freeing any data returned in the data pointer 224 @return A Max error code. */ 225 t_max_err jgraphics_get_resource_data(const void *moduleRef, const char *resname, long extcount, t_atom *exts, void **data, unsigned long *datasize); 226 227 /** Create a reference to an existing surface. 228 Use jgraphics_surface_destroy() to release your reference to the surface when you are done. 229 @ingroup jsurface 230 @param s The surface to reference. 231 @return The new reference to the surface. */ 232 t_jsurface* jgraphics_surface_reference(t_jsurface *s); 233 234 235 /** Release or free a surface. 236 @ingroup jsurface 237 @param s The surface to release. */ 238 void jgraphics_surface_destroy(t_jsurface *s); 239 240 241 /** Export a PNG file of the contents of a surface. 242 @ingroup jsurface 243 @param surface The surface to export. 244 @param filename Specify the name of the file to create. 245 @param path Specify the path id for where to create the file. 246 @param dpi Define the resolution of the image (e.g. 72). 247 @return A Max error code. */ 248 t_max_err jgraphics_image_surface_writepng(t_jsurface *surface, const char *filename, short path, long dpi); 249 250 /** Export a JPEG file of the contents of a surface. 251 @ingroup jsurface 252 @param surface The surface to export. 253 @param filename Specify the name of the file to create. 254 @param path Specify the path id for where to create the file. 255 @return A Max error code. */ 256 t_max_err jgraphics_image_surface_writejpeg(t_jsurface *surface, const char *filename, short path); 257 258 259 // Not used by any C74 code... 260 void jgraphics_surface_set_device_offset(t_jsurface *s, double x_offset, double y_offset); 261 void jgraphics_surface_get_device_offset(t_jsurface *s, double *x_offset, double *y_offset); 262 263 264 /** Retrieve the width of a surface. 265 @ingroup jsurface 266 @param s The surface to query. 267 @return The width of the surface. */ 268 int jgraphics_image_surface_get_width(t_jsurface *s); 269 270 /** Retrieve the height of a surface. 271 @ingroup jsurface 272 @param s The surface to query. 273 @return The height of the surface. */ 274 int jgraphics_image_surface_get_height(t_jsurface *s); 275 276 /** Set the color of an individual pixel in a surface. 277 @ingroup jsurface 278 @param s The surface. 279 @param x The horizontal coordinate of the pixel. 280 @param y The vertical coordinate of the pixel. 281 @param color The color of the pixel. */ 282 void jgraphics_image_surface_set_pixel(t_jsurface *s, int x, int y, t_jrgba color); 283 284 /** Retrieve the color of an individual pixel in a surface. 285 @ingroup jsurface 286 @param s The surface. 287 @param x The horizontal coordinate of the pixel. 288 @param y The vertical coordinate of the pixel. 289 @param color The address of a valid #t_jrgba struct 290 whose values will be filled in with the color of the pixel upon return. */ 291 void jgraphics_image_surface_get_pixel(t_jsurface *s, int x, int y, t_jrgba *color); 292 293 /** 294 @ingroup jsurface 295 @param s The surface to scroll. 296 @param x The origin of the rect to scroll. 297 @param y The origin of the rect to scroll. 298 @param width The width of the rect to scroll. 299 @param height The height of the rect to scroll. 300 @param dx The amount to scroll the surface horizontally. 301 @param dy The amount to scroll the surface vertically. 302 @param path Can pass NULL if you are not interested in this info. 303 Otherwise pass a pointer and it will be returned with a path containing the invalid region. 304 */ 305 void jgraphics_image_surface_scroll(t_jsurface *s, 306 int x, int y, int width, int height, 307 int dx, int dy, 308 t_jpath **path); // 309 310 311 // The lockpixels methods are for C74 internal use only. Use jgraphics_image_surface_create_for_data(). 312 313 /* Get a read-only raw bitmap of a surface. 314 This gives you a pointer to the raw bitmap data so you can read from it yourself and examine the stuff that was drawn. 315 The jgraphics_image_surface_lockpixels() version gives you a pointer to the bits that you can directly munge. 316 After either call you should make the appropriate unlock call. 317 @ingroup jsurface 318 @param s The surface. 319 @param x The rect horizontal-origin for the raw bitmap. 320 @param y The rect vertical-origin for the raw bitmap. 321 @param width The rect width for the bitmap. 322 @param height The rect height for the bitmap. 323 @param linestride The line stride for the bitmap. 324 @param pixelstride The pixel stride for the bitmap. 325 @return A pointer to the raw bitmap. */ 326 const unsigned char* jgraphics_image_surface_lockpixels_readonly(t_jsurface *s, 327 int x, int y, int width, int height, 328 int *linestride, int *pixelstride); 329 /* Unlock a surface locked by jgraphics_image_surface_lockpixels_readonly(). 330 @ingroup jsurface 331 @param s The surface. 332 @param data The pointer returned by jgraphics_image_surface_lockpixels_readonly(). */ 333 void jgraphics_image_surface_unlockpixels_readonly(t_jsurface *s, const unsigned char *data); 334 335 336 /* Get a writable bitmap of a surface. 337 After you are done reading/writing to the bitmap, you should call jgraphics_image_surface_unlockpixels(). 338 @ingroup jsurface 339 @param s The surface. 340 @param x The rect horizontal-origin for the raw bitmap. 341 @param y The rect vertical-origin for the raw bitmap. 342 @param width The rect width for the bitmap. 343 @param height The rect height for the bitmap. 344 @param linestride The line stride for the bitmap. 345 @param pixelstride The pixel stride for the bitmap. 346 @return A pointer to the raw bitmap. */ 347 unsigned char* jgraphics_image_surface_lockpixels(t_jsurface *s, 348 int x, int y, int width, int height, 349 int *linestride, int *pixelstride); 350 351 /* Unlock a surface locked by jgraphics_image_surface_lockpixels(). 352 @ingroup jsurface 353 @param s The surface. 354 @param data The pointer returned by jgraphics_image_surface_lockpixels(). */ 355 void jgraphics_image_surface_unlockpixels(t_jsurface *s, unsigned char *data); 356 357 358 /** Draw an image surface. 359 This not in cairo, but, it seems silly to have to make a brush to just draw an image. 360 This doesn't support rotations, however. 361 @ingroup jsurface 362 @param g The graphics context in which to draw the surface. 363 @param s The surface to draw. 364 @param srcRect The rect within the surface that should be drawn. 365 @param destRect The rect in the context to which to draw the srcRect. 366 @see jgraphics_image_surface_draw_fast() */ 367 void jgraphics_image_surface_draw(t_jgraphics *g, t_jsurface *s, t_rect srcRect, t_rect destRect); 368 369 370 /** Draw an image surface quickly. 371 The draw_fast version won't scale based on zoom factor or user transforms so make sure that this is what you want! 372 Draws entire image, origin *can* be shifted via zoom and user transforms 373 (even though image is not scaled based on those same transforms) 374 @ingroup jsurface 375 @param g The graphics context in which to draw the surface. 376 @param s The surface to draw. 377 @see jgraphics_image_surface_draw */ 378 void jgraphics_image_surface_draw_fast(t_jgraphics *g, t_jsurface *s); 379 380 381 /** Get surface data ready for manually writing to a file. 382 @ingroup jsurface 383 @param surf The surface whose data will be retrieved. 384 @param fmt The format for the data. This should be a selection from #t_jgraphics_fileformat. 385 @param data The address of a pointer that will be allocated and filled. 386 When you are done with this data you should free it using sysmem_freeptr(). 387 @param size The address of a variable to hold the size of the data upon return. 388 389 @remark A good example of this is to embed the surface as a PNG in a patcher file. 390 @code 391 long size = 0; 392 void *data = NULL; 393 394 jgraphics_write_image_surface_to_filedata(x->j_surface, JGRAPHICS_FILEFORMAT_PNG, &data, &size); 395 if (size) { 396 x->j_format = gensym("png"); 397 binarydata_appendtodictionary(data, size, gensym("data"), x->j_format, d); 398 x->j_imagedata = data; 399 x->j_imagedatasize = size; 400 } 401 @endcode 402 @see jgraphics_image_surface_create_from_filedata() */ 403 void jgraphics_write_image_surface_to_filedata(t_jsurface *surf, long fmt, void **data, long *size); 404 405 t_jsurface* jgraphics_image_surface_create_from_base64(const char *base64, unsigned long datalen); 406 void jgraphics_write_image_surface_to_base64(t_jsurface *surf, long fmt, char **base64, long *size); 407 408 409 /** Set all pixels in rect to 0. 410 @ingroup jsurface 411 @param s The surface to clear. 412 @param x The horizontal origin of the rect to clear. 413 @param y The vertical origin of the rect to clear. 414 @param width The width of the rect to clear. 415 @param height The height of the rect to clear. */ 416 void jgraphics_image_surface_clear(t_jsurface *s, int x, int y, int width, int height); 417 418 419 420 // SVG Stuff 421 422 /** Read an SVG file, return a #t_jsvg object. 423 @ingroup jsvg 424 @param filename The name of the file to read. 425 @param path The path id of the file to read. 426 @return A new SVG object. */ 427 t_jsvg* jsvg_create_from_file(const char *filename, short path); 428 429 430 /** Read an SVG file from a resource. 431 @ingroup jsvg 432 @param moduleRef The external's moduleRef. 433 @param resname The name of the SVG resource. 434 @return A new SVG object. 435 @see jgraphics_image_surface_create_from_resource() */ 436 t_jsvg* jsvg_create_from_resource(const void *moduleRef, const char *resname); 437 438 439 /** Create an SVG object from a string containing the SVG's XML. 440 @ingroup jsvg 441 @param svgXML The SVG source. 442 @return A new SVG object. */ 443 t_jsvg* jsvg_create_from_xmlstring(const char *svgXML); 444 445 446 /** Retrieve the size of an SVG object. 447 @ingroup jsvg 448 @param svg An SVG object. 449 @param width The address of a variable that will be set to the width upon return. 450 @param height The address of a variable that will be set to the width upon return. */ 451 void jsvg_get_size(t_jsvg *svg, double *width, double *height); 452 453 454 /** Free a #t_jsvg object. 455 @ingroup jsvg 456 @param svg The object to free. */ 457 void jsvg_destroy(t_jsvg *svg); 458 459 460 /** Render an SVG into a graphics context. 461 @ingroup jsvg 462 @param svg The SVG object to render. 463 @param g The graphics context in which to render. */ 464 void jsvg_render(t_jsvg *svg, t_jgraphics *g); 465 466 void jsvg_load_cached(t_symbol *name, t_jsvg **psvg); 467 t_jsvg_remap *jsvg_remap_create(t_jsvg *svg); 468 void jsvg_remap_addcolor(t_jsvg_remap *r, t_jrgba *src, t_jrgba *dst); 469 void jsvg_remap_perform(t_jsvg_remap *r, t_jsvg **remapped); 470 void jsvg_remap_destroy(t_jsvg_remap *r); 471 void jsvg_remap_addsinglecolor(t_jsvg_remap *r, t_jrgba *dst); 472 473 // this enum is anonymous because jgraphics_draw_jsvg takes an int flags argument 474 475 enum { 476 JGRAPHICS_JSVG_IMAGE_EFFECT = 1, ///< Not working quite yet 477 JGRAPHICS_JSVG_USE_CONTENT_AREA = 2 ///< Use the content area (viewBox) instead of the default JUCE SVG bounds 478 479 // more flags possible for centering etc. 480 }; 481 482 void jgraphics_draw_jsvg(t_jgraphics *g, t_jsvg *svg, t_rect *r, int flags, double opacity); 483 484 485 /** Create a context to draw on a particular surface. 486 When you are done, call jgraphics_destroy(). 487 @ingroup jsurface 488 @param target The surface to which to draw. 489 @return The new graphics context. */ 490 t_jgraphics* jgraphics_create(t_jsurface *target); 491 492 493 /** Get a reference to a graphics context. 494 When you are done you should release your reference with jgraphics_destroy(). 495 @ingroup jgraphics 496 @param g The context you wish to reference. 497 @return A new reference to the context. */ 498 t_jgraphics* jgraphics_reference(t_jgraphics *g); 499 500 501 /** Release or free a graphics context. 502 @ingroup jgraphics 503 @param g The context to release. */ 504 void jgraphics_destroy(t_jgraphics *g); 505 506 507 508 // Paths 509 510 typedef struct _jgraphics_path_elem { 511 float x1; 512 float y1; 513 float x2; 514 float y2; 515 float x3; 516 float y3; 517 t_jgraphics_path_type type; 518 } t_jgraphics_path_elem; 519 520 /** Begin a new path. 521 This action clears any current path in the context. 522 @ingroup jgraphics 523 @param g The graphics context. */ 524 void jgraphics_new_path(t_jgraphics *g); 525 526 527 /** Get a copy of the current path from a context. 528 @ingroup jgraphics 529 @param g the graphics context containing the current path 530 @return A copy of the current path. 531 */ 532 t_jpath* jgraphics_copy_path(t_jgraphics *g); 533 534 /** Create a new path consisting of the original path stroked with a given thickness 535 @ingroup jgraphics 536 @param p the path to be stroked 537 @param thickness thickness of the stroke 538 @param join the style to join segments together at corners 539 @param cap the style of end cap to use 540 @return the new path, which must be freed with jgraphics_path_destroy() when done 541 */ 542 t_jpath* jgraphics_path_createstroked(t_jpath *p, double thickness, t_jgraphics_line_join join, t_jgraphics_line_cap cap); 543 544 /** Release/free a path. 545 @ingroup jgraphics 546 @param path The path to release. */ 547 void jgraphics_path_destroy(t_jpath *path); 548 549 550 /** Add a path to a graphics context. 551 @ingroup jgraphics 552 @param g The graphics context. 553 @param path The path to add. */ 554 void jgraphics_append_path(t_jgraphics *g, t_jpath *path); 555 556 557 /** Close the current path in a context. 558 This will add a line segment to close current subpath. 559 @ingroup jgraphics 560 @param g The graphics context. */ 561 void jgraphics_close_path(t_jgraphics *g); 562 563 564 /** Round out any corners in a path. 565 This action clears any current path in the context. 566 @ingroup jgraphics 567 @param g The graphics context. 568 @param cornerRadius The amount by which to round corners. */ 569 void jgraphics_path_roundcorners(t_jgraphics *g, double cornerRadius); 570 571 /** Test if the path contains the point x,y. 572 @ingroup jgraphics 573 @param path the path 574 @param x the x-coordinate of the point to test 575 @param y the y-coordinate of the point to test */ 576 long jgraphics_path_contains(t_jpath *path, double x, double y); 577 578 /** Test if the path intersects the line defined by x1,y1 and x2,y2. 579 @ingroup jgraphics 580 @param path the path 581 @param x1 the x-coordinate of the first point on the line 582 @param y1 the y-coordinate of the first point on the line 583 @param x2 the x-coordinate of the second point on the line 584 @param y2 the y-coordinate of the second point on the line 585 */ 586 long jgraphics_path_intersectsline(t_jpath *path, double x1, double y1, double x2, double y2); 587 588 /** Return the length of a path 589 @ingroup jgraphics 590 @param path the path 591 @return the length of the path 592 */ 593 double jgraphics_path_getlength(t_jpath *path); 594 595 /** Return a point that lies a given distance from the start of the path 596 @ingroup jgraphics 597 @param path the path 598 @param distancefromstart distance from the start point 599 @param x pointer to double to receive the x position of the point 600 @param y pointer to double to receive the y position of the point 601 */ 602 void jgraphics_path_getpointalongpath(t_jpath *path, double distancefromstart, double *x, double *y); 603 604 /** Finds the point on the path that is nearest to the point x,y passed in 605 @ingroup jgraphics 606 @param path the path to search 607 @param x x position of the target point 608 @param y y position of the target point 609 @param path_x pointer to double to receive the x position of closest point on path 610 @param path_y pointer to double to receive the y position of the closest point on path 611 @return returns the distance along the path from the path start position to the found point on the path 612 */ 613 double jgraphics_path_getnearestpoint(t_jpath *path, double x, double y, double *path_x, double *path_y); 614 615 /** Get the path elements and return number of path elements 616 @ingroup jgraphics 617 @param path the path 618 @param elems pointer to array of path elements 619 @return the number of path elements 620 */ 621 long jgraphics_path_getpathelems(t_jpath *path, t_jgraphics_path_elem **elems); 622 623 /** Get the current location of the cursor in a graphics context. 624 @ingroup jgraphics 625 @param g The graphics context. 626 @param x The address of a variable that will be set to the horizontal cursor location upon return. 627 @param y The address of a variable that will be set to the vertical cursor location upon return. */ 628 void jgraphics_get_current_point(t_jgraphics *g, double *x, double *y); 629 630 631 /** Add a circular, clockwise, arc to the current path. 632 @ingroup jgraphics 633 @param g The graphics context. 634 @param xc The horizontal coordinate of the arc's center. 635 @param yc The vertical coordinate of the arc's center. 636 @param radius The radius of the arc. 637 @param angle1 The starting angle of the arc in radians. 638 Zero radians is center right (positive x axis). 639 @param angle2 The terminal angle of the arc in radians. 640 Zero radians is center right (positive x axis). */ 641 void jgraphics_arc(t_jgraphics *g, 642 double xc, double yc, 643 double radius, 644 double angle1, double angle2); 645 646 // used by the dial object 647 void jgraphics_piesegment(t_jgraphics *g, 648 double xc, double yc, 649 double radius, 650 double angle1, double angle2, 651 double innercircleproportionalsize); 652 653 /** Add a non-circular arc to the current path. 654 @ingroup jgraphics 655 @param g The graphics context. 656 @param xc The horizontal coordinate of the arc's center. 657 @param yc The vertical coordinate of the arc's center. 658 @param radiusx The horizontal radius of the arc. 659 @param radiusy The vertical radius of the arc. 660 @param angle1 The starting angle of the arc in radians. 661 Zero radians is center right (positive x axis). 662 @param angle2 The terminal angle of the arc in radians. 663 Zero radians is center right (positive x axis). */ 664 void jgraphics_ovalarc(t_jgraphics *g, 665 double xc, double yc, 666 double radiusx, double radiusy, 667 double angle1, double angle2); 668 669 670 /** Add a circular, counter-clockwise, arc to the current path. 671 @ingroup jgraphics 672 @param g The graphics context. 673 @param xc The horizontal coordinate of the arc's center. 674 @param yc The vertical coordinate of the arc's center. 675 @param radius The radius of the arc. 676 @param angle1 The starting angle of the arc in radians. 677 Zero radians is center right (positive x axis). 678 @param angle2 The terminal angle of the arc in radians. 679 Zero radians is center right (positive x axis). */ 680 void jgraphics_arc_negative(t_jgraphics *g, 681 double xc, double yc, 682 double radius, 683 double angle1, double angle2); 684 685 686 /** Add a cubic Bezier spline to the current path. 687 @ingroup jgraphics 688 @param g The graphics context. 689 @param x1 The first control point. 690 @param y1 The first control point. 691 @param x2 The second control point. 692 @param y2 The second control point. 693 @param x3 The destination point. 694 @param y3 The destination point. */ 695 void jgraphics_curve_to(t_jgraphics *g, 696 double x1, double y1, 697 double x2, double y2, 698 double x3, double y3); 699 700 701 /** Add a cubic Bezier spline to the current path, using coordinates relative to the current point. 702 @ingroup jgraphics 703 @param g The graphics context. 704 @param x1 The first control point. 705 @param y1 The first control point. 706 @param x2 The second control point. 707 @param y2 The second control point. 708 @param x3 The destination point. 709 @param y3 The destination point. */ 710 void jgraphics_rel_curve_to(t_jgraphics *g, 711 double x1, double y1, 712 double x2, double y2, 713 double x3, double y3); 714 715 716 /** Add a line segment to the current path. 717 @ingroup jgraphics 718 @param g The graphics context. 719 @param x The destination point. 720 @param y The destination point. */ 721 void jgraphics_line_to(t_jgraphics *g, double x, double y); 722 723 724 /** Add a line segment to the current path, using coordinates relative to the current point. 725 @ingroup jgraphics 726 @param g The graphics context. 727 @param x The destination point. 728 @param y The destination point. */ 729 void jgraphics_rel_line_to(t_jgraphics *g, double x, double y); 730 731 732 /** Move the cursor to a new point and begin a new subpath. 733 @ingroup jgraphics 734 @param g The graphics context. 735 @param x The new location. 736 @param y The new location. */ 737 void jgraphics_move_to(t_jgraphics *g, double x, double y); 738 739 740 /** Move the cursor to a new point and begin a new subpath, using coordinates relative to the current point. 741 @ingroup jgraphics 742 @param g The graphics context. 743 @param x The new location. 744 @param y The new location. */ 745 void jgraphics_rel_move_to(t_jgraphics *g, double x, double y); 746 747 748 /** Add a closed rectangle path in the context. 749 @ingroup jgraphics 750 @param g The graphics context. 751 @param x The horizontal origin. 752 @param y The vertical origin. 753 @param width The width of the rect. 754 @param height The height of the rect. */ 755 void jgraphics_rectangle(t_jgraphics *g, 756 double x, double y, 757 double width, double height); 758 759 760 /** Deprecated -- do not use. Adds a closed oval path in the context, however, it does not scale appropriately. 761 @ingroup jgraphics 762 @param g The graphics context. 763 @param x The horizontal origin. 764 @param y The vertical origin. 765 @param width The width of the oval. 766 @param height The height of the oval. */ 767 void jgraphics_oval(t_jgraphics *g, 768 double x, double y, 769 double width, double height); 770 771 772 /** Add a closed rounded-rectangle path in the context. 773 @ingroup jgraphics 774 @param g The graphics context. 775 @param x The horizontal origin. 776 @param y The vertical origin. 777 @param width The width of the rect. 778 @param height The height of the rect. 779 @param ovalwidth The width of the oval used for the round corners. 780 @param ovalheight The height of the oval used for the round corners. */ 781 void jgraphics_rectangle_rounded(t_jgraphics *g, 782 double x, double y, 783 double width, double height, 784 double ovalwidth, double ovalheight); 785 786 787 /** Add a closed elliptical path in the context. 788 @ingroup jgraphics 789 @param g The graphics context. 790 @param x The horizontal origin. 791 @param y The vertical origin. 792 @param width The width of the rect. 793 @param height The height of the rect. */ 794 void jgraphics_ellipse(t_jgraphics *g, 795 double x, double y, 796 double width, double height); 797 798 /** Add a closed bubble path in the context. 799 @ingroup jgraphics 800 @param g The graphics context. 801 @param bodyx Horizontal body origin. 802 @param bodyy The vertical origin. 803 @param bodywidth The width of the rect. 804 @param bodyheight The height of the rect. 805 @param cornersize Body rounded corners 806 @param arrowtipx X position of arrow tip 807 @param arrowtipy Y position of arrow tip 808 @param whichside side to connect arrow, see above definition of t_jgraphics_bubble_side enum, 809 @param arrowedgeprop Arrow proportion along edge (0-1) 810 @param arrowwidth Arrow base width 811 */ 812 void jgraphics_bubble(t_jgraphics *g, 813 double bodyx, double bodyy, 814 double bodywidth, double bodyheight, 815 double cornersize, double arrowtipx, double arrowtipy, 816 t_jgraphics_bubble_side whichside, double arrowedgeprop, double arrowwidth); 817 818 819 /** Add a closed triangular path in the context. 820 @ingroup jgraphics 821 @param g The graphics context. 822 @param x1 Coordinate for the first point. 823 @param y1 Coordinate for the first point. 824 @param x2 Coordinate for the second point. 825 @param y2 Coordinate for the second point. 826 @param x3 Coordinate for the third point. 827 @param y3 Coordinate for the third point. 828 */ 829 void jgraphics_triangle(t_jgraphics *g, double x1, double y1, double x2, double y2, double x3, double y3); 830 831 832 // Internal use only 833 void jgraphics_diagonal_line_fill(t_jgraphics *g, double pixels, double x, double y, double width, double height); 834 835 836 /** Enumeration of slanting options for font display. 837 @ingroup jfont */ 838 typedef enum _jgraphics_font_slant { 839 JGRAPHICS_FONT_SLANT_NORMAL, ///< Normal slanting (typically this means no slanting) 840 JGRAPHICS_FONT_SLANT_ITALIC ///< Italic slanting 841 // JGRAPHICS_FONT_SLANT_OBLIQUE 842 } t_jgraphics_font_slant; 843 844 845 /** Enumeration of font weight options for font display. 846 @ingroup jfont */ 847 typedef enum _jgraphics_font_weight { 848 JGRAPHICS_FONT_WEIGHT_NORMAL, ///< Normal font weight 849 JGRAPHICS_FONT_WEIGHT_BOLD ///< Bold font weight 850 } t_jgraphics_font_weight; 851 852 853 /** Specify a font for a graphics context. 854 @ingroup jgraphics 855 @param g The graphics context. 856 @param family The name of the font family (e.g. "Arial"). 857 @param slant Define the slant to use for the font. 858 @param weight Define the weight to use for the font. */ 859 void jgraphics_select_font_face(t_jgraphics *g, 860 const char *family, 861 t_jgraphics_font_slant slant, 862 t_jgraphics_font_weight weight); 863 864 865 /** Specify a font for a graphics context by passing a #t_jfont object. 866 @ingroup jgraphics 867 @param g The graphics context. 868 @param jfont A jfont object whose attributes will be copied to the context. */ 869 void jgraphics_select_jfont(t_jgraphics *g, t_jfont *jfont); 870 871 872 /** Specify the font size for a context. 873 @ingroup jgraphics 874 @param g The graphics context. 875 @param size The font size. */ 876 void jgraphics_set_font_size(t_jgraphics *g, double size); 877 878 879 /** Turn underlining on/off for text in a context. 880 @ingroup jgraphics 881 @param g The graphics context. 882 @param underline Pass true or false to set the appropriate behavior. */ 883 void jgraphics_set_underline(t_jgraphics *g, char underline); 884 885 886 /** Display text at the current position in a context. 887 @ingroup jgraphics 888 @param g The graphics context. 889 @param utf8 The text to display. */ 890 void jgraphics_show_text(t_jgraphics *g, const char *utf8); 891 892 /** Add a path of text to the current path. 893 @ingroup jgraphics 894 @param g The graphics context. 895 @param utf8 The text to generate path for. */ 896 void jgraphics_text_path(t_jgraphics *g, const char *utf8); 897 898 899 /** A structure for holding information related to how much space the rendering of a given font will use. 900 The units for these measurements is in pixels. 901 @ingroup jgraphics 902 */ 903 typedef struct _jgraphics_font_extents { 904 double ascent; ///< The ascent. 905 double descent; ///< The descent. 906 double height; ///< The hieght. 907 double max_x_advance; ///< Unused / Not valid. 908 double max_y_advance; ///< Unused / Not valid. 909 } t_jgraphics_font_extents; 910 911 912 /** Return the extents of the currently selected font for a given graphics context. 913 @ingroup jgraphics 914 @param g Pointer to a jgraphics context. 915 @param extents The address of a #t_jgraphics_font_extents structure to be filled with the results. 916 */ 917 void jgraphics_font_extents(t_jgraphics *g, t_jgraphics_font_extents *extents); 918 919 920 /** Return the height and width of a string given current graphics settings in a context. 921 @ingroup jgraphics 922 @param g Pointer to a jgraphics context. 923 @param utf8 A string containing the text whose dimensions we wish to find. 924 @param width The address of a variable to be filled with the width of the rendered text. 925 @param height The address of a variable to be filled with the height of the rendered text. 926 */ 927 void jgraphics_text_measure(t_jgraphics *g, const char *utf8, double *width, double *height); 928 929 930 /** Return the height, width, and number of lines that will be used to render a given string. 931 @ingroup jgraphics 932 @param g Pointer to a jgraphics context. 933 @param utf8 A string containing the text whose dimensions we wish to find. 934 @param wrapwidth The number of pixels in width at which the text should be wrapped if it is too long. 935 @param includewhitespace Set zero to not include white space in the calculation, otherwise set this parameter to 1. 936 @param width The address of a variable to be filled with the width of the rendered text. 937 @param height The address of a variable to be filled with the height of the rendered text. 938 @param numlines The address of a variable to be filled with the number of lines required to render the text. 939 */ 940 void jgraphics_text_measuretext_wrapped(t_jgraphics *g, const char *utf8, double wrapwidth, long includewhitespace, 941 double *width, double *height, long *numlines); 942 943 944 // Internal Use Only 945 double jgraphics_getfontscale(void); 946 947 948 949 // Working with fonts directly 950 951 // Internal Use Only 952 t_jfont* jfont_create_from_maxfont(short number, short size); 953 954 955 /** Create a new font object. 956 @ingroup jfont 957 @param family The name of the font family (e.g. Arial). 958 @param slant The type of slant for the font. 959 @param weight The type of weight for the font. 960 @param size The size of the font. 961 @return The new font object. Needs to be freed via jfont_destroy() when done. 962 */ 963 t_jfont* jfont_create(const char *family, 964 t_jgraphics_font_slant slant, 965 t_jgraphics_font_weight weight, 966 double size); 967 968 /** Create a new font object using a style instead of style flags. 969 @ingroup jfont 970 @param family The name of the font family (e.g. Arial). 971 @param stylename The name of the font style (e.g. Narrow Bold Italic). 972 @param size The size of the font. 973 @return The new font object. Needs to be freed via jfont_destroy() when done. 974 */ 975 t_jfont* jfont_create_withstylename(const char *family, 976 const char *stylename, 977 double size); 978 979 980 /** Create new reference to an existing font object. 981 @ingroup jfont 982 @param font The font object for which to obtain a reference. 983 @return The new font object reference. */ 984 t_jfont* jfont_reference(t_jfont *font); 985 986 987 /** Release or free a font object. 988 @ingroup jfont 989 @param font The font object to release. */ 990 void jfont_destroy(t_jfont *font); 991 992 993 /** Compare two fonts to see if they are equivalent. 994 @ingroup jfont 995 @param font The first font object that is being compared. 996 @param other The second font object that is being compared. 997 @return Nonzero value if the two fonts are equivalent. */ 998 long jfont_isequalto(t_jfont *font, t_jfont *other); 999 1000 /** Set the name of the font family (e.g. Arial). 1001 @ingroup jfont 1002 @param font The font object. 1003 @param family A t_symbol containing the name of the desired font family. */ 1004 void jfont_set_family(t_jfont *font, t_symbol *family); 1005 1006 /** Get the name of the font family (e.g. Arial). 1007 @ingroup jfont 1008 @param font The font object. 1009 @return A t_symbol representing the name of the font family. */ 1010 t_symbol* jfont_get_family(t_jfont *font); 1011 1012 /** Set the style of a font family (e.g. Narrow Bold Italic). 1013 @ingroup jfont 1014 @param font The font object. 1015 @param style The desired style. 1016 */ 1017 void jfont_set_style(t_jfont *font, t_symbol *style); 1018 1019 /** Get the style of the given font (e.g. Narrow Bold Italic). 1020 @ingroup jfont 1021 @param font The font object. 1022 @return A t_symbol representing the name of the font style. 1023 */ 1024 t_symbol* jfont_get_style(t_jfont *font); 1025 1026 /** Set the slant of the font. 1027 @ingroup jfont 1028 @param font The font object 1029 @param slant The desired slant. */ 1030 void jfont_set_slant(t_jfont *font, t_jgraphics_font_slant slant); 1031 1032 /** Get the slant of the font. 1033 @ingroup jfont 1034 @param font The font object. 1035 @return The current slant setting for the font. */ 1036 t_jgraphics_font_slant jfont_get_slant(t_jfont *font); 1037 1038 /** Set the weight of the font. 1039 @ingroup jfont 1040 @param font The font object 1041 @param weight The desired weight (e.g. bold). */ 1042 void jfont_set_weight(t_jfont *font, t_jgraphics_font_weight weight); 1043 1044 /** Get the weight of the font. 1045 @ingroup jfont 1046 @param font The font object. 1047 @return The current weight setting for the font. */ 1048 t_jgraphics_font_weight jfont_get_weight(t_jfont *font); 1049 1050 /** Set the size of a font object. 1051 @ingroup jfont 1052 @param font The font object. 1053 @param size The new size for the font object. */ 1054 void jfont_set_font_size(t_jfont *font, double size); 1055 1056 /** Get the size of a font object. 1057 @ingroup jfont 1058 @param font The font object. 1059 @return The size of the font. */ 1060 double jfont_get_font_size(t_jfont *font); 1061 1062 /** Set the underlining of a font object. 1063 @ingroup jfont 1064 @param font The font object. 1065 @param ul Pass true to underline, or false for no underlining. */ 1066 void jfont_set_underline(t_jfont *font, char ul); 1067 1068 /** Get the underline state of a font object. 1069 @ingroup jfont 1070 @param font The font object. 1071 @return Nonzero value if the font will be underlined. */ 1072 char jfont_get_underline(t_jfont *font); 1073 1074 double jfont_get_heighttocharheightratio(t_jfont *font); 1075 1076 1077 /** Get extents of this font 1078 @ingroup jfont 1079 @param font The font object. 1080 @param extents The font extents upon return/ */ 1081 void jfont_extents(t_jfont *font, t_jgraphics_font_extents *extents); 1082 1083 1084 /** Given a font, find out how much area is required to render a string of text. 1085 @ingroup jfont 1086 @param font The font object. 1087 @param utf8 The text whose rendering will be measured. 1088 @param width The address of a variable to hold the width upon return. 1089 @param height The address of a variable to hold the height upon return. */ 1090 void jfont_text_measure(t_jfont *font, const char *utf8, double *width, double *height); 1091 1092 1093 /** Given a font, find out how much area is required to render a string of text, 1094 provided a horizontal maximum limit at which the text is wrapped. 1095 @ingroup jfont 1096 @param font The font object. 1097 @param utf8 The text whose rendering will be measured. 1098 @param wrapwidth The maximum width, above which text should wrap onto a new line. 1099 @param includewhitespace If non-zero, include whitespace in the measurement. 1100 @param width The address of a variable to hold the width upon return. 1101 @param height The address of a variable to hold the height upon return. 1102 @param numlines The address of a variable to hold the number of lines of text after wrapping upon return. */ 1103 void jfont_text_measuretext_wrapped(t_jfont *font, const char *utf8, double wrapwidth, long includewhitespace, 1104 double *width, double *height, long *numlines); 1105 1106 /** Given a font, find out the width and height of the 'M' character. 1107 This is equivalent to jfont_text_measure(font, "M", width, height) but is faster. 1108 @ingroup jfont 1109 @param font The font object. 1110 @param width The address of a variable to hold the width upon return. 1111 @param height The address of a variable to hold the height upon return. */ 1112 void jfont_get_em_dimensions(t_jfont *font, double *width, double *height); 1113 1114 /** Get a list of font names. Note, this includes each font style in each font family. 1115 @ingroup jfont 1116 @param count The address of a variable to hold the count of font names in list upon return. 1117 @param list The address of a #t_symbol** initialized to NULL. 1118 Upon return this will be set to an array of count #t_symbol pointers. 1119 This array should be freed using sysmem_freeptr() when you are done with it. 1120 @return A Max error code. */ 1121 t_max_err jfont_getfontlist(long *count, t_symbol ***list); 1122 1123 /** Get a list of font styles available for a given font face. 1124 @ingroup jfont 1125 @param fontanme A symbol with the name of the font whose styles are to be retrieved. 1126 @param count The address of a variable to hold the count of font styles in the list upon return. 1127 @param list The address of a #t_symbol** initialized to NULL. 1128 Upon return this will be set to an array of count #t_symbol pointers. 1129 This array should b freed using sysmem_freptr() when you are done with it. 1130 @return A Max error code. 1131 */ 1132 t_max_err jfont_getfontstylenames(t_symbol *fontname, long *count, t_symbol ***stylenames); 1133 1134 /** Given a font name with style appended separate into the component parts. (e.g. "Arial Narrow Bold Italic" -> "Arial" and "Narrow Bold Italic". 1135 @ingroup jfont 1136 @param fontfacewithstyle The name with style appended (e.g. "Arial Narrow Bold Italic") 1137 @param fontface The address of a #t_symbol*. On return is set to the name of the font (e.g. "Arial") 1138 @param style The address of a #t_symbol*. On return is set to the name of the font style (e.g. "Narrow Bold Italic") 1139 */ 1140 void jfont_normalizefontname(t_symbol *fontfacewithstyle, t_symbol **fontface, t_symbol **style); 1141 1142 long jfont_isfixedwidth(const char *name); 1143 1144 void jfont_ellipsifytext(t_jfont *font, char *text, long maxcharbuflen, double maxwidth); 1145 1146 const char *jfont_get_default_fixedwidth_name(void); 1147 1148 // Internal Use Only -- not exported 1149 void jfont_set_juce_default_fontname(char *s); 1150 void jfont_copy_juce_default_fontname(char *s, long maxlen); 1151 void jfont_copy_juce_platform_fontname(char *s, long maxlen); 1152 void jfont_set_juce_fallback_fontname(char *s); 1153 void jfont_copy_juce_fallback_fontname(char *s, long maxlen); 1154 1155 1156 /** Determine if you can anti-alias text to a transparent background. 1157 You might want to call this and then disable "useimagebuffer" if false *and* 1158 you are rendering text on a transparent background. 1159 @ingroup jgraphics 1160 @return Non-zero if you can anti-alias text to a transparent background. */ 1161 long jgraphics_system_canantialiastexttotransparentbg(); 1162 1163 /** Create a new textlayout object. 1164 @ingroup textlayout 1165 @return The new textlayout object. */ 1166 t_jtextlayout* jtextlayout_create(); 1167 1168 1169 /** Create a new textlayout object. 1170 This gives a hint to the textlayout as to what the text bgcolor will be. 1171 It won't actually paint the bg for you. 1172 But, it does let it do a better job. 1173 @ingroup textlayout 1174 @param g The graphics context for the textlayout. 1175 @param bgcolor The background color for the textlayout. 1176 @return The new textlayout object. */ 1177 t_jtextlayout* jtextlayout_withbgcolor(t_jgraphics *g, t_jrgba *bgcolor); 1178 1179 1180 /** Release/free a textlayout object. 1181 @ingroup textlayout 1182 @param textlayout The textlayout object to release. */ 1183 void jtextlayout_destroy(t_jtextlayout* textlayout); 1184 1185 1186 /** Enumeration of text justification options, which are specified as a bitmask. 1187 @ingroup jgraphics */ 1188 typedef enum _jgraphics_text_justification { 1189 JGRAPHICS_TEXT_JUSTIFICATION_LEFT = 1, ///< Justify left 1190 JGRAPHICS_TEXT_JUSTIFICATION_RIGHT = 2, ///< Justify right 1191 JGRAPHICS_TEXT_JUSTIFICATION_HCENTERED = 4, ///< Centered horizontally 1192 JGRAPHICS_TEXT_JUSTIFICATION_TOP = 8, ///< Justified to the top 1193 JGRAPHICS_TEXT_JUSTIFICATION_BOTTOM = 16, ///< Justified to the bottom 1194 JGRAPHICS_TEXT_JUSTIFICATION_VCENTERED = 32, ///< Centered vertically 1195 JGRAPHICS_TEXT_JUSTIFICATION_HJUSTIFIED = 64, ///< Horizontally justified 1196 JGRAPHICS_TEXT_JUSTIFICATION_CENTERED = JGRAPHICS_TEXT_JUSTIFICATION_HCENTERED + JGRAPHICS_TEXT_JUSTIFICATION_VCENTERED ///< Shortcut for Centering both vertically and horizontally 1197 } t_jgraphics_text_justification; 1198 1199 1200 /** Flags for setting text layout options. 1201 @ingroup textlayout */ 1202 typedef enum _jgraphics_textlayout_flags { 1203 JGRAPHICS_TEXTLAYOUT_NOWRAP = 1, ///< disable word wrapping 1204 JGRAPHICS_TEXTLAYOUT_USEELLIPSIS = 3 ///< show ... if a line doesn't fit (implies NOWRAP too) 1205 } t_jgraphics_textlayout_flags; 1206 1207 1208 /** Set the text and attributes of a textlayout object. 1209 @ingroup textlayout 1210 @param textlayout The textlayout object. 1211 @param utf8 The text to render. 1212 @param jfont The font with which to render the text. 1213 @param x The text is placed within rect specified by x, y, width, height. 1214 @param y The text is placed within rect specified by x, y, width, height. 1215 @param width The text is placed within rect specified by x, y, width, height. 1216 @param height The text is placed within rect specified by x, y, width, height. 1217 @param justification How to justify the text within the rect. 1218 @param flags Additional flags to control behaviour. */ 1219 void jtextlayout_set(t_jtextlayout *textlayout, 1220 const char *utf8, 1221 t_jfont *jfont, 1222 double x, double y, 1223 double width, 1224 double height, 1225 t_jgraphics_text_justification justification, 1226 t_jgraphics_textlayout_flags flags); 1227 1228 /** Set the text of a textlayout object. 1229 @ingroup textlayout 1230 @param textlayout The textlayout object. 1231 @param utf8 The text to render. 1232 @param jfont The font with which to render the text.*/ 1233 void jtextlayout_settext(t_jtextlayout *textlayout, 1234 const char *utf8, 1235 t_jfont *jfont); 1236 1237 /** Set the color to render text in a textlayout object. 1238 @ingroup textlayout 1239 @param textlayout The textlayout object for which to set the color. 1240 @param textcolor The color for the text. */ 1241 void jtextlayout_settextcolor(t_jtextlayout *textlayout, t_jrgba *textcolor); 1242 1243 1244 /** Return a measurement of how much space will be required to draw the text of a textlayout. 1245 @ingroup textlayout 1246 @param textlayout The textlayout object to query. 1247 @param startindex You can measure a subset of the characters. 1248 This defines the character from which to start. 1249 @param numchars Pass -1 for all characters from startindex to end 1250 @param includewhitespace Define whether to measure with or without whitespace truncated from edges. 1251 @param width Returns the width of text not including any margins. 1252 @param height Returns the height of text not including any margins. 1253 @param numlines Returns the number of lines of text. */ 1254 void jtextlayout_measuretext(t_jtextlayout *textlayout, 1255 long startindex, 1256 long numchars, 1257 long includewhitespace, 1258 double *width, double *height, 1259 long *numlines); 1260 1261 1262 /** Draw a textlayout in a given graphics context. 1263 @ingroup textlayout 1264 @param tl The textlayout object to query. 1265 @param g The graphics context in which to draw the text. */ 1266 void jtextlayout_draw(t_jtextlayout *tl, t_jgraphics *g); 1267 1268 1269 /** Retrieve a count of the number of characters in a textlayout object. 1270 @ingroup textlayout 1271 @param tl The textlayout object to query. 1272 @return The number of characters. */ 1273 long jtextlayout_getnumchars(t_jtextlayout *tl); 1274 1275 1276 /** Retrieve the #t_rect containing a character at a given index. 1277 @ingroup textlayout 1278 @param tl The textlayout object to query. 1279 @param index The index from which to fetch the unicode character. 1280 @param rect The address of a valid #t_rect which will be filled in upon return. 1281 @return A Max error code. */ 1282 t_max_err jtextlayout_getcharbox(t_jtextlayout *tl, long index, t_rect *rect); 1283 1284 1285 /** Retrieve the unicode character at a given index. 1286 @ingroup textlayout 1287 @param tl The textlayout object to query. 1288 @param index The index from which to fetch the unicode character. 1289 @param pch The address of a variable to hold the unicode character value upon return. 1290 @return A Max error code. */ 1291 t_max_err jtextlayout_getchar(t_jtextlayout *tl, long index, long *pch); 1292 1293 1294 /** Create a t_jpath object representing the text layout. 1295 @ingroup textlayout 1296 @param tl The textlayout object to retrieve a path for. 1297 @return A t_jpath. When finished with the path free it with jgraphics_path_destroy. */ 1298 t_jpath* jtextlayout_createpath(t_jtextlayout *tl); 1299 1300 1301 /** An affine transformation (such as scale, shear, etc). 1302 @ingroup jmatrix */ 1303 typedef struct { 1304 double xx; ///< xx component 1305 double yx; ///< yx component 1306 double xy; ///< xy component 1307 double yy; ///< yy component 1308 double x0; ///< x translation 1309 double y0; ///< y translation 1310 } t_jmatrix; 1311 1312 /** Set a #t_jmatrix to an affine transformation. 1313 @ingroup jmatrix 1314 @param x 1315 @param xx 1316 @param yx 1317 @param xy 1318 @param yy 1319 @param x0 1320 @param y0 1321 @remark given x,y the matrix specifies the following transformation: 1322 @code 1323 xnew = xx * x + xy * y + x0; 1324 ynew = yx * x + yy * y + y0; 1325 @endcode 1326 */ 1327 void jgraphics_matrix_init(t_jmatrix *x, double xx, double yx, double xy, double yy, double x0, double y0); 1328 1329 /** Modify a matrix to be an identity transform. 1330 @ingroup jmatrix 1331 @param x The #t_jmatrix. 1332 */ 1333 void jgraphics_matrix_init_identity(t_jmatrix *x); 1334 1335 /** Initialize a #t_jmatrix to translate (offset) a point. 1336 @ingroup jmatrix 1337 @param x The #t_jmatrix. 1338 @param tx The amount of x-axis translation. 1339 @param ty The amount of y-axis translation. 1340 */ 1341 void jgraphics_matrix_init_translate(t_jmatrix *x, double tx, double ty); 1342 1343 /** Initialize a #t_jmatrix to scale (offset) a point. 1344 @ingroup jmatrix 1345 @param x The #t_jmatrix. 1346 @param sx The horizontal scale factor. 1347 @param sy The vertical scale factor. 1348 */ 1349 void jgraphics_matrix_init_scale(t_jmatrix *x, double sx, double sy); 1350 1351 /**Initialize a #t_jmatrix to rotate (offset) a point. 1352 @ingroup jmatrix 1353 @param x The #t_jmatrix. 1354 @param radians The angle or rotation in radians. 1355 */ 1356 void jgraphics_matrix_init_rotate(t_jmatrix *x, double radians); 1357 1358 1359 /** Apply a translation to an existing matrix. 1360 @ingroup jmatrix 1361 @param x The #t_jmatrix. 1362 @param tx The amount of x-axis translation. 1363 @param ty The amount of y-axis translation. 1364 */ 1365 void jgraphics_matrix_translate(t_jmatrix *x, double tx, double ty); 1366 1367 /** Apply a scaling to an existing matrix. 1368 @ingroup jmatrix 1369 @param x The #t_jmatrix. 1370 @param sx The horizontal scale factor. 1371 @param sy The vertical scale factor. 1372 */ 1373 void jgraphics_matrix_scale(t_jmatrix *x, double sx, double sy); 1374 1375 /** Apply a rotation to an existing matrix. 1376 @ingroup jmatrix 1377 @param x The #t_jmatrix. 1378 @param radians The angle or rotation in radians. 1379 */ 1380 void jgraphics_matrix_rotate(t_jmatrix *x, double radians); 1381 1382 /** Invert an existing matrix. 1383 @ingroup jmatrix 1384 @param x The #t_jmatrix. 1385 */ 1386 void jgraphics_matrix_invert(t_jmatrix *x); 1387 1388 /** Multiply two matrices: resulting matrix has effect of first applying a and then applying b. 1389 @ingroup jmatrix 1390 @param result The resulting product #t_jmatrix. 1391 @param a The first operand. 1392 @param b The second operand. 1393 */ 1394 void jgraphics_matrix_multiply(t_jmatrix *result, const t_jmatrix *a, const t_jmatrix *b); 1395 1396 1397 /** Transform a point using a #t_jmatrix transormation. 1398 @ingroup jmatrix 1399 @param matrix The #t_jmatrix. 1400 @param x The address of the variable holding the x coordinate. 1401 @param y The address of the variable holding the y coordinate. 1402 */ 1403 void jgraphics_matrix_transform_point(const t_jmatrix *matrix, double *x, double *y); 1404 1405 1406 1407 1408 // Patterns 1409 t_jpattern* jgraphics_pattern_create_rgba(double red, 1410 double green, // colors between 0 and 1 1411 double blue, 1412 double alpha); // solid, set alpha to 1.0 1413 1414 t_jpattern* jgraphics_pattern_create_for_surface(t_jsurface *surface); 1415 1416 t_jpattern* jgraphics_pattern_create_linear(double x0, double y0, double x1, double y1); 1417 1418 /* 1419 cx0 : x coordinate for the center of the start circle 1420 cy0 : y coordinate for the center of the start circle 1421 radius0 : radius of the start circle 1422 cx1 : x coordinate for the center of the end circle 1423 cy1 : y coordinate for the center of the end circle 1424 radius1 : radius of the end circle 1425 */ 1426 t_jpattern* jgraphics_pattern_create_radial(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1); 1427 1428 void jgraphics_pattern_add_color_stop_rgba(t_jpattern* pattern, double offset, double red, double green, double blue, double alpha); 1429 1430 void jgraphics_pattern_add_color_for_proportion(t_jpattern* pattern, double proportion); 1431 1432 t_jpattern *jgraphics_pattern_reference(t_jpattern *pattern); 1433 void jgraphics_pattern_destroy(t_jpattern *pattern); 1434 1435 typedef enum _jgraphics_pattern_type { 1436 JGRAPHICS_PATTERN_TYPE_SOLID, 1437 JGRAPHICS_PATTERN_TYPE_SURFACE, 1438 JGRAPHICS_PATTERN_TYPE_LINEAR, 1439 JGRAPHICS_PATTERN_TYPE_RADIAL 1440 } t_jgraphics_pattern_type; 1441 1442 t_jgraphics_pattern_type jgraphics_pattern_get_type(t_jpattern *pattern); 1443 1444 typedef enum _jgraphics_extend { 1445 JGRAPHICS_EXTEND_NONE, 1446 JGRAPHICS_EXTEND_REPEAT, 1447 JGRAPHICS_EXTEND_REFLECT, 1448 JGRAPHICS_EXTEND_PAD 1449 } t_jgraphics_extend; 1450 1451 // rbs -- JGRAPHICS_EXTEND_NONE for images isn't actually supported yet 1452 #define JGRAPHICS_EXTEND_GRADIENT_DEFAULT JGRAPHICS_EXTEND_PAD 1453 #define JGRAPHICS_EXTEND_SURFACE_DEFAULT JGRAPHICS_EXTEND_NONE 1454 1455 // These functions are placeholders for Cairo functionality, but for which there is no direct JUCE implementation. 1456 // They may or may not be implemented in the future. 1457 void jgraphics_pattern_set_extend(t_jpattern *pattern, t_jgraphics_extend extend); 1458 t_jgraphics_extend jgraphics_pattern_get_extend(t_jpattern *pattern); 1459 1460 void jgraphics_pattern_set_matrix(t_jpattern *pattern, const t_jmatrix *matrix); 1461 void jgraphics_pattern_get_matrix(t_jpattern *pattern, t_jmatrix *matrix); 1462 // pattern matrix convenience functions 1463 void jgraphics_pattern_translate(t_jpattern *pattern, double tx, double ty); 1464 void jgraphics_pattern_scale(t_jpattern *pattern, double sx, double sy); 1465 void jgraphics_pattern_rotate(t_jpattern *pattern, double angle); 1466 void jgraphics_pattern_transform(t_jpattern *pattern, const t_jmatrix *matrix); 1467 void jgraphics_pattern_identity_matrix(t_jpattern *pattern); 1468 t_jsurface *jgraphics_pattern_get_surface(t_jpattern *pattern); 1469 1470 // Transforms 1471 void jgraphics_translate(t_jgraphics *g, double tx, double ty); 1472 void jgraphics_scale(t_jgraphics *g, double sx, double sy); 1473 void jgraphics_rotate(t_jgraphics *g, double angle); 1474 void jgraphics_transform(t_jgraphics *g, const t_jmatrix *matrix); 1475 void jgraphics_set_matrix(t_jgraphics *g, const t_jmatrix *matrix); 1476 void jgraphics_get_matrix(t_jgraphics *g, t_jmatrix *matrix); 1477 void jgraphics_identity_matrix(t_jgraphics *g); 1478 1479 1480 /** User coordinates are those passed to drawing functions in a given #t_jgraphics context. 1481 Device coordinates refer to patcher canvas coordinates, before any zooming. 1482 @ingroup jgraphics */ 1483 void jgraphics_user_to_device(t_jgraphics *g, 1484 double *x, 1485 double *y); 1486 1487 /** User coordinates are those passed to drawing functions in a given #t_jgraphics context. 1488 Device coordinates refer to patcher canvas coordinates, before any zooming. 1489 @ingroup jgraphics */ 1490 void jgraphics_device_to_user(t_jgraphics *g, 1491 double *x, 1492 double *y); 1493 1494 // Graphics 1495 1496 void jgraphics_save(t_jgraphics* g); // doesn't save/restore the path 1497 void jgraphics_restore(t_jgraphics *g); 1498 1499 t_jsurface* jgraphics_get_target(t_jgraphics *g); 1500 1501 1502 // Pushing and Popping groups is not currently exported or supported by Max. 1503 void jgraphics_push_group(t_jgraphics *g); 1504 t_jpattern* jgraphics_pop_group(t_jgraphics *g); 1505 void jgraphics_pop_group_to_source(t_jgraphics *g); 1506 t_jsurface* jgraphics_get_group_target(t_jgraphics *g); 1507 // jgraphics_pop_group_surface is not in cairo, but equivalent to the following sequence 1508 // jgraphics_get_group_target(), jgraphics_surface_reference(), jgraphics_restore() 1509 t_jsurface* jgraphics_pop_group_surface(t_jgraphics *g); 1510 1511 1512 // if a t_jpattern source was previously selected, it is removed 1513 void jgraphics_set_source_rgba(t_jgraphics *g, 1514 double red, 1515 double green, 1516 double blue, 1517 double alpha); 1518 1519 void jgraphics_set_source_jrgba(t_jgraphics *g, t_jrgba *rgba); 1520 1521 void jgraphics_set_source_rgb(t_jgraphics *g, 1522 double red, 1523 double green, 1524 double blue); 1525 // if NULL source is passed in will revert to prior solid color. 1526 void jgraphics_set_source(t_jgraphics *g, t_jpattern *source); 1527 1528 // convenience function for creating pattern from surface and making it the source for g 1529 void jgraphics_set_source_surface(t_jgraphics *g, 1530 t_jsurface *surface, 1531 double x, double y); 1532 1533 1534 typedef enum _jgraphics_pattern_shared { 1535 JGRAPHICS_PATTERN_GRAY = 0, 1536 JGRAPHICS_NUM_SHARED_PATTERNS 1537 } t_jgraphics_pattern_shared; 1538 1539 1540 // We create some standard patterns which are "owned" by the jgraphics library. 1541 // You can use these as a source for filling or stroking paths. 1542 // The gray patter above is what is used to put dotted lines around the comment box, and others. 1543 void jgraphics_set_source_shared(t_jgraphics *g, t_jgraphics_pattern_shared patindex); 1544 1545 // color transforms 1546 // each component (rgba) has a scale and offset value as part of the graphics context. 1547 // this is saved and restored with the jgraphics_save and jgraphics_restore calls. 1548 1549 void jgraphics_scale_source_rgba(t_jgraphics *g, 1550 double redscale, 1551 double greenscale, 1552 double bluescale, 1553 double alphascale); 1554 1555 void jgraphics_translate_source_rgba(t_jgraphics *g, 1556 double redoffset, 1557 double greenoffset, 1558 double blueoffset, 1559 double alphaoffset); 1560 1561 // example use of this function is in the gswitch object 1562 void jgraphics_set_dash(t_jgraphics *g, 1563 double *dashes, 1564 int numdashes, 1565 double offset); // offset not supported yet 1566 1567 1568 typedef enum _jgraphics_fill_rule { 1569 JGRAPHICS_FILL_RULE_WINDING, 1570 JGRAPHICS_FILL_RULE_EVEN_ODD 1571 } t_jgraphics_fill_rule; 1572 1573 void jgraphics_set_fill_rule(t_jgraphics *g, t_jgraphics_fill_rule fill_rule); 1574 t_jgraphics_fill_rule jgraphics_get_fill_rule(t_jgraphics *g); 1575 1576 void jgraphics_set_line_cap(t_jgraphics *g, t_jgraphics_line_cap line_cap); 1577 t_jgraphics_line_cap jgraphics_get_line_cap(t_jgraphics *g); 1578 1579 void jgraphics_set_line_join(t_jgraphics *g, 1580 t_jgraphics_line_join line_join); 1581 t_jgraphics_line_join jgraphics_get_line_join(t_jgraphics *g); 1582 1583 void jgraphics_set_line_width(t_jgraphics *g, 1584 double width); 1585 double jgraphics_get_line_width(t_jgraphics *g); 1586 1587 // perhaps someday we could expose something like this 1588 // jgraphics_set_operator() 1589 1590 void jgraphics_fill(t_jgraphics *g); 1591 void jgraphics_fill_preserve(t_jgraphics *g); 1592 void jgraphics_fill_with_alpha(t_jgraphics *g, double alpha); 1593 void jgraphics_fill_preserve_with_alpha(t_jgraphics *g, double alpha); 1594 // Note: you can use jgraphics_image_surface_create with a 1x1 offscreen to do path stuff 1595 // that isn't actually going to be used for drawing. 1596 int jgraphics_in_fill(t_jgraphics *g, double x, double y); // hit test 1597 int jgraphics_path_intersects_line(t_jgraphics *g, double x1, double y1, double x2, double y2); // not in cairo 1598 1599 // various utilities 1600 int jgraphics_ptinrect(t_pt pt, t_rect rect); 1601 1602 int jgraphics_lines_intersect(double l1x1, double l1y1, double l1x2, double l1y2, double l2x1, double l2y1, double l2x2, double l2y2, double *ix, double *iy); 1603 int jgraphics_line_intersects_rect(double linex1, double liney1, double linex2, double liney2, t_rect r, double *ix, double *iy); 1604 1605 // jgraphics_ptaboveline: returns non-zero if the given point is above the line 1606 // specified by the two points: lx1, ly1 to ending point lx2, ly2 1607 int jgraphics_ptaboveline(t_pt pt, double lx1, double ly1, double lx2, double ly2); 1608 1609 // return nonzero if points a and b are on the same side of the line specified by lx1, ly1 -> lx2, ly2 1610 int jgraphics_points_on_same_side_of_line(t_pt a, t_pt b, double lx1, double ly1, double lx2, double ly2); 1611 1612 /* 1613 Note that the functions jgraphics_rectangle_rounded() and jgraphics_ptinroundedrect() 1614 need different size arguments as ovalsize and ovalwidth. 1615 */ 1616 int jgraphics_ptinroundedrect(t_pt pt, t_rect rect, double ovalwidth, double ovalheight); 1617 1618 // get extents of current path in device coordinates (after transform matrix) 1619 void jgraphics_fill_extents(t_jgraphics *g, 1620 double *x1, double *y1, 1621 double *x2, double *y2); 1622 1623 // paints current source using alpha of pattern 1624 //void jgraphics_mask(t_jgraphics *x, 1625 // t_jpattern *pattern); 1626 1627 // paints current source using alpha of surface 1628 //void jgraphics_mask_surface(t_jgraphics *g, 1629 // t_jsurface *surface, 1630 // double surface_x, // surface origin 1631 // double surface_y); // surface origin 1632 1633 // paint current source in entire current clip region 1634 void jgraphics_paint(t_jgraphics *g); 1635 void jgraphics_paint_with_alpha(t_jgraphics *g, 1636 double alpha); 1637 1638 void jgraphics_stroke(t_jgraphics *g); 1639 void jgraphics_stroke_preserve(t_jgraphics *g); 1640 void jgraphics_stroke_with_alpha(t_jgraphics *g, double alpha); 1641 void jgraphics_stroke_preserve_with_alpha(t_jgraphics *g, double alpha); 1642 1643 // fast non antialiasing/rotating versions 1644 void jgraphics_rectangle_fill_fast(t_jgraphics *g, double x, double y, double width, double height); 1645 void jgraphics_rectangle_draw_fast(t_jgraphics *g, double x, double y, double width, double height, double border); 1646 void jgraphics_line_draw_fast(t_jgraphics *g, double x1, double y1, double x2, double y2, double linewidth); 1647 1648 // desktopui API: so externals can create transparent popup windows, draw to them, and receive mouse events 1649 1650 typedef enum _jdesktopui_flags { 1651 JDESKTOPUI_FLAGS_FIRSTFLAG = 1 // no flags defined yet, but this is a placeholder 1652 } t_jdesktopui_flags; 1653 1654 t_jdesktopui* jdesktopui_new(t_object *owner, t_jdesktopui_flags flags, t_rect rect); 1655 void jdesktopui_destroy(t_jdesktopui *x); 1656 void jdesktopui_setvisible(t_jdesktopui *x, long way); 1657 void jdesktopui_setalwaysontop(t_jdesktopui *x, long way); 1658 void jdesktopui_setrect(t_jdesktopui *x, t_rect rect); 1659 void jdesktopui_getrect(t_jdesktopui *x, t_rect *rect); 1660 void jdesktopui_setposition(t_jdesktopui *x, t_pt pt); 1661 void jdesktopui_setfadetimes(t_jdesktopui *x, int fade_in_ms, int fade_out_ms); 1662 t_jgraphics* jdesktopui_get_jgraphics(t_jdesktopui *x); 1663 void jdesktopui_redraw(t_jdesktopui *x); 1664 void jdesktopui_redrawrect(t_jdesktopui *x, t_rect rect); 1665 double jdesktopui_getopacity(t_jdesktopui *x); 1666 void *jdesktopui_createtimer(t_jdesktopui *x, t_symbol *msg, void *arg); 1667 void jdesktopui_starttimer(void *ref, int interval); 1668 void jdesktopui_stoptimer(void *ref, int alsodelete); 1669 void jdesktopui_destroytimer(void *ref); 1670 1671 // color transformations 1672 1673 t_jrgba jgraphics_jrgba_contrasting(t_jrgba *c, double amount); 1674 t_jrgba jgraphics_jrgba_contrastwith(t_jrgba *c1, t_jrgba *c2); 1675 t_jrgba jgraphics_jrgba_darker(t_jrgba *c, double amount); 1676 t_jrgba jgraphics_jrgba_brighter(t_jrgba *c, double amount); 1677 t_jrgba jgraphics_jrgba_overlay(t_jrgba *c1, t_jrgba *c2); 1678 t_jrgba jgraphics_jrgba_interpolate(t_jrgba *c1, t_jrgba *c2, double proportion); 1679 void jgraphics_jrgba_gethsb(t_jrgba *c, double *h, double *s, double *b); 1680 t_jrgba jgraphics_jrgba_fromhsb(double h, double s, double b, double a); 1681 1682 long jcolor_getcolor(t_symbol *name, t_jrgba *on, t_jrgba *off); 1683 void jcolor_linkcolor(t_object *x, t_symbol *colorname, t_symbol *attrname); 1684 void jcolor_unlinkcolor(t_object *x, t_symbol *colorname, t_symbol *attrname); 1685 char *jgraphics_jrgba_tohexstring(t_jrgba *c, long includealpha); 1686 1687 // popup menu API so externals can create popup menus that can also be drawn into 1688 1689 /** Create a pop-up menu. 1690 Free this pop-up menu using jpopupmenu_destroy(). 1691 @ingroup jpopupmenu 1692 @return A pointer to the newly created jpopupmenu object. */ 1693 t_jpopupmenu* jpopupmenu_create(); 1694 1695 /** Free a pop-up menu created with jpopupmenu_create(). 1696 @ingroup jpopupmenu 1697 @param menu The pop-up menu to be freed. */ 1698 void jpopupmenu_destroy(t_jpopupmenu *menu); 1699 1700 /** Clear the conents of a pop-up menu. 1701 @ingroup jpopupmenu 1702 @param menu The pop-up menu whose contents will be cleared. */ 1703 void jpopupmenu_clear(t_jpopupmenu *menu); 1704 1705 typedef struct _jpopupmenu_options { 1706 bool zoomwithview; 1707 int defitemid; 1708 } t_jpopupmenu_options; 1709 1710 t_jpopupmenu_options jpopupmenu_default_options(); 1711 1712 // Internal use only 1713 void jpopupmenu_setitemcallback(method fun, void *arg); 1714 1715 /** Set the colors used by a pop-up menu. 1716 @ingroup jpopupmenu 1717 @param menu The pop-up menu to which the colors will be applied. 1718 @param text The text color for menu items. 1719 @param bg The background color for menu items. 1720 @param highlightedtext The text color for the highlighted menu item. 1721 @param highlightedbg The background color the highlighted menu item. */ 1722 void jpopupmenu_setcolors(t_jpopupmenu *menu, 1723 t_jrgba text, 1724 t_jrgba bg, 1725 t_jrgba highlightedtext, 1726 t_jrgba highlightedbg); 1727 1728 // Internal use only (header functions are not exported) 1729 void jpopupmenu_setheadercolor(t_jpopupmenu *menu, t_jrgba *hc); 1730 1731 /** Set the font used by a pop-up menu. 1732 @ingroup jpopupmenu 1733 @param menu The pop-up menu whose font will be set. 1734 @param font A pointer to a font object, whose font info will be copied to the pop-up menu. */ 1735 void jpopupmenu_setfont(t_jpopupmenu *menu, t_jfont *font); 1736 1737 /** Add an item to a pop-up menu. 1738 @ingroup jpopupmenu 1739 @param menu The pop-up menu to which the item will be added. 1740 @param itemid Each menu item should be assigned a unique integer id using this parameter. 1741 @param utf8Text The text to display in for the menu item. 1742 @param textColor The color to use for the menu item, or NULL to use the default color. 1743 @param checked A non-zero value indicates that the item should have a check-mark next to it. 1744 @param disabled A non-zero value indicates that the item should be disabled. 1745 @param icon A #t_jsurface will be used as an icon for the menu item if provided here. 1746 Pass NULL for no icon. */ 1747 void jpopupmenu_additem(t_jpopupmenu *menu, 1748 int itemid, 1749 const char *utf8Text, 1750 t_jrgba *textColor, 1751 int checked, 1752 int disabled, 1753 t_jsurface *icon); 1754 1755 /** Add a pop-menu to another pop-menu as a submenu. 1756 Note that the submenu contents are copied at the time of this call. 1757 So, any changes to the submenu after this returns won't have an effect. 1758 Also, it is safe to destroy the submenu after this function returns. 1759 @ingroup jpopupmenu 1760 @param menu The pop-up menu to which a menu will be added as a submenu. 1761 @param utf8Name The name of the menu item. 1762 @param submenu The pop-up menu which will be used as the submenu. 1763 @param disabled Pass a non-zero value to disable the menu item. */ 1764 void jpopupmenu_addsubmenu(t_jpopupmenu *menu, 1765 const char *utf8Name, 1766 t_jpopupmenu *submenu, 1767 int disabled); 1768 1769 /** Add a separator to a pop-menu. 1770 @ingroup jpopupmenu 1771 @param menu The pop-up menu to which the separator will be added. */ 1772 void jpopupmenu_addseparator(t_jpopupmenu *menu); 1773 void jpopupmenu_addseperator(t_jpopupmenu *menu); // [sic] 1774 1775 // Internal use only (header functions are not exported) 1776 void jpopupmenu_addheader(t_jpopupmenu *menu, const char *utf8Text); 1777 1778 // Internal use only 1779 // ownerdraw: give a t_object to the menu. 1780 // it will be sent a paint message to draw itself. 1781 // it will be sent a getsize message to find out the size. 1782 void jpopupmenu_addownerdrawitem(t_jpopupmenu *menu, 1783 int itemid, 1784 t_object *owner); 1785 1786 /** Tell a menu to display at a specified location. 1787 @ingroup jpopupmenu 1788 @param menu The pop-up menu to display. 1789 @param screen The point at which to display in screen coordinates. 1790 @param defitemid The initially choosen item id. 1791 @return The item id for the item in the menu choosen by the user. */ 1792 int jpopupmenu_popup(t_jpopupmenu *menu, 1793 t_pt screen, 1794 int defitemid); // initial item id 1795 1796 /** Tell a menu to display above a given box in a patcher. 1797 @ingroup jpopupmenu 1798 @param menu The pop-up menu to display. 1799 @param box The box above which to display the menu. 1800 @param view The patcherview for the box in which to display the menu. 1801 @param offset An offset from the box position at which to display the menu. 1802 @param defitemid The initially choosen item id. 1803 @return The item id for the item in the menu choosen by the user. */ 1804 int jpopupmenu_popup_abovebox(t_jpopupmenu *menu, t_object *box, t_object *view, int offset, int defitemid); 1805 1806 /** Tell a menu to display near a given box in a patcher. 1807 @ingroup jpopupmenu 1808 @param menu The pop-up menu to display. 1809 @param box The box above which to display the menu. 1810 @param view The patcherview for the box in which to display the menu. 1811 @param defitemid The initially choosen item id. 1812 @return The item id for the item in the menu choosen by the user. */ 1813 int jpopupmenu_popup_nearbox(t_jpopupmenu *menu, 1814 t_object *box, t_object *view, 1815 int defitemid); 1816 1817 /** Tell a menu to display near a given box in a patcher with options. 1818 @ingroup jpopupmenu 1819 @param menu The pop-up menu to display. 1820 @param box The box above which to display the menu. 1821 @param view The patcherview for the box in which to display the menu. 1822 @param opts The jpopupmenu options 1823 @return The item id for the item in the menu choosen by the user. */ 1824 int jpopupmenu_popup_nearbox_with_options(t_jpopupmenu *menu, 1825 t_object *box, t_object *view, 1826 t_jpopupmenu_options opts); 1827 1828 /** Tell a menu to display below a given rectangle in a patcher. 1829 @ingroup jpopupmenu 1830 @param menu The pop-up menu to display. 1831 @param rect The rectangle below which to display the menu. 1832 @param defitemid The initially choosen item id. 1833 @return The item id for the item in the menu choosen by the user. */ 1834 int jpopupmenu_popup_belowrect(t_jpopupmenu *menu, t_rect rect, int defitemid); 1835 1836 /** Tell a menu to display above a given rectangle in a patcher. 1837 @ingroup jpopupmenu 1838 @param menu The pop-up menu to display. 1839 @param rect The rectangle above which to display the menu. 1840 @param defitemid The initially choosen item id. 1841 @return The item id for the item in the menu choosen by the user. */ 1842 int jpopupmenu_popup_aboverect(t_jpopupmenu *menu, t_rect rect, int defitemid); 1843 1844 int jpopupmenu_popup_leftofpt(t_jpopupmenu *menu, t_pt pt, int defitemid, int flags); 1845 1846 int jpopupmenu_popup_centered(t_jpopupmenu *menu, 1847 t_pt screen, 1848 int defitemid); // initial item id 1849 1850 void jpopupmenu_estimatesize(t_jpopupmenu *menu, int *width, int *height); 1851 void jpopupmenu_setitemtooltip(void *itemref, char *tip); 1852 void jpopupmenu_setfixedwidth(t_jpopupmenu *menu, int width); 1853 void jpopupmenu_additemwithshortcut(t_jpopupmenu *menu, int itemid, 1854 const char *utf8Text, 1855 t_jrgba *textColor, 1856 int checked, int disabled, 1857 t_jsurface *icon, t_jsvg *svg, char *shortcut); 1858 1859 enum { 1860 JPOPUPMENU_DARKSTYLE = 1, 1861 JPOPUPMENU_FLATSTYLE = 2 1862 }; 1863 1864 void jpopupmenu_setstandardstyle(t_jpopupmenu *menu, long styleindex, double fontsize, int margin); 1865 1866 1867 /** Tell any open popup menus to go away. 1868 */ 1869 void jpopupmenu_closeall(); 1870 1871 // unused by any C74 code 1872 // you can draw to a surface and then turn that into a cursor 1873 // only works with 16 x 16 surfaces 1874 void jmouse_setcursor_surface(t_object *patcherview, t_object *box, t_jsurface *surface, int xHotSpot, int yHotSpot); 1875 1876 1877 // Unused by any C74 code 1878 void jbox_fontface_to_weight_slant(t_object *b, long *weight, long *slant); 1879 1880 /** Get the slant box's font. 1881 @ingroup jfont 1882 @param b An object's box. 1883 @return A value from the #t_jgraphics_font_weight enum. */ 1884 long jbox_get_font_weight(t_object *b); 1885 1886 /** Get the slant box's font. 1887 @ingroup jfont 1888 @param b An object's box. 1889 @return A value from the #t_jgraphics_font_slant enum. */ 1890 long jbox_get_font_slant(t_object *b); 1891 1892 // create a jfont object for box -- internal use only 1893 t_jfont *jbox_createfont(t_object *b); 1894 1895 void jgraphics_jrgba_set_brightness(t_jrgba *c, double amt); 1896 1897 // utility funtions and macros for new rgba attribtes and legacy rgb attributes 1898 1899 // don't call these two functions directly, instead use the macros below... 1900 t_max_err jgraphics_attr_setrgba(t_object *x, t_object *attr, long argc, t_atom *argv); 1901 t_max_err jgraphics_attr_setrgb_alias(t_object *x, t_object *attr, long argc, t_atom *argv); 1902 1903 1904 /** 1905 Create a color (#t_jrgba) attribute and add it to a Max class. 1906 1907 @ingroup attr 1908 @param c The class pointer. 1909 @param attrname The name of this attribute as a C-string. 1910 @param flags Any flags you wish to declare for this attribute, as defined in #e_max_attrflags. 1911 @param structname The C identifier for the struct (containing a valid #t_object header) representing an instance of this class. 1912 @param structmember The C identifier of the member in the struct that holds the value of this attribute. 1913 */ 1914 #define CLASS_ATTR_RGBA(c,attrname,flags,structname,structmember) \ 1915 { CLASS_ATTR_DOUBLE_ARRAY(c,attrname,flags,structname,structmember,4); \ 1916 CLASS_ATTR_ACCESSORS(c,attrname,NULL,jgraphics_attr_setrgba); \ 1917 CLASS_ATTR_PAINT(c,attrname,0); } 1918 1919 1920 // for internal use only? 1921 #define CLASS_ATTR_RGBA_LEGACY(c,attrname,aliasname,flags,structname,structmember) \ 1922 { CLASS_ATTR_RGBA(c,attrname,flags,structname,structmember); \ 1923 CLASS_ATTR_ALIAS(c,attrname,aliasname); \ 1924 CLASS_ATTR_INVISIBLE(c,aliasname,0); \ 1925 CLASS_ATTR_ACCESSORS(c,aliasname,NULL,jgraphics_attr_setrgb_alias); } 1926 1927 1928 /** 1929 Retrieves the value of a color attribute, given its parent object and name. 1930 1931 @ingroup attr 1932 @param ob The attribute's parent object 1933 @param s The attribute's name 1934 @param c The address of a #t_jrgba struct that will be filled with the attribute's color component values. 1935 @return This function returns the error code #MAX_ERR_NONE if successful, 1936 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 1937 */ 1938 t_max_err object_attr_getjrgba(void *ob, t_symbol *s, t_jrgba *c); 1939 1940 1941 /** 1942 Sets the value of a color attribute, given its parent object and name. 1943 The function will call the attribute's <tt>set</tt> method, using the data provided. 1944 1945 @ingroup attr 1946 @param ob The attribute's parent object 1947 @param s The attribute's name 1948 @param c The address of a #t_jrgba struct that contains the new color. 1949 @return This function returns the error code #MAX_ERR_NONE if successful, 1950 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 1951 */ 1952 t_max_err object_attr_setjrgba(void *ob, t_symbol *s, t_jrgba *c); 1953 1954 1955 /** Get the components of a color in an array of pre-allocated atoms. 1956 1957 @ingroup color 1958 @param argv The address to the first of an array of atoms that will hold the result. 1959 At least 4 atoms must be allocated, as 4 atoms will be set by this function 1960 for the red, green, blue, and alpha components. 1961 @param c The address of a #t_jrgba struct from which the color components will be fetched. 1962 */ 1963 void jrgba_to_atoms(t_jrgba *c, t_atom *argv); 1964 1965 1966 /** Set the components of a color by providing an array of atoms. 1967 If it is an array of 3 atoms, then the atoms provided should define the 1968 red, green, and blue components (in this order) in a range of [0.0, 1.0]. 1969 If a 4th atom is provided, it will define the alpha channel. 1970 If the alpha channel is not defined then it is assumed to be 1.0. 1971 1972 @ingroup color 1973 @param argc The number of atoms in the array provided in argv. 1974 This should be 3 or 4 depending on whether or not the alpha channel is being provided. 1975 @param argv The address to the first of an array of atoms that define the color. 1976 @param c The address of a #t_jrgba struct for which the color will be defined. 1977 @return A Max error code. */ 1978 t_max_err atoms_to_jrgba(long argc, t_atom *argv, t_jrgba *c); 1979 1980 1981 /** Set the components of a color. 1982 @ingroup color 1983 @param prgba The address of a #t_jrgba struct for which the color will be defined. 1984 @param r The value of the red component in a range of [0.0, 1.0]. 1985 @param g The value of the green component in a range of [0.0, 1.0]. 1986 @param b The value of the blue component in a range of [0.0, 1.0]. 1987 @param a The value of the alpha component in a range of [0.0, 1.0]. */ 1988 void jrgba_set(t_jrgba *prgba, double r, double g, double b, double a); 1989 1990 1991 /** Copy a color. 1992 @ingroup color 1993 @param dest The address of a #t_jrgba struct to which the color will be copied. 1994 @param src The address of a #t_jrgba struct from which the color will be copied. */ 1995 void jrgba_copy(t_jrgba *dest, t_jrgba *src); 1996 1997 1998 /** Compare two colors for equality. 1999 @ingroup color 2000 @param rgba1 The address of a #t_jrgba struct to compare. 2001 @param rgba2 The address of another #t_jrgba struct to compare. 2002 @return returns 1 if rgba1 == rgba2. */ 2003 long jrgba_compare(t_jrgba *rgba1, t_jrgba *rgba2); 2004 2005 2006 /** Get a list of of filetypes appropriate for use with jgraphics surfaces. 2007 @ingroup jgraphics 2008 @param dummy Unused. 2009 @param count The address of a variable to be set with the number of types in filetypes upon return. 2010 @param filetypes The address of a variable that will represent the array of file types upon return. 2011 @param alloc The address of a char that will be flagged with a 1 or a 0 depending on whether or not 2012 memory was allocated for the filetypes member. 2013 2014 @remark This example shows a common usage of jgraphics_getfiletypes(). 2015 @code 2016 char filename[MAX_PATH_CHARS]; 2017 t_fourcc *type = NULL; 2018 long ntype; 2019 long outtype; 2020 t_max_err err; 2021 char alloc; 2022 short path; 2023 t_jsurface *surface; 2024 2025 if (want_to_show_dialog) { 2026 jgraphics_getfiletypes(x, &ntype, &type, &alloc); 2027 err = open_dialog(filename, &path,(void *)&outtype, (void *)type, ntype); 2028 if (err) 2029 goto out; 2030 } 2031 else { 2032 strncpy_zero(filename, s->s_name, MAX_PATH_CHARS); 2033 err = locatefile_extended(filename, &path, &outtype, type, ntype); 2034 if (err) 2035 goto out; 2036 } 2037 surface = jgraphics_image_surface_create_referenced(filename, path); 2038 out: 2039 if (alloc) 2040 sysmem_freeptr((char *)type); 2041 @endcode 2042 */ 2043 void jgraphics_getfiletypes(void *dummy, long *count, t_fourcc **filetypes, char *alloc); 2044 2045 2046 // boxlayer stuff 2047 2048 /** Invalidate a layer, indicating that it needs to be re-drawn. 2049 @ingroup boxlayer 2050 @param b The object/box to invalidate. 2051 @param view The patcherview for the object which should be invalidated, or NULL for all patcherviews. 2052 @param name The name of the layer to invalidate. 2053 @return A Max error code. */ 2054 t_max_err jbox_invalidate_layer(t_object *b, t_object *view, t_symbol *name); 2055 2056 // unused by any C74 code 2057 t_max_err jbox_remove_layer(t_object *b, t_object *view, t_symbol *name); 2058 2059 /** Create a layer, and ready it for drawing commands. 2060 The layer drawing commands must be wrapped with a matching call to jbox_end_layer() 2061 prior to calling jbox_paint_layer(). 2062 2063 @ingroup boxlayer 2064 @param b The object/box to which the layer is attached. 2065 @param view The patcherview for the object to which the layer is attached. 2066 @param name A name for this layer. 2067 @param width The width of the layer. 2068 @param height The height of the layer. 2069 @return A #t_jgraphics context for drawing into the layer. */ 2070 t_jgraphics* jbox_start_layer(t_object *b, t_object *view, t_symbol *name, double width, double height); 2071 2072 /** Conclude a layer, indicating that it is complete and ready for painting. 2073 @ingroup boxlayer 2074 @param b The object/box for the layer opened by jbox_start_layer(). 2075 @param view The patcherview for the object opened by jbox_start_layer(). 2076 @param name The name of the layer. 2077 @return A Max error code. */ 2078 t_max_err jbox_end_layer(t_object *b, t_object *view, t_symbol *name); 2079 2080 /** Paint a layer at a given position. 2081 Note that the current color alpha value is used when painting layers to allow you to blend layers. 2082 The same is also true for jgraphics_image_surface_draw() and jgraphics_image_surface_draw_fast(). 2083 2084 @ingroup boxlayer 2085 @param b The object/box to be painted. 2086 @param view The patcherview for the object which should be painted, or NULL for all patcherviews. 2087 @param name The name of the layer to paint. 2088 @param x The x-coordinate for the position at which to paint the layer. 2089 @param y The y-coordinate for the position at which to paint the layer. 2090 @return A Max error code. */ 2091 t_max_err jbox_paint_layer(t_object *b, t_object *view, t_symbol *name, double x, double y); 2092 2093 2094 /** Simple utility to test for rectangle intersection. 2095 @ingroup jgraphics 2096 @param r1 The address of the first rect for the test. 2097 @param r2 The address of the second rect for the test. 2098 @return Returns true if the rects intersect, otherwise false. */ 2099 long jgraphics_rectintersectsrect(t_rect *r1, t_rect *r2); 2100 2101 /** Simple utility to test for rectangle containment. 2102 @ingroup jgraphics 2103 @param outer The address of the first rect for the test. 2104 @param inner The address of the second rect for the test. 2105 @return Returns true if the inner rect is completely inside the outer rect, 2106 otherwise false. */ 2107 long jgraphics_rectcontainsrect(t_rect *outer, t_rect *inner); 2108 2109 /** Generate a #t_rect according to positioning rules. 2110 @ingroup jgraphics 2111 @param positioned_rect The address of a valid #t_rect whose members will be filled in upon return. 2112 @param positioned_near_this_rect A pointer to a rect near which this rect should be positioned. 2113 @param keep_inside_this_rect A pointer to a rect defining the limits within which the new rect must reside. */ 2114 void jgraphics_position_one_rect_near_another_rect_but_keep_inside_a_third_rect( 2115 t_rect *positioned_rect, 2116 const t_rect *positioned_near_this_rect, 2117 const t_rect *keep_inside_this_rect); 2118 2119 2120 /** Clip to a subset of the graphics context; once done, cannot be undone, only further reduced. 2121 @ingroup jgraphics 2122 2123 @param g The #t_jgraphics context to be clipped. 2124 @param x x origin of clip region. 2125 @param y y origin of clip region. 2126 @param width width of clip region. 2127 @param height height of clip region. 2128 */ 2129 void jgraphics_clip(t_jgraphics *g, double x, double y, double width, double height); 2130 2131 2132 typedef enum _jgraphics_dpi_awareness { 2133 JGRAPHICS_DPI_AWARENESS_DEFAULT, // will be aware if Max has hi dpi enabled 2134 JGRAPHICS_DPI_AWARENESS_UNAWARE, 2135 JGRAPHICS_DPI_AWARENESS_SYSTEM_AWARE, 2136 JGRAPHICS_DPI_AWARENESS_PER_MONITOR_AWARE, 2137 JGRAPHICS_DPI_AWARENESS_PER_MONITOR_AWARE_V2 2138 } t_jgraphics_dpi_awareness; 2139 2140 2141 2142 t_dpi_awareness_context* jgraphics_enterdpiawarenesscontext(t_jgraphics_dpi_awareness awareness); 2143 void jgraphics_exitdpiawarenesscontext(t_dpi_awareness_context *context); 2144 2145 #if C74_PRAGMA_STRUCT_PACKPUSH 2146 #pragma pack(pop) 2147 #elif C74_PRAGMA_STRUCT_PACK 2148 #pragma pack() 2149 #endif 2150 2151 END_USING_C_LINKAGE 2152 2153 #endif // #ifndef _JGRAPHICS_H_ 2154