⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawn.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 5 页
字号:
              (double)(record->param3 - record->param1),
              (double)(record->param4 - record->param2), (double)record->param5);
        m_ops.Append(op);
        break;
      }
//      case META_PATBLT:
//      case META_SAVEDC:
      case META_SETPIXEL:
      {
        wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_POINT,
              (double)record->param1, (double)record->param2,
              0.0, 0.0);

//        SHOULD SET THE COLOUR - SET PEN?
//        rec->param3 = getint(handle);   // COLORREF
        m_ops.Append(op);
        break;
      }
//      case META_OFFSETCLIPRGN:
      case META_TEXTOUT:
      {
        wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_TEXT,
              (double)record->param1, (double)record->param2,
              0.0, 0.0, 0.0, record->stringParam);
        m_ops.Append(op);
        break;
      }
//      case META_BITBLT:
//      case META_STRETCHBLT:
      case META_POLYGON:
      {
        int n = (int)record->param1;
        wxRealPoint *newPoints = new wxRealPoint[n];
        for (int i = 0; i < n; i++)
        {
          newPoints[i].x = record->points[i].x;
          newPoints[i].y = record->points[i].y;
        }

        wxOpPolyDraw *op = new wxOpPolyDraw(DRAWOP_DRAW_POLYGON, n, newPoints);
        m_ops.Append(op);
        break;
      }
      case META_POLYLINE:
      {
        int n = (int)record->param1;
        wxRealPoint *newPoints = new wxRealPoint[n];
        for (int i = 0; i < n; i++)
        {
          newPoints[i].x = record->points[i].x;
          newPoints[i].y = record->points[i].y;
        }

        wxOpPolyDraw *op = new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE, n, newPoints);
        m_ops.Append(op);
        break;
      }
//      case META_ESCAPE:
//      case META_RESTOREDC:
//      case META_FILLREGION:
//      case META_FRAMEREGION:
//      case META_INVERTREGION:
//      case META_PAINTREGION:
//      case META_SELECTCLIPREGION: // DO THIS!
      case META_SELECTOBJECT:
      {
        // The pen, brush etc. has already been created when the metafile
        // was read in, so we don't create it - we set it.
        wxNode *recNode = metaFile->gdiObjects.Item((int)record->param2);
        if (recNode)
        {
          wxMetaRecord *gdiRec = (wxMetaRecord *)recNode->GetData();
          if (gdiRec && (gdiRec->param1 != 0))
          {
            wxObject *obj = (wxObject *)gdiRec->param1;
            if (obj->IsKindOf(CLASSINFO(wxPen)))
            {
              wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_PEN, this, (int)record->param2);
              m_ops.Append(op);
            }
            else if (obj->IsKindOf(CLASSINFO(wxBrush)))
            {
              wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_BRUSH, this, (int)record->param2);
              m_ops.Append(op);
            }
            else if (obj->IsKindOf(CLASSINFO(wxFont)))
            {
              wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_FONT, this, (int)record->param2);
              m_ops.Append(op);
            }
          }
        }
        break;
      }
//      case META_SETTEXTALIGN:
//      case META_DRAWTEXT:
//      case META_CHORD:
//      case META_SETMAPPERFLAGS:
//      case META_EXTTEXTOUT:
//      case META_SETDIBTODEV:
//      case META_SELECTPALETTE:
//      case META_REALIZEPALETTE:
//      case META_ANIMATEPALETTE:
//      case META_SETPALENTRIES:
//      case META_POLYPOLYGON:
//      case META_RESIZEPALETTE:
//      case META_DIBBITBLT:
//      case META_DIBSTRETCHBLT:
      case META_DIBCREATEPATTERNBRUSH:
      {
        // Place holder
        m_gdiObjects.Append(NULL);
        break;
      }
