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

📄 basic2.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 4 页
字号:

  delete[] xpoints;
  delete[] ypoints;

  return true;
}

void wxPolygonShape::OnDraw(wxDC& dc)
{
    int n = m_points->GetCount();
    wxPoint *intPoints = new wxPoint[n];
    int i;
    for (i = 0; i < n; i++)
    {
      wxRealPoint* point = (wxRealPoint*) m_points->Item(i)->GetData();
      intPoints[i].x = WXROUND(point->x);
      intPoints[i].y = WXROUND(point->y);
    }

    if (m_shadowMode != SHADOW_NONE)
    {
      if (m_shadowBrush)
        dc.SetBrush(* m_shadowBrush);
      dc.SetPen(* g_oglTransparentPen);

      dc.DrawPolygon(n, intPoints, WXROUND(m_xpos + m_shadowOffsetX), WXROUND(m_ypos + m_shadowOffsetY));
    }

    if (m_pen)
    {
      if (m_pen->GetWidth() == 0)
        dc.SetPen(* g_oglTransparentPen);
      else
        dc.SetPen(* m_pen);
    }
    if (m_brush)
      dc.SetBrush(* m_brush);
    dc.DrawPolygon(n, intPoints, WXROUND(m_xpos), WXROUND(m_ypos));

    delete[] intPoints;
}

void wxPolygonShape::OnDrawOutline(wxDC& dc, double x, double y, double w, double h)
{
  dc.SetBrush(* wxTRANSPARENT_BRUSH);
  // Multiply all points by proportion of new size to old size
  double x_proportion = (double)(fabs(w/m_originalWidth));
  double y_proportion = (double)(fabs(h/m_originalHeight));

  int n = m_originalPoints->GetCount();
  wxPoint *intPoints = new wxPoint[n];
  int i;
  for (i = 0; i < n; i++)
  {
    wxRealPoint* point = (wxRealPoint*) m_originalPoints->Item(i)->GetData();
    intPoints[i].x = WXROUND(x_proportion * point->x);
    intPoints[i].y = WXROUND(y_proportion * point->y);
  }
  dc.DrawPolygon(n, intPoints, WXROUND(x), WXROUND(y));
  delete[] intPoints;
}

// Make as many control points as there are vertices.
void wxPolygonShape::MakeControlPoints()
{
  wxObjectList::compatibility_iterator node = m_points->GetFirst();
  while (node)
  {
    wxRealPoint *point = (wxRealPoint *)node->GetData();
    wxPolygonControlPoint *control = new wxPolygonControlPoint(m_canvas, this, CONTROL_POINT_SIZE,
      point, point->x, point->y);
    m_canvas->AddShape(control);
    m_controlPoints.Append(control);
    node = node->GetNext();
  }
}

void wxPolygonShape::ResetControlPoints()
{
  wxObjectList::compatibility_iterator node = m_points->GetFirst();
  wxObjectList::compatibility_iterator controlPointNode = m_controlPoints.GetFirst();
  while (node && controlPointNode)
  {
    wxRealPoint *point = (wxRealPoint *)node->GetData();
    wxPolygonControlPoint *controlPoint = (wxPolygonControlPoint *)controlPointNode->GetData();

    controlPoint->m_xoffset = point->x;
    controlPoint->m_yoffset = point->y;
    controlPoint->m_polygonVertex = point;

    node = node->GetNext();
    controlPointNode = controlPointNode->GetNext();
  }
}


