DRAW.H

[目次 | 型・クラス・構造体 | マクロ]

目次

型・クラス・構造体一覧

マクロ一覧


   1|/************************************************************************** 
   2|*  1. <<< 描画ツール (Draw) >>>
   3|***************************************************************************/
   4|
   5|#ifndef __DRAW_H
   6|#define __DRAW_H
   7|#include "drawscr.h"
   8|
   9|/*----------------------------------------------------------------------
  10|[Module Property]
  11|name = Draw
  12|title = 描画ツール
  13|category = グラフィック
  14|src = draw.c  draw.cc
  15|depend = DrawScr
  16|priority =
  17|accord =
  18|----------------------------------------------------------------------*/
  19|
  20|#ifndef USES_PRIORITY_HEADER
  21|/*[START_OF_PRIORITY_HEADER]*/
  22|
  23|#define  USES_DRAW
  24|typedef struct _Draw  Draw;
  25|typedef struct _Draw_CopyPen Draw_CopyPen;
  26|
  27|/*[END_OF_PRIORITY_HEADER]*/
  28|#endif /* USES_PRIORITY_HEADER */
  29|
  30|
  31|
  32|/*** モジュール・プロパティ ***/
  33|/*#define  Draw_ChkCharOut*/ /* 文字記号レイヤがあふれたかチェックする */
  34|
  35|/*** 集約コンポーネント ***/
  36|#ifndef  USES_DRAWSCR
  37|#include "drawscr.h"
  38|#endif
  39|
  40|/*-------------------------------------------------------------------*/
  41|/*--- Interface Area ------------------------------------------------*/
  42|/*-------------------------------------------------------------------*/
  43|
  44|#ifdef __cplusplus
  45|extern "C" {
  46|#endif
  47|
  48|/************************************************************************
  49|*  2. <<< 描画ツール [Draw] >>>
  50|*【役割】
  51|*・画面に描画ツール機能を付加します。(Adapter Pattern)
  52|*************************************************************************/
  53|struct _Draw {
  54|  DrawScr  drawScr;        /* 描画対象画面 */
  55|};
  56|
  57|/*** 基本的な処理をする ***/
  58|void  Draw_init( Draw*, DrawScr scr );
  59|/* type  Draw_getScr( Draw*, type ); */
  60|void  Draw_clear( Draw*, int color );
  61|void  Draw_pset( Draw*, int x, int y, int color );
  62|void  Draw_psetXor( Draw*, int x, int y, int color );
  63|void  Draw_psets( Draw*, int x, int y, unsigned char* pattern,
  64|  int nPixel, int color );
  65|
  66|/*** コピーする ***/
  67|void  Draw_xorPaint( Draw* );
  68|#ifdef USES_SCREEN
  69|void  Draw_flushTo( Draw* , Screen* target );
  70|void  Draw_flushFromScreen( Draw*, Screen* target );
  71|#ifdef USES_MASK
  72|void  Draw_flushTo2( Draw*, Screen* target, Mask_A* mask,
  73|  int baseX, int baseY, int clipX );
  74|void  Draw_flushFromScreen2( Draw*, Screen* target,
  75|  Mask_A* mask, int baseX, int baseY, int clipX );
  76|#endif /* USES_MASK */
  77|#endif /* USES_SCREEN */
  78|#ifdef USES_DSCREEN
  79|void  Draw_flushFromDScreen( Draw*, DScreen* target );
  80|void  Draw_flushFromDScreen2( Draw*, DScreen* target,
  81|  Mask_A* mask, int baseX, int baseY, int clipX );
  82|#endif /* USES_DSCREEN */
  83|
  84|/*** 図形を描く ***/
  85|void  Draw_line( Draw*, int x1, int y1, int x2, int y2, int color );
  86|void  Draw_line2( Draw*, int x1, int y1, int x2, int y2, int color );
  87|void  Draw_loseLine( Draw*, int x1, int y1, int x2, int y2,
  88|  int color, int pattern );
  89|void  Draw_boldLine( Draw*, int x1, int y1, int x2, int y2,
  90|  int color, int width, int type );
  91|void  Draw_lineForXorPaint( Draw*, int x1, int y1, int x2, int y2,
  92|  int color );
  93|void  Draw_copyLine( Draw*, int x1, int y1, int x2, int y2,
  94|  Draw_CopyPen* pen );
  95|#ifdef USES_SSTACK
  96|void  Draw_bezier( Draw*, int x1, int y1, int x2, int y2,
  97|              int x3, int y3, int x4, int y4, int color );
  98|void  Draw_bezierForXorPaint( Draw*, int x1, int y1, int x2, int y2,
  99|              int x3, int y3, int x4, int y4, int color );
 100|#endif  /* USES_SSTACK */
 101|void  Draw_rectFill( Draw*, int x1, int y1, int x2, int y2,
 102|  int color );
 103|
 104|#ifdef USES_THREED
 105|#ifdef USES_SCALE
 106|void  Draw_line3dP( Draw* draw, ThreeD_ViewL* viewp, Scale* scale,
 107|  ThreeD_XYZ* p1, ThreeD_XYZ* p2, int color );
 108|void  Draw_line3d( Draw* draw, ThreeD_ViewL* viewp, Scale* scale,
 109|  double x1, double y1, double z1,
 110|  double x2, double y2, double z2, int color );
 111|#endif /* USES_SCALE */
 112|#endif /* USES_THREED */
 113|
 114|#ifdef USES_THREED2
 115|#ifdef USES_SCALE3
 116|void  Draw_line3dP2( Draw* draw, ThreeD2_ViewL* viewp, Scale3* scale,
 117|  ThreeD2_XYZ* p1, ThreeD2_XYZ* p2, int color );
 118|void  Draw_line3d2( Draw* draw, ThreeD2_ViewL* viewp, Scale3* scale,
 119|  int x1, int y1, int z1,
 120|  int x2, int y2, int z2, int color );
 121|#endif /* USES_SCALE3 */
 122|#endif /* USES_THREED2 */
 123|
 124|
 125|/*** 文字などを描く ***/
 126|void  Draw_ascii( Draw*, int x, int y, char code, int color );
 127|void  Draw_jis( Draw*, int x, int y, unsigned short code, int color );
 128|#ifdef USES_MASK
 129|void  Draw_pattern( Draw*, int x, int y, char* pattern, int color );
 130|#endif
 131|
 132|/*** その他 ***/
 133|int  Draw_getDirec( int dx, int dy );
 134|
 135|
 136|/************************************************************************
 137|*  3. <<< 太いペン [Draw_Pen] >>>
 138|*************************************************************************/
 139|void  Draw_Pen_init(void);
 140|extern int*  Draw_Pen_maru[9];
 141|
 142|
 143|/************************************************************************
 144|*  4. <<< 線の種類 [Draw_BoldType] >>>
 145|*************************************************************************/
 146|#define  Draw_BoldType_Line   1
 147|#define  Draw_BoldType_Circle 2
 148|
 149|
 150|#ifdef USES_SCREEN
 151|/************************************************************************
 152|*  5. <<< コピーペン [Draw_CopyPen] >>>
 153|*【補足】
 154|*・別の画面に描かれている画像をコピーするように、図形を描画する
 155|*・拡大縮小はしない。あらかじめやっておくこと。
 156|*・dx,dy は、コピー元の(0,0)の位置に対応するコピー先の座標に等しい。
 157|*************************************************************************/
 158|struct _Draw_CopyPen {
 159|  Screen*  src;      /* コピー元の(ワーク)画面 */
 160|  int  dx, dy;       /* コピー先との座標の差分 */
 161|};
 162|#endif
 163|
 164|/*--------------------------------------------------------------------*/
 165|/*--- Mapping Area ---------------------------------------------------*/
 166|/*--------------------------------------------------------------------*/
 167|
 168|/************************************************************************
 169|*  6. <<< 初期化する [Draw_init()] >>>
 170|*【引数】
 171|*  ・DrawScr scr;  描画対象画面
 172|*【補足】
 173|*・scr は、Screen_inf_DrawScr( Screen* ) などの関数の返り値を指定します。
 174|*・Screen などの画面は、Draw にリンクされます。削除しないでください。
 175|*・void  Draw_init( Draw*, DrawScr scr ) に相当します。
 176|*************************************************************************/
 177|#define  Draw_init( this, s )   ((this)->drawScr = s)
 178|
 179|
 180|/************************************************************************
 181|*  7. <<< Draw のその他の関数 >>>
 182|*  8. <<< [Draw_getWidth()],[Draw_getHeight()],[Draw_clear()] >>>
 183|*  9. <<< [Draw_pset()],[Draw_psetXor()],[Draw_psets()] >>>
 184|*  10. <<< [Draw_xorPaint()] >>>
 185|*  11. <<< [Draw_flushTo()],[Draw_flushTo2()] >>>
 186|*  12. <<< [Draw_flushFromScreen()],[Draw_flushFromScreen2()] >>>
 187|*  13. <<< [Draw_flushFromDScreen()],[Draw_flushFromDScreen2()] >>>
 188|*************************************************************************/
 189|#define  Draw_getWidth( this ) \
 190|  DrawScr_getWidth( (this)->drawScr )
 191|#define  Draw_getHeight( this ) \
 192|  DrawScr_getHeight( (this)->drawScr )
 193|#define  Draw_clear( this, color ) \
 194|  DrawScr_clear( (this)->drawScr, color )
 195|#define  Draw_pset( this, x, y, color ) \
 196|  DrawScr_pset( (this)->drawScr, x, y, color )
 197|#define  Draw_psetXor( this, x, y, color ) \
 198|  DrawScr_psetXor( (this)->drawScr, x, y, color )
 199|#define  Draw_psets( this, x, y, pattern, nPixel, color ) \
 200|  DrawScr_psets( (this)->drawScr, x, y, pattern, nPixel, color )
 201|#define  Draw_xorPaint( this ) \
 202|  DrawScr_xorPaint( (this)->drawScr, this )
 203|#define  Draw_flushTo( this, target ) \
 204|  DrawScr_flushTo2( (this)->drawScr, (target)->drawScr, NULL, 0, 0, 0 )
 205|#define  Draw_flushTo2( this, target, mask, x, y, clipX ) \
 206|  DrawScr_flushTo2( (this)->drawScr, (target)->drawScr, mask, x, y, clipX )
 207|#define  Draw_flushFromScreen( this, work ) \
 208|  DrawScr_flushFromScreen2( (this)->drawScr, work, NULL, 0, 0, 0 )
 209|#define  Draw_flushFromScreen2( this, work, mask, x, y, clipX ) \
 210|  DrawScr_flushFromScreen2( (this)->drawScr, work, mask, x, y, clipX )
 211|#define  Draw_flushFromDScreen( this, work ) \
 212|  DrawScr_flushFromDScreen2( (this)->drawScr, work, NULL, 0, 0, 0 )
 213|#define  Draw_flushFromDScreen2( this, work, mask, x, y, clipX ) \
 214|  DrawScr_flushFromDScreen2( (this)->drawScr, work, mask, x, y, clipX )
 215|
 216|
 217|
 218|/*************************************************************************
 219|*  14. <<< ベクトル成分 dx,dy から方向番号を取得する [Draw_getDirec()] >>>
 220|*
 221|*  
 222|*
 223|*【引数】
 224|*  ・int  dx,dy;    方向ベクトルの x,y 成分
 225|*  ・int  ret;      方向番号(出力)
 226|*【補足】
 227|*・返り値は、全方向を8分割して、左上水平寄りの 0度〜 45度を0とします。
 228|*  以後、右回りに1〜7とします。(数学の一般角とは逆方向)
 229|*・この値は、|dx|(絶対値)と|dy| のうち、大きい方が dx なら、第1ビットが0、
 230|*  dy なら第1ビットが1になります。
 231|*・|dx|>|dy| の場合、dx がプラスなら第2ビットが0、マイナスなら1になり、
 232|*  dy がプラスなら第0ビットから第2ビットまでのうち値が1になっている数が
 233|*  奇数になります。
 234|*・|dx|<|dy| の場合、dy がプラスなら第2ビットが0、マイナスなら1になり、
 235|*  dx がプラスなら第0ビットから第2ビットまでのうち値が1になっている数が
 236|*  奇数になります。
 237|**************************************************************************/
 238|#define Draw_getDirec2( dx, dy, ret ) \
 239|{ \
 240|  register int dx2 = (dx); \
 241|  register int dy2 = (dy); \
 242|\
 243|  if ( dx2 > 0 ) { \
 244|    if ( dy2 < 0 ) { \
 245|      if ( dx2 > -dy2 )  ret = 0; \
 246|      else               ret = 7; \
 247|    } \
 248|    else { \
 249|      if ( dx2 > dy2 )  ret = 1; \
 250|      else              ret = 2; \
 251|    } \
 252|  } \
 253|  else { \
 254|    if ( dy2 < 0 ) { \
 255|      if ( dx2 < dy2 )  ret = 5; \
 256|      else              ret = 6; \
 257|    } \
 258|    else { \
 259|      if ( -dx2 > dy2 )  ret = 4; \
 260|      else               ret = 3; \
 261|    } \
 262|  } \
 263|}
 264|
 265|#ifdef __cplusplus
 266|}
 267|#endif
 268|
 269|#endif  /* __DRAW_H */
 270| 
 271|