matome.cpp

C:\home\SVGCats_src\src\matome.cpp

[大目次 | 目次 | 関数]

大目次

目次

関数一覧


   1|/***********************************************************************
   2|  1. <<< まとめ記号{ (Matome) >>> 
   3|************************************************************************/
   4|
   5|#include "mixer_precomp.h"  /* Auto precompiled header, Look at mixer-... folder */
   6|// #pragma hdrstop
   7|
   8|#if defined(USES_MXP_AUTOINC)
   9| #include "matome.ah"  /* Auto include header, Look at mixer-... folder */
  10|#endif
  11| 
  12|/*-------------------------------------------------------------------------*/
  13|/* 2. <<<< ◆ (Matome) まとめ記号{  >>>>  */ 
  14|/*-------------------------------------------------------------------------*/
  15| 
  16|Matome::Matome() 
  17|{
  18|  StdPlus_onMalloc( this );
  19|  m_bInUndoBuf = false;
  20|  m_bHold = false;
  21|  m_bSelected = false;
  22|}
  23|
  24|Matome::~Matome()
  25|{
  26|  StdPlus_onFree( this );
  27|}
  28|
  29|
  30| 
  31|/***********************************************************************
  32|  2-1. <<< [Matome::print] CadPrim::print の実装部 >>> 
  33|************************************************************************/
  34|void  Matome::print( const char* title )
  35|{
  36|#ifndef  ERRORS_CUT_DEBUG_TOOL
  37|  Errors_printf( "%sMatome[%d:%p], p1(%d,%d), p2(%d,%d)", title, m_id, this,
  38|    m_x1, m_y1, m_x2, m_y2 );
  39|#endif
  40|}
  41|
  42|
  43|/***********************************************************************
  44|  2-2. <<< [Matome::GetID] CadPrim::GetID の実装部 >>>
  45|************************************************************************/
  46|int  Matome::GetID()
  47|{
  48|  return  m_id;
  49|}
  50|
  51|
  52|/***********************************************************************
  53|  2-3. <<< [Matome::SetID] CadPrim::SetID の実装部 >>>
  54|************************************************************************/
  55|void  Matome::SetID( int id )
  56|{
  57|  m_id = id;
  58|}
  59|
  60|
  61|/***********************************************************************
  62|  2-4. <<< [Matome::GetTypeID] CadPrim::GetTypeID の実装部 >>>
  63|************************************************************************/
  64|int  Matome::GetTypeID()
  65|{
  66|  return  Matome_TypeID;
  67|}
  68|
  69|
  70|/***********************************************************************
  71|  2-5. <<< [Matome::GetTypeNameJp] CadPrim::GetTypeNameJp の実装部 >>>
  72|************************************************************************/
  73|char*  Matome::GetTypeNameJp()
  74|{
  75|  return  "まとめ線";
  76|}
  77|
  78|
  79|/***********************************************************************
  80|  2-6. <<< [Matome::GetTypeNameEn] CadPrim::GetTypeNameEn の実装部 >>>
  81|************************************************************************/
  82|char*  Matome::GetTypeNameEn()
  83|{
  84|  return  "Pack Line";
  85|}
  86|
  87|
  88|/***********************************************************************
  89|  2-7. <<< [Matome::SetBInUndoBuf] CadPrim::SetBInUndoBuf の実装部 >>>
  90|************************************************************************/
  91|void  Matome::SetBInUndoBuf( bool b )
  92|{
  93|  m_bInUndoBuf = b;
  94|}
  95|
  96|
  97|/***********************************************************************
  98|  2-8. <<< [Matome::GetLinkURL] CadPrim::GetLinkURL の実装部 >>>
  99|************************************************************************/
 100|char*  Matome::GetLinkURL()
 101|{
 102|  return  "";
 103|}
 104|
 105|
 106|/***********************************************************************
 107|  2-9. <<< [Matome::GetIdLabel] CadPrim::GetIdLabel の実装部 >>>
 108|************************************************************************/
 109|char*  Matome::GetIdLabel()
 110|{
 111|  return  "";
 112|}
 113|
 114|
 115| 
 116|/***********************************************************************
 117|  2-10. <<< [Matome::OutSVG] SVGファイルに属性値を出力する >>> 
 118|【引数】
 119|  ・FILE*   f;    出力先のテキスト・ファイル
 120|************************************************************************/
 121|void  Matome::OutSVG( CadPrim_SaveParam* p )
 122|{
 123|  int  dx = m_x2 - m_x1;
 124|  int  dy = m_y2 - m_y1;
 125|  int  adx = abs(dx);
 126|  int  ady = abs(dy);
 127|  int  sx = (m_x2 > m_x1) ? +1 : -1;  /* 符号 */
 128|  int  sy = (m_y2 > m_y1) ? +1 : -1;
 129|  int  hx = (m_x1 + m_x2) / 2;  /* 中点 */
 130|  int  hy = (m_y1 + m_y2) / 2;
 131|
 132|  /* <path> タグをファイルに出力する */
 133|  /* d="Mx1,y1 Arx,ry angle bLongCourse,bRightCurve x2,y2" */
 134|  fprintf( p->f, "\t<path subtype=\"matome\" " );
 135|  if ( adx > ady ) {
 136|    fprintf( p->f, "d=\"M%d.5,%d.5 A%d,%d 0 0,%d %d.5,%d.5 ",
 137|      m_x1, m_y2,  ady/2, ady/2,  (sx==sy),  m_x1+sx*ady/2, hy );
 138|    fprintf( p->f, "L%d.5,%d.5 A%d,%d, 0 0,%d, %d.5,%d.5 ",
 139|      hx-sx*ady/2, hy,  ady/2, ady/2,  (sx!=sy),  hx, m_y1 );
 140|    fprintf( p->f, "A%d,%d, 0 0,%d, %d.5,%d.5 ",
 141|      ady/2, ady/2,  (sx!=sy),  hx+sx*ady/2, hy );
 142|    fprintf( p->f, "L%d.5,%d.5 A%d,%d, 0 0,%d, %d.5,%d.5\"\n",
 143|      m_x2-sx*ady/2, hy,  ady/2, ady/2,  (sx==sy),  m_x2, m_y2 );
 144|  }
 145|  else {
 146|    fprintf( p->f, "d=\"M%d.5,%d.5 A%d,%d 0 0,%d %d.5,%d.5 ",
 147|      m_x2, m_y1, adx/2,adx/2,  (sx!=sy), hx, m_y1+sy*adx/2 );
 148|    fprintf( p->f, "L%d.5,%d.5 A%d,%d, 0 0,%d, %d.5,%d.5 ",
 149|      hx, hy-sy*adx/2,  adx/2, adx/2,  (sx==sy),  m_x1, hy );
 150|    fprintf( p->f, "A%d,%d, 0 0,%d, %d.5,%d.5 ",
 151|      adx/2, adx/2,  (sx==sy),  hx, hy+sy*adx/2 );
 152|    fprintf( p->f, "L%d.5,%d.5 A%d,%d, 0 0,%d, %d.5,%d.5\"\n",
 153|      hx, m_y2-sy*adx/2,  adx/2, adx/2,  (sx!=sy),  m_x2, m_y2 );
 154|  }
 155|
 156|  fprintf( p->f, "\t\tstyle=\"fill:none;stroke:rgb(%d,%d,%d);stroke-width:%d\"/>\n",
 157|    Color_WinRGB_getR( m_BorderColor ), Color_WinRGB_getG( m_BorderColor ),
 158|    Color_WinRGB_getB( m_BorderColor ),
 159|    m_BorderWidth );
 160|}
 161|
 162| 
 163|/***********************************************************************
 164|  2-11. <<< [Matome::Draw] 矩形を描画する >>> 
 165|【引数】
 166|  ・CDC*    dc;    デバイスコンテキスト
 167|************************************************************************/
 168|void  Matome::Draw( CDC* dc, CadPrim_DrawParam* p )
 169|{
 170|  int  zoom = p->zoom;
 171|  int  x1 = m_x1 * zoom / 100 - p->x0;
 172|  int  y1 = m_y1 * zoom / 100 - p->y0;
 173|  int  x2 = m_x2 * zoom / 100 - p->x0;
 174|  int  y2 = m_y2 * zoom / 100 - p->y0;
 175|  int  dx = x2 - x1;
 176|  int  dy = y2 - y1;
 177|  int  adx = abs(dx);
 178|  int  ady = abs(dy);
 179|  int  sx = (x2 > x1) ? +1 : -1;  /* 符号 */
 180|  int  sy = (y2 > y1) ? +1 : -1;
 181|  int  hx = (x1 + x2) / 2;  /* 中点 */
 182|  int  hy = (y1 + y2) / 2;
 183|
 184|  CPen     pen( PS_SOLID, m_BorderWidth * zoom / 100,
 185|    p->bWhiteToBGColor && m_BorderColor == 0x000000 ?
 186|    GetSysColor( COLOR_WINDOWTEXT ) : m_BorderColor );
 187|  CPen*    oldPen;
 188|
 189|  oldPen = (CPen*)dc->SelectObject( &pen );
 190|
 191|  if ( adx > ady ) {
 192|    if (dy>0) dc->Arc( x1-(dx<0?ady:0), hy,  x1+(dx>0?ady:0), y2+ady/2,  x1+sx*ady/2, hy,  x1, y2 );
 193|    else      dc->Arc( x1-(dx<0?ady:0), y2-ady/2,  x1+(dx>0?ady:0), hy,  x1, y2,  x1+sx*ady/2, hy );
 194|    dc->MoveTo( x1+sx*ady/2-1, hy );  dc->LineTo( hx-sx*ady/2+1, hy );
 195|    if (dy>0) dc->Arc( hx-sx*ady, y1-ady/2,  hx,hy,  hx-sx*ady/2,hy,  hx, y1  );
 196|    else      dc->Arc( hx-sx*ady, hy, hx, y1+ady/2,  hx, y1,  hx-sx*ady/2,hy  );
 197|    if (dy>0) dc->Arc( hx, y1-ady/2,  hx+sx*ady,hy,  hx, y1,  hx+sx*ady/2, hy );
 198|    else      dc->Arc( hx, hy, hx+sx*ady, y1+ady/2,  hx+sx*ady/2, hy,  hx, y1 );
 199|    dc->MoveTo( hx+sx*ady/2-1, hy );  dc->LineTo( x2-sx*ady/2+1, hy );
 200|    if (dy>0) dc->Arc( x2-sx*ady, hy,  x2, y2+ady/2,  x2, y2,  x2-sx*ady/2, hy );
 201|    else      dc->Arc( x2-sx*ady, y2-ady/2,  x2, hy,  x2-sx*ady/2, hy,  x2, y2 );
 202|  }
 203|  else {
 204|    if (dx>0) dc->Arc( hx, y1-(dy<0?adx:0),  x2+adx/2, y1+(dy>0?adx:0),  x2, y1,  hx, y1+sy*adx/2 );
 205|    else      dc->Arc( x2-adx/2, y1-(dy<0?adx:0),  hx, y1+(dy>0?adx:0),  hx, y1+sy*adx/2,  x2, y1 );
 206|    dc->MoveTo( hx, y1+sy*adx/2-1 );  dc->LineTo( hx, hy-sy*adx/2+1 );
 207|    if (dx>0) dc->Arc( x1-adx/2, hy-(dy>0?adx:0),  hx, hy+(dy<0?adx:0),  x1, hy,  hx, hy-sy*adx/2  );
 208|    else      dc->Arc( hx, hy-(dy>0?adx:0),  x1+adx/2, hy+(dy<0?adx:0),  hx, hy-sy*adx/2,  x1, hy  );
 209|    if (dx>0) dc->Arc( x1-adx/2, hy-(dy<0?adx:0),  hx, hy+(dy>0?adx:0),  hx, hy+sy*adx/2,  x1, hy );
 210|    else      dc->Arc( hx, hy-(dy<0?adx:0),  x1+adx/2, hy+(dy>0?adx:0),  x1, hy,  hx, hy+sy*adx/2 );
 211|    dc->MoveTo( hx, hy+sy*adx/2-1 );  dc->LineTo( hx, y2-sy*adx/2+1 );
 212|    if (dx>0) dc->Arc( hx, y2-(dy>0?adx:0),  x2+adx/2, y2+(dy<0?adx:0),  hx, y2-sy*adx/2,  x2, y2 );
 213|    else      dc->Arc( x2-adx/2, y2-(dy>0?adx:0),  hx, y2+(dy<0?adx:0),  x2, y2 ,  hx, y2-sy*adx/2);
 214|  }
 215|
 216|  dc->SelectObject( oldPen );
 217|
 218|  if ( m_bHold && p->bDrawHandle )
 219|    DrawHandles( dc, p, ~GetSysColor( COLOR_HIGHLIGHT ) & 0xFFFFFF, false );
 220|}
 221|
 222|
 223| 
 224|/***********************************************************************
 225|  2-12. <<< [Matome::DrawHandles] 全ハンドルを描画する >>> 
 226|【引数】
 227|  ・CDC*    dc;      デバイスコンテキスト
 228|  ・int     color;   ハンドルの色
 229|************************************************************************/
 230|void  Matome::DrawHandles( CDC* dc, CadPrim_DrawParam* p, COLORREF color,
 231|  bool bDrawFrame )
 232|{
 233|  CPen     pen( PS_SOLID, 1, color ^ 0xFFFFFF );
 234|  CBrush   brush( color );
 235|  CPen*    oldPen;
 236|  CBrush*  oldBrush;
 237|  int  zoom = p->zoom;
 238|  int  x1 = m_x1 * zoom / 100 - p->x0;
 239|  int  y1 = m_y1 * zoom / 100 - p->y0;
 240|  int  x2 = m_x2 * zoom / 100 - p->x0;
 241|  int  y2 = m_y2 * zoom / 100 - p->y0;
 242|  int  hx = (x1 + x2) / 2;
 243|  int  hy = (y1 + y2) / 2;
 244|
 245|  oldPen = dc->SelectObject( &pen );
 246|  oldBrush = dc->SelectObject( &brush );
 247|
 248|  dc->Rectangle( x1 - 3, y1 - 3, x1 + 3, y1 + 3 );
 249|  dc->Rectangle( hx - 3, y1 - 3, hx + 3, y1 + 3 );
 250|  dc->Rectangle( x2 - 3, y1 - 3, x2 + 3, y1 + 3 );
 251|  dc->Rectangle( x1 - 3, hy - 3, x1 + 3, hy + 3 );
 252|  dc->Rectangle( x2 - 3, hy - 3, x2 + 3, hy + 3 );
 253|  dc->Rectangle( x1 - 3, y2 - 3, x1 + 3, y2 + 3 );
 254|  dc->Rectangle( hx - 3, y2 - 3, hx + 3, y2 + 3 );
 255|  dc->Rectangle( x2 - 3, y2 - 3, x2 + 3, y2 + 3 );
 256|
 257|  dc->SelectObject( oldBrush );
 258|  dc->SelectObject( oldPen );
 259|}
 260|
 261| 
 262|/***********************************************************************
 263|  2-13. <<< [Matome::copy] CadPrim::copy の実装部 >>> 
 264|************************************************************************/
 265|void  Matome::copy( CadPrim* a, ListX* prims )
 266|{
 267|  Matome*  r = (Matome*)a;
 268|
 269|  m_id = r->m_id;
 270|  m_x1 = r->m_x1;
 271|  m_y1 = r->m_y1;
 272|  m_x2 = r->m_x2;
 273|  m_y2 = r->m_y2;
 274|  m_BorderWidth = r->m_BorderWidth;
 275|  m_BorderColor = r->m_BorderColor;
 276|}
 277|
 278|/***********************************************************************
 279|  2-14. <<< [Matome::copyStyle] CadPrim::copyStyle の実装部 >>>
 280|************************************************************************/
 281|void  Matome::copyStyle( CadPrim* a, ListX* prims )
 282|{
 283|  Matome*  r = (Matome*)a;
 284|
 285|  m_BorderWidth = r->m_BorderWidth;
 286|  m_BorderColor = r->m_BorderColor;
 287|}
 288|
 289|/***********************************************************************
 290|  2-15. <<< [Matome::isEqual] CadPrim::isEqual の実装部 >>>
 291|************************************************************************/
 292|bool  Matome::isEqual( CadPrim* a )
 293|{
 294|  Matome*  r = (Matome*)a;
 295|
 296|  return (
 297|    a->GetTypeID() == Matome_TypeID &&
 298|    m_id == r->m_id &&
 299|    m_x1 == r->m_x1 &&
 300|    m_y1 == r->m_y1 &&
 301|    m_x2 == r->m_x2 &&
 302|    m_y2 == r->m_y2 &&
 303|    m_BorderWidth == r->m_BorderWidth &&
 304|    m_BorderColor == r->m_BorderColor );
 305|}
 306|
 307|/***********************************************************************
 308|  2-16. <<< [Matome::GetNewCopy] CadPrim::GetNewCopy の実装部 >>>
 309|************************************************************************/
 310|CadPrim*  Matome::GetNewCopy( ListX* prims )
 311|{
 312|  Matome*  r = new Matome;
 313|
 314|  r->copy( this, prims );
 315|  return  r;
 316|}
 317|
 318|
 319|/***********************************************************************
 320|  2-17. <<< [Matome::GetSerializedSize] CadPrim::GetSerializedSize の実装部 >>>
 321|************************************************************************/
 322|int  Matome::GetSerializedSize()
 323|{
 324|  return  ( sizeof(*this) + 3 ) & ~3;
 325|}
 326|
 327|
 328|/***********************************************************************
 329|  2-18. <<< [Matome::CopyToSerial] CadPrim::CopyToSerial の実装部 >>>
 330|************************************************************************/
 331|void  Matome::CopyToSerial( void* a )
 332|{
 333|  Matome*  r = (Matome*)a;
 334|
 335|  r->m_id = m_id;
 336|  r->m_x1 = m_x1;
 337|  r->m_y1 = m_y1;
 338|  r->m_x2 = m_x2;
 339|  r->m_y2 = m_y2;
 340|  r->m_BorderWidth = m_BorderWidth;
 341|  r->m_BorderColor = m_BorderColor;
 342|}
 343|
 344|
 345|/***********************************************************************
 346|  2-19. <<< [Matome::CopyFromSerial] CadPrim::CopyFromSerial の実装部 >>>
 347|************************************************************************/
 348|void  Matome::CopyFromSerial( void* a )
 349|{
 350|  Matome*  r = (Matome*)a;
 351|
 352|  m_id = r->m_id;
 353|  m_x1 = r->m_x1;
 354|  m_y1 = r->m_y1;
 355|  m_x2 = r->m_x2;
 356|  m_y2 = r->m_y2;
 357|  m_BorderWidth = r->m_BorderWidth;
 358|  m_BorderColor = r->m_BorderColor;
 359|}
 360|
 361|
 362| 
 363|/***********************************************************************
 364|  2-20. <<< [Matome::GetHitHandleNum] Rect_getHitHandleNum の C++ ラップ >>> 
 365|************************************************************************/
 366|int  Matome::GetHitHandleNum( int x, int y, int zoom, int mode,
 367|  int* dx, int* dy, int* diff, int* arrow )
 368|{
 369|  int  r;
 370|  int  x1 = m_x1;
 371|  int  y1 = m_y1;
 372|  int  x2 = m_x2;
 373|  int  y2 = m_y2;
 374|  int  hx = (x1 + x2) / 2;
 375|  int  hy = (y1 + y2) / 2;
 376|  enum { d = 5 };
 377|
 378|  if ( x1 - d <= x && x <= x1 + d )  { r = 1;  *dx = x1 - x; }
 379|  else if ( hx - d <= x && x <= hx + d )  { r = 2;  *dx = hx - x; }
 380|  else if ( x2 - d <= x && x <= x2 + d )  { r = 3;  *dx = x2 - x; }
 381|  else  r = 0;
 382|
 383|  if ( r != 0 ) {
 384|    if ( y1 - d <= y && y <= y1 + d )    *dy = y1 - y;
 385|    else if ( hy - d <= y && y <= hy + d )  { r += 3;  *dy = hy - y; }
 386|    else if ( y2 - d <= y && y <= y2 + d )  { r += 6;  *dy = y2 - y; }
 387|    else  r = 0;
 388|  }
 389|
 390|  if ( r == 0 || r == 5 ) {
 391|    int  adx = abs(x1 - x2);
 392|    int  ady = abs(y1 - y2);
 393|    int  a1, a2;
 394|
 395|    if ( adx > ady ) {
 396|      if ( hy - d <= y && y <= hy + d ) {
 397|        if ( x1 < x2 )  { a1 = x1;  a2 = x2; }
 398|        else            { a1 = x2;  a2 = x1; }
 399|        if ( a1 + ady/2 - d <= x && x <= a2 - ady/2 + d ) {
 400|          r = -1;  *diff = y - hy;
 401|          *dx = m_x1 - x;  *dy = m_y1 - y;
 402|          *arrow = CadPrim_MovableArrow;
 403|        }
 404|      }
 405|    }
 406|    else {
 407|      if ( hx - d <= x && x <= hx + d ) {
 408|        if ( y1 < y2 )  { a1 = y1;  a2 = y2; }
 409|        else            { a1 = y2;  a2 = y1; }
 410|        if ( a1 + adx/2 - d <= y && y <= a2 - adx/2 + d ) {
 411|          r = -1;  *diff = x - hx;
 412|          *dx = m_x1 - x;  *dy = m_y1 - y;
 413|          *arrow = CadPrim_MovableArrow;
 414|        }
 415|      }
 416|    }
 417|  }
 418|  else {
 419|    if ( r == 5 )  return  0;
 420|    else if ( r >= 6 )  r--;
 421|
 422|    *diff = abs(*dx) + abs(*dy);
 423|    switch ( r ) {
 424|      case 1:  *arrow = CadPrim_RightDownArrow;  break;
 425|      case 2:  *arrow = CadPrim_VerticalArrow;  break;
 426|      case 3:  *arrow = CadPrim_RightUpArrow;  break;
 427|      case 4:  *arrow = CadPrim_HorizontalArrow;  break;
 428|      case 5:  *arrow = CadPrim_HorizontalArrow;  break;
 429|      case 6:  *arrow = CadPrim_RightUpArrow;  break;
 430|      case 7:  *arrow = CadPrim_VerticalArrow;  break;
 431|      case 8:  *arrow = CadPrim_RightDownArrow;  break;
 432|    }
 433|  }
 434|
 435|  return  r;
 436|}
 437|
 438|
 439|/***********************************************************************
 440|  2-21. <<< [Matome::Move] CadPrim::Move の実装部 >>>
 441|************************************************************************/
 442|void  Matome::Move( int dx, int dy )
 443|{
 444|  m_x1 += dx;  m_y1 += dy;
 445|  m_x2 += dx;  m_y2 += dy;
 446|}
 447|
 448|
 449|/***********************************************************************
 450|  2-22. <<< [Matome::MoveByHandle] CadPrim::MoveByHandle の実装部 >>>
 451|************************************************************************/
 452|void  Matome::MoveByHandle( int iHandle, int x, int y, bool bShift, bool bRotate )
 453|{
 454|  switch ( iHandle ) {
 455|    case  1:  m_x1 = x;  m_y1 = y;  break;
 456|    case  2:             m_y1 = y;  break;
 457|    case  3:  m_x2 = x;  m_y1 = y;  break;
 458|    case  4:  m_x1 = x;             break;
 459|    case  5:  m_x2 = x;             break;
 460|    case  6:  m_x1 = x;  m_y2 = y;  break;
 461|    case  7:             m_y2 = y;  break;
 462|    case  8:  m_x2 = x;  m_y2 = y;  break;
 463|    case  -1:  Move( x - m_x1,  y - m_y1 );  break;
 464|  }
 465|}
 466|
 467|
 468|/***********************************************************************
 469|  2-23. <<< [Matome::GetCenterOfHandle] CadPrim::GetCenterOfHandle の実装部 >>>
 470|************************************************************************/
 471|void  Matome::GetCenterOfHandle( int iHandle, int* x, int* y )
 472|{
 473|  switch ( iHandle ) {
 474|    case 1:  *x = m_x1;               *y = m_y1;  break;
 475|    case 2:  *x = (m_x1 + m_x2) / 2;  *y = m_y1;  break;
 476|    case 3:  *x = m_x2;               *y = m_y1;  break;
 477|    case 4:  *x = m_x1;               *y = (m_y1 + m_y2) / 2;  break;
 478|    case 5:  *x = m_x2;               *y = (m_y1 + m_y2) / 2;  break;
 479|    case 6:  *x = m_x1;               *y = m_y2;  break;
 480|    case 7:  *x = (m_x1 + m_x2) / 2;  *y = m_y2;  break;
 481|    case 8:  *x = m_x2;               *y = m_y2;  break;
 482|  }
 483|}
 484|
 485| 
 486|/***********************************************************************
 487|  2-24. <<< [Matome::SetHold] CadPrim::SetHold の実装部 >>> 
 488|************************************************************************/
 489|void  Matome::SetHold( bool b )
 490|{
 491|  m_bHold = b;
 492|}
 493|
 494|/***********************************************************************
 495|  2-25. <<< [Matome::GetHold] CadPrim::GetHold の実装部 >>>
 496|************************************************************************/
 497|bool  Matome::GetHold()
 498|{
 499|  return  m_bHold;
 500|}
 501|
 502|/***********************************************************************
 503|  2-26. <<< [Matome::IsHoldable] CadPrim::IsHoldable の実装部 >>>
 504|************************************************************************/
 505|bool  Matome::IsHoldable()
 506|{
 507|  return  true;
 508|}
 509|
 510|/***********************************************************************
 511|  2-27. <<< [Matome::SetSelected] CadPrim::SetSelected の実装部 >>>
 512|************************************************************************/
 513|void  Matome::SetSelected( bool b )
 514|{
 515|  m_bSelected = b;
 516|}
 517|
 518|/***********************************************************************
 519|  2-28. <<< [Matome::GetSelected] CadPrim::GetSelected の実装部 >>>
 520|************************************************************************/
 521|bool  Matome::GetSelected()
 522|{
 523|  return  m_bSelected;
 524|}
 525|
 526| 
 527|/***********************************************************************
 528|  2-29. <<< [Matome::IsMultiSelect] CadPrim::IsMultiSelect の実装部 >>> 
 529|************************************************************************/
 530|bool  Matome::IsMultiSelect( Rect* rect )
 531|{
 532|  Rect  m;
 533|  Rect  com;
 534|
 535|  if ( m_x1 < m_x2 )  { m.x = m_x1;  m.w = m_x2 - m_x1 + 1; }
 536|  else  { m.x = m_x2;  m.w = m_x1 - m_x2 + 1; }
 537|
 538|  if ( m_y1 < m_y2 )  { m.y = m_y1;  m.h = m_y2 - m_y1 + 1; }
 539|  else  { m.y = m_y2;  m.h = m_y1 - m_y2 + 1; }
 540|
 541|  Rect_toAnd( &com, &m, rect );
 542|  return  ( com.w > 0 && com.h > 0 );
 543|}
 544|
 545|
 546|/***********************************************************************
 547|  2-30. <<< [Matome::GetForAlign] CadPrim::GetForAlign の実装部 >>>
 548|************************************************************************/
 549|int   Matome::GetForAlign( int iPos )
 550|{
 551|  switch ( iPos ) {
 552|    case  CadPrim_AlignLeft:    return  ( m_x1 < m_x2 ) ? m_x1 : m_x2;
 553|    case  CadPrim_AlignRight:   return  ( m_x1 < m_x2 ) ? m_x2 : m_x1;
 554|    case  CadPrim_AlignTop:     return  ( m_y1 < m_y2 ) ? m_y1 : m_y2;
 555|    case  CadPrim_AlignBottom:  return  ( m_y1 < m_y2 ) ? m_y2 : m_y1;
 556|    case  CadPrim_AlignVertical:    return  (m_x1 + m_x2) / 2;
 557|    case  CadPrim_AlignHorizontal:  return  (m_y1 + m_y2) / 2;
 558|    default:  error();  return  0;
 559|  }
 560|}
 561|
 562|/***********************************************************************
 563|  2-31. <<< [Matome::SetForAlign] CadPrim::SetForAlign の実装部 >>>
 564|************************************************************************/
 565|void  Matome::SetForAlign( int iPos, int value )
 566|{
 567|  int  d;
 568|
 569|  switch ( iPos ) {
 570|    case  CadPrim_AlignLeft:    m_x2 += value - m_x1;   m_x1 = value;  break;
 571|    case  CadPrim_AlignRight:   m_x1 += value - m_x2;   m_x2 = value;  break;
 572|    case  CadPrim_AlignTop:     m_y2 += value - m_y1;   m_y1 = value;  break;
 573|    case  CadPrim_AlignBottom:  m_y1 += value - m_y2;   m_y2 = value;  break;
 574|    case  CadPrim_AlignVertical:    d = value - (m_x1+m_x2)/2;  m_x1+=d;  m_x2+=d;  break;
 575|    case  CadPrim_AlignHorizontal:  d = value - (m_y1+m_y2)/2;  m_y1+=d;  m_y2+=d;  break;
 576|    default:  error();
 577|  }
 578|}
 579|
 580|/***********************************************************************
 581|  2-32. <<< [Matome::GetForFitSize] CadPrim::GetForFitSize の実装部 >>>
 582|************************************************************************/
 583|int   Matome::GetForFitSize( int iAttr )
 584|{
 585|  if ( iAttr == CadPrim_Horizontal )  return  abs(m_x1 - m_x2) + 1;
 586|  else  return  abs(m_y1 - m_y2) + 1;
 587|}
 588|
 589|/***********************************************************************
 590|  2-33. <<< [Matome::SetForFitSize] CadPrim::SetForFitSize の実装部 >>>
 591|************************************************************************/
 592|void  Matome::SetForFitSize( int iAttr, int value )
 593|{
 594|  if ( iAttr == CadPrim_Horizontal ) {
 595|    if ( m_x1 < m_x2 )  { m_x1 += value - abs(m_x1 - m_x2) + 1;  m_x2 = m_x1 + value - 1; }
 596|    else  { m_x2 += value - abs(m_x1 - m_x2) + 1;  m_x1 = m_x2 + value - 1; }
 597|  }
 598|  else {
 599|    if ( m_y1 < m_y2 )  { m_y1 += value - abs(m_y1 - m_y2) + 1;  m_y2 = m_y1 + value - 1; }
 600|    else  { m_y2 += value - abs(m_y1 - m_y2) + 1;  m_y1 = m_y2 + value - 1; }
 601|  }
 602|}
 603| 
 604|/***********************************************************************
 605|  2-34. <<< [Matome::OnCreated] CadPrim::OnCreated の実装部 >>> 
 606|************************************************************************/
 607|void  Matome::OnCreated()
 608|{
 609|  if ( abs(m_x1 - m_x2) <= 4 && abs(m_y1 - m_y2) <= 4 ) {
 610|    m_x2 = m_x1 + 4;  m_y2 = m_y1 + 32;
 611|  }
 612|}
 613|
 614| 
 615|/***********************************************************************
 616|  2-35. <<< [Matome::GetNProp] プロパティの要素数を返す >>> 
 617|************************************************************************/
 618|int  Matome::GetNProp()
 619|{
 620|  #ifdef  NDEBUG
 621|    return  6;
 622|  #else
 623|    return  7;
 624|  #endif
 625|}
 626|
 627|
 628|/***********************************************************************
 629|  2-36. <<< [Matome::GetProp] プロパティの名前と値を取得する >>>
 630|************************************************************************/
 631|int  Matome::GetProp( int iProp, bool bJapanese, char* name, int name_size,
 632|  char* value, int value_size, const char* path, void** option )
 633|{
 634|  int  r = CadPrim_ReadOnly;
 635|  static int  range[2];
 636|
 637|  switch ( iProp ) {
 638|    case 0:
 639|      strncpy( name, "x1", name_size );
 640|      sprintf( value, "%d", m_x1 );
 641|      range[0] = INT_MIN;  range[1] = INT_MAX;
 642|      *option = range;
 643|      r = CadPrim_Int;
 644|      break;
 645|    case 1:
 646|      strncpy( name, "y1", name_size );
 647|      sprintf( value, "%d", m_y1 );
 648|      range[0] = INT_MIN;  range[1] = INT_MAX;
 649|      *option = range;
 650|      r = CadPrim_Int;
 651|      break;
 652|    case 2:
 653|      strncpy( name, "x2", name_size );
 654|      sprintf( value, "%d", m_x2 );
 655|      range[0] = INT_MIN;  range[1] = INT_MAX;
 656|      *option = range;
 657|      r = CadPrim_Int;
 658|      break;
 659|    case 3:
 660|      strncpy( name, "y2", name_size );
 661|      sprintf( value, "%d", m_y2 );
 662|      range[0] = INT_MIN;  range[1] = INT_MAX;
 663|      *option = range;
 664|      r = CadPrim_Int;
 665|      break;
 666|    case 4:
 667|      if ( bJapanese )
 668|        strncpy( name, "線幅", name_size );
 669|      else
 670|        strncpy( name, "Line Width", name_size );
 671|      sprintf( value, "%d", m_BorderWidth );
 672|      range[0] = 1;  range[1] = INT_MAX;
 673|      *option = range;
 674|      r = CadPrim_Int;
 675|      break;
 676|    case 5:
 677|      if ( bJapanese )
 678|        strncpy( name, "色", name_size );
 679|      else
 680|        strncpy( name, "Color", name_size );
 681|      StrX_getColorStr( value, m_BorderColor );
 682|      r = CadPrim_Color;
 683|      break;
 684|   #ifndef NDEBUG
 685|    case 6:
 686|      strncpy( name, "id", name_size );
 687|      sprintf( value, "%d", m_id );
 688|      break;
 689|   #endif
 690|  }
 691|
 692|  return  r;
 693|}
 694|
 695|/***********************************************************************
 696|  2-37. <<< [Matome::SetProp] プロパティの値を設定する >>>
 697|************************************************************************/
 698|void  Matome::SetProp( int iProp, const char* value, const char* path )
 699|{
 700|  switch ( iProp ) {
 701|    case 0:
 702|      m_x1 = atoi( value );
 703|      break;
 704|    case 1:
 705|      m_y1 = atoi( value );
 706|      break;
 707|    case 2:
 708|      m_x2 = atoi( value );
 709|      break;
 710|    case 3:
 711|      m_y2 = atoi( value );
 712|      break;
 713|    case 4:
 714|      m_BorderWidth = atoi( value );
 715|      break;
 716|    case 5:
 717|      m_BorderColor = StrX_getColorValue( value );
 718|      break;
 719|  }
 720|}
 721| 
 722|/***********************************************************************
 723|  2-38. <<< [Matome::IsNeedUnicode] CadPrim::IsNeedUnicode の実装部 >>> 
 724|************************************************************************/
 725|bool  Matome::IsNeedUnicode()
 726|{
 727|  return  false;
 728|}
 729|
 730| 
 731|
 732| 
 733|