libcm is a C development framework with an emphasis on audio signal processing applications.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cmGrDevCtx.h 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. //| Copyright: (C) 2009-2020 Kevin Larke <contact AT larke DOT org>
  2. //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
  3. #ifndef cmGrDevCtx_h
  4. #define cmGrDevCtx_h
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. //( { file_desc:"Device independent graphics context object used by cmGr." kw:[plot]}
  9. enum
  10. {
  11. kOkGrDcRC = cmOkRC,
  12. kStackFaultGrDcRC,
  13. kDevDrvFailGrDcRC
  14. };
  15. typedef cmRC_t cmGrDcRC_t;
  16. extern cmGrDcH_t cmGrDcNullHandle;
  17. enum
  18. {
  19. kSolidLsGrFl = 0x01,
  20. kDashLsGrFl = 0x02,
  21. kDotLsGrFl = 0x04
  22. };
  23. enum
  24. {
  25. kHelveticaFfGrId,
  26. kTimesFfGrId,
  27. kCourierFfGrId,
  28. kFontFfCnt
  29. };
  30. enum
  31. {
  32. kNormalFsGrFl = 0x00,
  33. kBoldFsGrFl = 0x01,
  34. kItalicFsGrFl = 0x02
  35. };
  36. typedef struct cmGrDev_str
  37. {
  38. // return true on success
  39. bool (*create)( void* arg, unsigned w, unsigned h );
  40. void (*destroy)( void* arg );
  41. void (*begin_draw)( void* arg );
  42. void (*end_draw)( void* arg );
  43. void (*draw)( void* arg, int x, int y );
  44. void (*set_color)( void* arg, const cmGrColor_t c );
  45. void (*get_color)( void* arg, cmGrColor_t* c );
  46. // Return false if the 'font' label is not recognized.
  47. void (*set_font_family)(void* arg, unsigned fontId );
  48. unsigned (*get_font_family)(void* arg );
  49. void (*set_font_style)( void* arg, unsigned styleFLags );
  50. unsigned (*get_font_style)( void* arg );
  51. void (*set_font_size)( void* arg, unsigned size );
  52. unsigned (*get_font_size)( void* arg );
  53. void (*set_pen_style)( void* arg, unsigned styleFlags );
  54. unsigned (*get_pen_style)( void* arg );
  55. void (*set_pen_width)( void* arg, unsigned w );
  56. unsigned (*get_pen_width)( void* arg );
  57. void (*draw_line)( void* arg, int x, int y, int x1, int y1 );
  58. void (*draw_rect)( void* arg, int x, int y, unsigned w, unsigned h );
  59. void (*fill_rect)( void* arg, int x, int y, unsigned w, unsigned h );
  60. // Draw an ellipse, diamond or triangle inside the rectangle formed by l,t,w,h.
  61. void (*draw_ellipse)( void* arg, int x, int y, unsigned w, unsigned h );
  62. void (*fill_ellipse)( void* arg, int x, int y, unsigned w, unsigned h );
  63. void (*draw_diamond)( void* arg, int x, int y, unsigned w, unsigned h );
  64. void (*fill_diamond)( void* arg, int x, int y, unsigned w, unsigned h );
  65. void (*draw_triangle)( void* arg, int x, int y, unsigned w, unsigned h, unsigned dirFlag );
  66. void (*fill_triangle)( void* arg, int x, int y, unsigned w, unsigned h, unsigned dirFlag );
  67. // x,y identifies the left,lower text edge
  68. void (*draw_text)( void* arg, const char* text, int x, int y );
  69. void (*draw_text_rot)(void* arg, const char* text, int x, int y, int angle );
  70. void (*measure_text)( void* arg, const char* text, unsigned* w, unsigned* h );
  71. // Fill p[w*h*3] with RGB data.
  72. void (*read_image)( void* arg, unsigned char* p, int x, int y, unsigned w, unsigned h );
  73. void (*draw_image)( void* arg, const unsigned char* p, int x, int y, unsigned w, unsigned h );
  74. } cmGrDev_t;
  75. cmGrDcRC_t cmGrDevCtxCreate( cmCtx_t* ctx, cmGrDcH_t* hp, cmGrDev_t* dd, void* ddArg, int x, int y, int w, int h );
  76. cmGrDcRC_t cmGrDevCtxDestroy( cmGrDcH_t* hp );
  77. bool cmGrDevCtxIsValid( cmGrDcH_t h );
  78. cmGrDcRC_t cmGrDevCtxResize( cmGrDcH_t h, int x, int y, int ww, int hh );
  79. void cmGrDevCtxSize( cmGrDcH_t h, cmGrPExt_t* pext );
  80. void cmGrDevCtxBeginDraw( cmGrDcH_t h );
  81. void cmGrDevCtxEndDraw( cmGrDcH_t h );
  82. void cmGrDevCtxDraw( cmGrDcH_t h );
  83. void cmGrDcPushCtx( cmGrDcH_t h );
  84. void cmGrDcPopCtx( cmGrDcH_t h );
  85. unsigned cmGrDcColor( cmGrDcH_t h );
  86. void cmGrDcSetColorRgb( cmGrDcH_t h, unsigned char r, unsigned char g, unsigned char b );
  87. void cmGrDcSetColor( cmGrDcH_t h, cmGrColor_t color );
  88. unsigned cmGrDcFontFamily( cmGrDcH_t h );
  89. void cmGrDcSetFontFamily( cmGrDcH_t h, unsigned fontId );
  90. unsigned cmGrDcFontStyle( cmGrDcH_t h );
  91. void cmGrDcSetFontStyle( cmGrDcH_t h, unsigned style );
  92. unsigned cmGrDcFontSize( cmGrDcH_t h );
  93. void cmGrDcSetFontSize( cmGrDcH_t h, unsigned size );
  94. unsigned cmGrDcPenWidth( cmGrDcH_t h );
  95. void cmGrDcSetPenWidth( cmGrDcH_t h, unsigned width );
  96. unsigned cmGrDcPenStyle( cmGrDcH_t h );
  97. void cmGrDcSetPenStyle( cmGrDcH_t h, unsigned style );
  98. void cmGrDcDrawLine( cmGrDcH_t h, int x, int y, int x1, int y1 );
  99. // x,y is the upper,left.
  100. void cmGrDcDrawRect( cmGrDcH_t h, int x, int y, unsigned ww, unsigned hh );
  101. void cmGrDcDrawRectPExt( cmGrDcH_t h, const cmGrPExt_t* pext );
  102. void cmGrDcFillRect( cmGrDcH_t h, int x, int y, unsigned ww, unsigned hh );
  103. void cmGrDcDrawEllipse( cmGrDcH_t h, int x, int y, unsigned ww, unsigned hh );
  104. void cmGrDcFillEllipse( cmGrDcH_t h, int x, int y, unsigned ww, unsigned hh );
  105. void cmGrDcDrawDiamond( cmGrDcH_t h, int x, int y, unsigned ww, unsigned hh );
  106. void cmGrDcFillDiamond( cmGrDcH_t h, int x, int y, unsigned ww, unsigned hh );
  107. // Set 'dirFlag' to kTopGrFl,kBottomGrFl,kRightGrFl,kLeftGrFl to indicate
  108. // the direction the triangle is pointeed.
  109. void cmGrDcDrawTriangle( cmGrDcH_t h, int x, int y, unsigned ww, unsigned hh, unsigned dirFlag );
  110. void cmGrDcFillTriangle( cmGrDcH_t h, int x, int y, unsigned ww, unsigned hh, unsigned dirFlag );
  111. void cmGrDcMeasure( cmGrDcH_t h, const cmChar_t* text, cmGrPSz_t* sz );
  112. void cmGrDcDrawText( cmGrDcH_t h, const cmChar_t* text, int x, int y );
  113. void cmGrDcDrawTextRot( cmGrDcH_t h, const cmChar_t* text, int x, int y, int angle );
  114. void cmGrDcReadImage( cmGrDcH_t h, unsigned char* p, const cmGrPExt_t* pext );
  115. void cmGrDcDrawImage( cmGrDcH_t h, const unsigned char* p, const cmGrPExt_t* pext );
  116. //
  117. // Composite Functions
  118. //
  119. void cmGrDcSetFont( cmGrDcH_t h, unsigned fontId, unsigned size, unsigned style );
  120. void cmGrDcFontSetAndMeasure(cmGrDcH_t h, unsigned fontId, unsigned size, unsigned style, const cmChar_t* text, cmGrPSz_t* sz );
  121. enum
  122. {
  123. kLeftJsGrFl = 0x001,
  124. kRightJsGrFl = 0x002,
  125. kTopJsGrFl = 0x004,
  126. kBottomJsGrFl = 0x008,
  127. kHorzCtrJsGrFl = 0x010,
  128. kVertCtrJsGrFl = 0x020,
  129. kNorthJsGrFl = 0x040,
  130. kEastJsGrFl = 0x080,
  131. kSouthJsGrFl = 0x100,
  132. kWestJsGrFl = 0x200
  133. };
  134. // Use compass (NSEW) flags to select the draw point. Defaults to center for both dir's.
  135. // Use TBLF flags to select the text justification relative to the point.
  136. // In effect the TBLF flags select the corner of the text to place at the location of
  137. // the point selected by the NSEW flags.
  138. // If neither NS flag is set then the vertical point is set to the vertical center.
  139. // If neither EW flags is set then the horizontal point is set to the horzontal center.
  140. void cmGrDcDrawTextJustify( cmGrDcH_t h, unsigned fontId, unsigned size, unsigned style, const cmChar_t* text, const cmGrPExt_t* pext, unsigned flags );
  141. // Use LBLF to set the justification - the text corner to match to the given point.
  142. // If neither TL flag is given then the point is matched to the vertical center of the text.
  143. // If neither RL flag is given then the point is matched to the horizontal center of the text.
  144. void cmGrDcDrawTextJustifyPt( cmGrDcH_t h, unsigned fontId, unsigned size, unsigned style, const cmChar_t* text, unsigned flags, int x, int y );
  145. // Return the rectangle around the text but do not display the text.
  146. void cmGrDcDrawTextJustifyRect( cmGrDcH_t h, unsigned fontId, unsigned size, unsigned style, const cmChar_t* text, unsigned flags, int x, int y, cmGrPExt_t* pext );
  147. // Is the point x,y visible in this drawing context.
  148. bool cmGrDcPointIsVisible( cmGrDcH_t h, int x, int y );
  149. // Is any of the rectangle visible in this drawing context.
  150. bool cmGrDcRectIsVisible( cmGrDcH_t h, const cmGrPExt_t* r );
  151. //)
  152. #ifdef __cplusplus
  153. }
  154. #endif
  155. #endif