//      case META_STRETCHDIB:
//      case META_EXTFLOODFILL:
//      case META_RESETDC:
//      case META_STARTDOC:
//      case META_STARTPAGE:
//      case META_ENDPAGE:
//      case META_ABORTDOC:
//      case META_ENDDOC:
//      case META_DELETEOBJECT: // DO!!
      case META_CREATEPALETTE:
      {
        // Place holder
        m_gdiObjects.Append(NULL);
        break;
      }
      case META_CREATEBRUSH:
      {
        // Place holder
        m_gdiObjects.Append(NULL);
        break;
      }
      case META_CREATEPATTERNBRUSH:
      {
        // Place holder
        m_gdiObjects.Append(NULL);
        break;
      }
      case META_CREATEPENINDIRECT:
      {
        // The pen is created when the metafile is read in.
        // We keep track of all the GDI objects needed for this
        // image so when reading the wxDrawnShape from file,
        // we can read in all the GDI objects, then refer
        // to them by an index starting from zero thereafter.
        m_gdiObjects.Append((wxObject *)record->param1);
        break;
      }
      case META_CREATEFONTINDIRECT:
      {
        m_gdiObjects.Append((wxObject *)record->param1);
        break;
      }
      case META_CREATEBRUSHINDIRECT:
      {
        // Don't have to do anything here: the pen is created
        // when the metafile is read in.
        m_gdiObjects.Append((wxObject *)record->param1);
        break;
      }
      case META_CREATEBITMAPINDIRECT:
      {
        // Place holder
        m_gdiObjects.Append(NULL);
        break;
      }
      case META_CREATEBITMAP:
      {
        // Place holder
        m_gdiObjects.Append(NULL);
        break;
      }
      case META_CREATEREGION:
      {
        // Place holder
        m_gdiObjects.Append(NULL);
        break;
      }
      default:
      {
        break;
      }
    }
    node = node->GetNext();
  }
  double actualWidth = (double)fabs(metaFile->right - metaFile->left);
  double actualHeight = (double)fabs(metaFile->bottom - metaFile->top);

  double initialScaleX = 1.0;
  double initialScaleY = 1.0;

  double xoffset, yoffset;

  // Translate so origin is at centre of rectangle
  if (metaFile->bottom > metaFile->top)
    yoffset = - (double)((metaFile->bottom - metaFile->top)/2.0);
  else
    yoffset = - (double)((metaFile->top - metaFile->bottom)/2.0);

  if (metaFile->right > metaFile->left)
    xoffset = - (double)((metaFile->right - metaFile->left)/2.0);
  else
    xoffset = - (double)((metaFile->left - metaFile->right)/2.0);

  Translate(xoffset, yoffset);

  // Scale to a reasonable size (take the width of this wxDrawnShape
  // as a guide)
  if (actualWidth != 0.0)
  {
    initialScaleX = (double)((*rwidth) / actualWidth);
    initialScaleY = initialScaleX;
    (*rheight) = initialScaleY*actualHeight;
  }
  Scale(initialScaleX, initialScaleY);

  m_width = (actualWidth*initialScaleX);
  m_height = *rheight;

  delete metaFile;
  return true;
}

// Scale to fit size
void wxPseudoMetaFile::ScaleTo(double w, double h)
{
  double scaleX = (double)(w/m_width);
  double scaleY = (double)(h/m_height);

  // Do the scaling
  Scale(scaleX, scaleY);
}