#if wxUSE_PROLOGIO
void wxPolygonShape::WriteAttributes(wxExpr *clause)
{
  wxShape::WriteAttributes(clause);

  clause->AddAttributeValue(wxT("x"), m_xpos);
  clause->AddAttributeValue(wxT("y"), m_ypos);

  // Make a list of lists for the coordinates
  wxExpr *list = new wxExpr(wxExprList);
  wxObjectList::compatibility_iterator node = m_points->GetFirst();
  while (node)
  {
    wxRealPoint *point = (wxRealPoint *)node->GetData();
    wxExpr *point_list = new wxExpr(wxExprList);
    wxExpr *x_expr = new wxExpr((double)point->x);
    wxExpr *y_expr = new wxExpr((double)point->y);

    point_list->Append(x_expr);
    point_list->Append(y_expr);
    list->Append(point_list);

    node = node->GetNext();
  }
  clause->AddAttributeValue(wxT("points"), list);

  // Save the original (unscaled) points
  list = new wxExpr(wxExprList);
  node = m_originalPoints->GetFirst();
  while (node)
  {
    wxRealPoint *point = (wxRealPoint *)node->GetData();
    wxExpr *point_list = new wxExpr(wxExprList);
    wxExpr *x_expr = new wxExpr((double) point->x);
    wxExpr *y_expr = new wxExpr((double) point->y);
    point_list->Append(x_expr);
    point_list->Append(y_expr);
    list->Append(point_list);

    node = node->GetNext();
  }
  clause->AddAttributeValue(wxT("m_originalPoints"), list);
}

void wxPolygonShape::ReadAttributes(wxExpr *clause)
{
  wxShape::ReadAttributes(clause);

  // Read a list of lists
  m_points = new wxList;
  m_originalPoints = new wxList;

  wxExpr *points_list = NULL;
  clause->AssignAttributeValue(wxT("points"), &points_list);

  // If no points_list, don't crash!! Assume a diamond instead.
  double the_height = 100.0;
  double the_width = 100.0;
  if (!points_list)
  {
    wxRealPoint *point = new wxRealPoint(0.0, (-the_height/2));
    m_points->Append((wxObject*) point);

    point = new wxRealPoint((the_width/2), 0.0);
    m_points->Append((wxObject*) point);

    point = new wxRealPoint(0.0, (the_height/2));
    m_points->Append((wxObject*) point);

    point = new wxRealPoint((-the_width/2), 0.0);
    m_points->Append((wxObject*) point);

    point = new wxRealPoint(0.0, (-the_height/2));
    m_points->Append((wxObject*) point);
  }
  else
  {
    wxExpr *node = points_list->value.first;

    while (node)
    {
      wxExpr *xexpr = node->value.first;
      long x = xexpr->IntegerValue();

      wxExpr *yexpr = xexpr->next;
      long y = yexpr->IntegerValue();

      wxRealPoint *point = new wxRealPoint((double)x, (double)y);
      m_points->Append((wxObject*) point);

      node = node->next;
    }
  }

  points_list = NULL;
  clause->AssignAttributeValue(wxT("m_originalPoints"), &points_list);

  // If no points_list, don't crash!! Assume a diamond instead.
  if (!points_list)
  {
    wxRealPoint *point = new wxRealPoint(0.0, (-the_height/2));
    m_originalPoints->Append((wxObject*) point);

    point = new wxRealPoint((the_width/2), 0.0);
    m_originalPoints->Append((wxObject*) point);

    point = new wxRealPoint(0.0, (the_height/2));
    m_originalPoints->Append((wxObject*) point);

    point = new wxRealPoint((-the_width/2), 0.0);
    m_originalPoints->Append((wxObject*) point);

    point = new wxRealPoint(0.0, (-the_height/2));
    m_originalPoints->Append((wxObject*) point);

    m_originalWidth = the_width;
    m_originalHeight = the_height;
  }
  else
  {
    wxExpr *node = points_list->value.first;
    double min_x = 1000;
    double min_y = 1000;
    double max_x = -1000;
    double max_y = -1000;
    while (node)
    {
      wxExpr *xexpr = node->value.first;
      long x = xexpr->IntegerValue();

      wxExpr *yexpr = xexpr->next;
      long y = yexpr->IntegerValue();

      wxRealPoint *point = new wxRealPoint((double)x, (double)y);
      m_originalPoints->Append((wxObject*) point);

      if (x < min_x)
        min_x = (double)x;
      if (y < min_y)
        min_y = (double)y;
      if (x > max_x)
        max_x = (double)x;
      if (y > max_y)
        max_y = (double)y;

      node = node->next;
    }
    m_originalWidth = max_x - min_x;
    m_originalHeight = max_y - min_y;
  }

  CalculateBoundingBox();
}
#endif

void wxPolygonShape::Copy(wxShape& copy)
{
  wxShape::Copy(copy);

  wxASSERT( copy.IsKindOf(CLASSINFO(wxPolygonShape)) );

  wxPolygonShape& polyCopy = (wxPolygonShape&) copy;

  polyCopy.ClearPoints();

  polyCopy.m_points = new wxList;
  polyCopy.m_originalPoints = new wxList;

  wxObjectList::compatibility_iterator node = m_points->GetFirst();
  while (node)
  {
    wxRealPoint *point = (wxRealPoint *)node->GetData();
    wxRealPoint *new_point = new wxRealPoint(point->x, point->y);
    polyCopy.m_points->Append((wxObject*) new_point);
    node = node->GetNext();
  }
  node = m_originalPoints->GetFirst();
  while (node)
  {
    wxRealPoint *point = (wxRealPoint *)node->GetData();
    wxRealPoint *new_point = new wxRealPoint(point->x, point->y);
    polyCopy.m_originalPoints->Append((wxObject*) new_point);
    node = node->GetNext();
  }
  polyCopy.m_boundWidth = m_boundWidth;
  polyCopy.m_boundHeight = m_boundHeight;
  polyCopy.m_originalWidth = m_originalWidth;
  polyCopy.m_originalHeight = m_originalHeight;
}

int wxPolygonShape::GetNumberOfAttachments() const
{
  int maxN = (m_points ? (m_points->GetCount() - 1) : 0);
  wxObjectList::compatibility_iterator node = m_attachmentPoints.GetFirst();
  while (node)
  {
    wxAttachmentPoint *point = (wxAttachmentPoint *)node->GetData();
    if (point->m_id > maxN)
      maxN = point->m_id;
    node = node->GetNext();
  }
  return maxN+1;;
}

bool wxPolygonShape::GetAttachmentPosition(int attachment, double *x, double *y,
                                         int nth, int no_arcs, wxLineShape *line)
{
  if ((m_attachmentMode == ATTACHMENT_MODE_EDGE) && m_points && attachment < (int) m_points->GetCount())
  {
    wxRealPoint *point = (wxRealPoint *)m_points->Item(attachment)->GetData();
    *x = point->x + m_xpos;
    *y = point->y + m_ypos;
    return true;
  }
  else
  { return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line); }
}

bool wxPolygonShape::AttachmentIsValid(int attachment) const
{
  if (!m_points)
    return false;

  if ((attachment >= 0) && (attachment < (int) m_points->GetCount()))
    return true;

  wxObjectList::compatibility_iterator node = m_attachmentPoints.GetFirst();
  while (node)
  {
    wxAttachmentPoint *point = (wxAttachmentPoint *)node->GetData();
    if (point->m_id == attachment)
      return true;
    node = node->GetNext();
  }
  return false;
}

// Rotate about the given axis by the given amount in radians
void wxPolygonShape::Rotate(double x, double y, double theta)
{
    double actualTheta = theta-m_rotation;

    // Rotate attachment points
    double sinTheta = (double)sin(actualTheta);
    double cosTheta = (double)cos(actualTheta);
    wxObjectList::compatibility_iterator node = m_attachmentPoints.GetFirst();
    while (node)
    {
        wxAttachmentPoint *point = (wxAttachmentPoint *)node->GetData();
        double x1 = point->m_x;
        double y1 = point->m_y;
        point->m_x = x1*cosTheta - y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
        point->m_y = x1*sinTheta + y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
        node = node->GetNext();
    }

    node = m_points->GetFirst();
    while (node)
    {
        wxRealPoint *point = (wxRealPoint *)node->GetData();
        double x1 = point->x;
        double y1 = point->y;
        point->x = x1*cosTheta - y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
        point->y = x1*sinTheta + y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
        node = node->GetNext();
    }
    node = m_originalPoints->GetFirst();
    while (node)
    {
        wxRealPoint *point = (wxRealPoint *)node->GetData();
        double x1 = point->x;
        double y1 = point->y;
        point->x = x1*cosTheta - y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
        point->y = x1*sinTheta + y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
        node = node->GetNext();
    }

    m_rotation = theta;

    CalculatePolygonCentre();
    CalculateBoundingBox();
    ResetControlPoints();
}