void wxPseudoMetaFile::GetBounds(double *boundMinX, double *boundMinY, double *boundMaxX, double *boundMaxY)
{
  double maxX = (double) -99999.9;
  double maxY = (double) -99999.9;
  double minX = (double) 99999.9;
  double minY = (double) 99999.9;

  wxNode *node = m_ops.GetFirst();
  while (node)
  {
    wxDrawOp *op = (wxDrawOp *)node->GetData();
    switch (op->GetOp())
    {
      case DRAWOP_DRAW_LINE:
      case DRAWOP_DRAW_RECT:
      case DRAWOP_DRAW_ROUNDED_RECT:
      case DRAWOP_DRAW_ELLIPSE:
      case DRAWOP_DRAW_ELLIPTIC_ARC:
      case DRAWOP_DRAW_POINT:
      case DRAWOP_DRAW_TEXT:
      {
        wxOpDraw *opDraw = (wxOpDraw *)op;
        if (opDraw->m_x1 < minX) minX = opDraw->m_x1;
        if (opDraw->m_x1 > maxX) maxX = opDraw->m_x1;
        if (opDraw->m_y1 < minY) minY = opDraw->m_y1;
        if (opDraw->m_y1 > maxY) maxY = opDraw->m_y1;
        if (op->GetOp() == DRAWOP_DRAW_LINE)
        {
          if (opDraw->m_x2 < minX) minX = opDraw->m_x2;
          if (opDraw->m_x2 > maxX) maxX = opDraw->m_x2;
          if (opDraw->m_y2 < minY) minY = opDraw->m_y2;
          if (opDraw->m_y2 > maxY) maxY = opDraw->m_y2;
        }
        else if (op->GetOp() == DRAWOP_DRAW_RECT ||
                 op->GetOp() == DRAWOP_DRAW_ROUNDED_RECT ||
                 op->GetOp() == DRAWOP_DRAW_ELLIPSE ||
                 op->GetOp() == DRAWOP_DRAW_ELLIPTIC_ARC)
        {
          if ((opDraw->m_x1 + opDraw->m_x2) < minX) minX = (opDraw->m_x1 + opDraw->m_x2);
          if ((opDraw->m_x1 + opDraw->m_x2) > maxX) maxX = (opDraw->m_x1 + opDraw->m_x2);
          if ((opDraw->m_y1 + opDraw->m_y2) < minY) minY = (opDraw->m_y1 + opDraw->m_y2);
          if ((opDraw->m_y1 + opDraw->m_y2) > maxY) maxY = (opDraw->m_y1 + opDraw->m_y2);
        }
        break;
      }
      case DRAWOP_DRAW_ARC:
      {
        // TODO: don't yet know how to calculate the bounding box
        // for an arc. So pretend it's a line; to get a correct
        // bounding box, draw a blank rectangle first, of the correct
        // size.
        wxOpDraw *opDraw = (wxOpDraw *)op;
        if (opDraw->m_x1 < minX) minX = opDraw->m_x1;
        if (opDraw->m_x1 > maxX) maxX = opDraw->m_x1;
        if (opDraw->m_y1 < minY) minY = opDraw->m_y1;
        if (opDraw->m_y1 > maxY) maxY = opDraw->m_y1;
        if (opDraw->m_x2 < minX) minX = opDraw->m_x2;
        if (opDraw->m_x2 > maxX) maxX = opDraw->m_x2;
        if (opDraw->m_y2 < minY) minY = opDraw->m_y2;
        if (opDraw->m_y2 > maxY) maxY = opDraw->m_y2;
        break;
      }
      case DRAWOP_DRAW_POLYLINE:
      case DRAWOP_DRAW_POLYGON:
      case DRAWOP_DRAW_SPLINE:
      {
        wxOpPolyDraw *poly = (wxOpPolyDraw *)op;
        for (int i = 0; i < poly->m_noPoints; i++)
        {
          if (poly->m_points[i].x < minX) minX = poly->m_points[i].x;
          if (poly->m_points[i].x > maxX) maxX = poly->m_points[i].x;
          if (poly->m_points[i].y < minY) minY = poly->m_points[i].y;
          if (poly->m_points[i].y > maxY) maxY = poly->m_points[i].y;
        }
        break;
      }
      default:
        break;
    }
    node = node->GetNext();
  }

  *boundMinX = minX;
  *boundMinY = minY;
  *boundMaxX = maxX;
  *boundMaxY = maxY;
/*
  *w = (double)fabs(maxX - minX);
  *h = (double)fabs(maxY - minY);
*/
}

// Calculate size from current operations
void wxPseudoMetaFile::CalculateSize(wxDrawnShape* shape)
{
  double boundMinX, boundMinY, boundMaxX, boundMaxY;

  GetBounds(& boundMinX, & boundMinY, & boundMaxX, & boundMaxY);

  SetSize(boundMaxX - boundMinX, boundMaxY - boundMinY);

  if (shape)
  {
    shape->SetWidth(m_width);
    shape->SetHeight(m_height);
  }
}

// Set of functions for drawing into a pseudo metafile.
// They use integers, but doubles are used internally for accuracy
// when scaling.

void wxPseudoMetaFile::DrawLine(const wxPoint& pt1, const wxPoint& pt2)
{
    wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_LINE,
          (double) pt1.x, (double) pt1.y, (double) pt2.x, (double) pt2.y);

    m_ops.Append(theOp);
}