// Rectangle object

IMPLEMENT_DYNAMIC_CLASS(wxRectangleShape, wxShape)

wxRectangleShape::wxRectangleShape(double w, double h)
{
  m_width = w; m_height = h; m_cornerRadius = 0.0;
  SetDefaultRegionSize();
}

void wxRectangleShape::OnDraw(wxDC& dc)
{
    double x1 = (double)(m_xpos - m_width/2.0);
    double y1 = (double)(m_ypos - m_height/2.0);

    if (m_shadowMode != SHADOW_NONE)
    {
      if (m_shadowBrush)
        dc.SetBrush(* m_shadowBrush);
      dc.SetPen(* g_oglTransparentPen);

      if (m_cornerRadius != 0.0)
        dc.DrawRoundedRectangle(WXROUND(x1 + m_shadowOffsetX), WXROUND(y1 + m_shadowOffsetY),
                                 WXROUND(m_width), WXROUND(m_height), m_cornerRadius);
      else
        dc.DrawRectangle(WXROUND(x1 + m_shadowOffsetX), WXROUND(y1 + m_shadowOffsetY), WXROUND(m_width), WXROUND(m_height));
    }

    if (m_pen)
    {
      if (m_pen->GetWidth() == 0)
        dc.SetPen(* g_oglTransparentPen);
      else
        dc.SetPen(* m_pen);
    }
    if (m_brush)
      dc.SetBrush(* m_brush);

    if (m_cornerRadius != 0.0)
      dc.DrawRoundedRectangle(WXROUND(x1), WXROUND(y1), WXROUND(m_width), WXROUND(m_height), m_cornerRadius);
    else
      dc.DrawRectangle(WXROUND(x1), WXROUND(y1), WXROUND(m_width), WXROUND(m_height));
}

void wxRectangleShape::GetBoundingBoxMin(double *the_width, double *the_height)
{
  *the_width = m_width;
  *the_height = m_height;
}

void wxRectangleShape::SetSize(double x, double y, bool WXUNUSED(recursive))
{
  SetAttachmentSize(x, y);
  m_width = (double)wxMax(x, 1.0);
  m_height = (double)wxMax(y, 1.0);
  SetDefaultRegionSize();
}

void wxRectangleShape::SetCornerRadius(double rad)
{
  m_cornerRadius = rad;
}

// Assume (x1, y1) is centre of box (most generally, line end at box)
bool wxRectangleShape::GetPerimeterPoint(double WXUNUSED(x1), double WXUNUSED(y1),
                                     double x2, double y2,
                                     double *x3, double *y3)
{
  double bound_x, bound_y;
  GetBoundingBoxMax(&bound_x, &bound_y);
  oglFindEndForBox(bound_x, bound_y, m_xpos, m_ypos, x2, y2, x3, y3);

  return true;
}

#if wxUSE_PROLOGIO
void wxRectangleShape::WriteAttributes(wxExpr *clause)
{
  wxShape::WriteAttributes(clause);
  clause->AddAttributeValue(wxT("x"), m_xpos);
  clause->AddAttributeValue(wxT("y"), m_ypos);

  clause->AddAttributeValue(wxT("width"), m_width);
  clause->AddAttributeValue(wxT("height"), m_height);
  if (m_cornerRadius != 0.0)
    clause->AddAttributeValue(wxT("corner"), m_cornerRadius);
}

void wxRectangleShape::ReadAttributes(wxExpr *clause)
{
  wxShape::ReadAttributes(clause);
  clause->AssignAttributeValue(wxT("width"), &m_width);
  clause->AssignAttributeValue(wxT("height"), &m_height);
  clause->AssignAttributeValue(wxT("corner"), &m_cornerRadius);

⌨️ 快捷键说明

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