void wxPseudoMetaFile::DrawRectangle(const wxRect& rect)
{
    wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_RECT,
          (double) rect.x, (double) rect.y, (double) rect.width, (double) rect.height);

    m_ops.Append(theOp);
}

void wxPseudoMetaFile::DrawRoundedRectangle(const wxRect& rect, double radius)
{
    wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT,
          (double) rect.x, (double) rect.y, (double) rect.width, (double) rect.height);

    theOp->m_radius = radius;

    m_ops.Append(theOp);
}

void wxPseudoMetaFile::DrawEllipse(const wxRect& rect)
{
    wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_ELLIPSE,
          (double) rect.x, (double) rect.y, (double) rect.width, (double) rect.height);

    m_ops.Append(theOp);
}

void wxPseudoMetaFile::DrawArc(const wxPoint& centrePt, const wxPoint& startPt, const wxPoint& endPt)
{
    wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_ARC,
          (double) centrePt.x, (double) centrePt.y, (double) startPt.x, (double) startPt.y);

    theOp->m_x3 = (double) endPt.x;
    theOp->m_y3 = (double) endPt.y;

    m_ops.Append(theOp);
}

void wxPseudoMetaFile::DrawEllipticArc(const wxRect& rect, double startAngle, double endAngle)
{
    const double pi = M_PI ;

    double startAngleRadians = startAngle* (pi*2.0/360.0);
    double endAngleRadians = endAngle* (pi*2.0/360.0);

    wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_ELLIPTIC_ARC,
          (double) rect.x, (double) rect.y, (double) rect.width, (double) rect.height);

    theOp->m_x3 = startAngleRadians;
    theOp->m_y3 = endAngleRadians;

    m_ops.Append(theOp);
}

void wxPseudoMetaFile::DrawPoint(const wxPoint& pt)
{
    wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_POINT,
          (double) pt.x, (double) pt.y, 0.0, 0.0);

    m_ops.Append(theOp);
}

void wxPseudoMetaFile::DrawText(const wxString& text, const wxPoint& pt)
{
    wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_TEXT,
          (double) pt.x, (double) pt.y, 0.0, 0.0);

    theOp->m_textString = text;

    m_ops.Append(theOp);
}

void wxPseudoMetaFile::DrawLines(int n, wxPoint pts[])
{
    wxRealPoint* realPoints = new wxRealPoint[n];
    int i;
    for (i = 0; i < n; i++)
    {
        realPoints[i].x = pts[i].x;
        realPoints[i].y = pts[i].y;
    }
    wxOpPolyDraw* theOp = new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE, n, realPoints);
    m_ops.Append(theOp);
}

void wxPseudoMetaFile::DrawPolygon(int n, wxPoint pts[], int flags)
{
    wxRealPoint* realPoints = new wxRealPoint[n];
    int i;
    for (i = 0; i < n; i++)
    {
        realPoints[i].x = pts[i].x;
        realPoints[i].y = pts[i].y;
    }
    wxOpPolyDraw* theOp = new wxOpPolyDraw(DRAWOP_DRAW_POLYGON, n, realPoints);
    m_ops.Append(theOp);

    if (flags & oglMETAFLAGS_OUTLINE)
        m_outlineOp = (m_ops.GetCount() - 1);
}

void wxPseudoMetaFile::DrawSpline(int n, wxPoint pts[])
{
    wxRealPoint* realPoints = new wxRealPoint[n];
    int i;
    for (i = 0; i < n; i++)
    {
        realPoints[i].x = pts[i].x;
        realPoints[i].y = pts[i].y;
    }
    wxOpPolyDraw* theOp = new wxOpPolyDraw(DRAWOP_DRAW_SPLINE, n, realPoints);
    m_ops.Append(theOp);
}

void wxPseudoMetaFile::SetClippingRect(const wxRect& rect)
{
    /* wxOpSetClipping* theOp = */ new wxOpSetClipping(DRAWOP_SET_CLIPPING_RECT,
        (double) rect.x, (double) rect.y, (double) rect.width, (double) rect.height);
}

void wxPseudoMetaFile::DestroyClippingRect()
{
    wxOpSetClipping* theOp = new wxOpSetClipping(DRAWOP_DESTROY_CLIPPING_RECT,
        0.0, 0.0, 0.0, 0.0);

    m_ops.Append(theOp

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -