📄 drawn.cpp
字号:
expr->Append(new wxExpr((long)theBrush->GetColour().Blue())); } else if (obj->IsKindOf(CLASSINFO(wxFont))) { wxFont *theFont = (wxFont *)obj; expr = new wxExpr(wxExprList); expr->Append(new wxExpr((long)gyTYPE_FONT)); expr->Append(new wxExpr((long)theFont->GetPointSize())); expr->Append(new wxExpr((long)theFont->GetFamily())); expr->Append(new wxExpr((long)theFont->GetStyle())); expr->Append(new wxExpr((long)theFont->GetWeight())); expr->Append(new wxExpr((long)theFont->GetUnderlined())); } } else { // If no recognised GDI object, append a place holder anyway. expr = new wxExpr(wxExprList); expr->Append(new wxExpr((long)0)); } if (expr) { clause->AddAttributeValue(buf, expr); i ++; } node = node->GetNext(); } // Write drawing operations i = 1; node = m_ops.GetFirst(); while (node) { wxSprintf(buf, _T("op%d_%d"), whichAngle, i); wxDrawOp *op = (wxDrawOp *)node->GetData(); wxExpr *expr = op->WriteExpr(this); if (expr) { clause->AddAttributeValue(buf, expr); i ++; } node = node->GetNext(); } // Write outline and fill GDI op lists (if any) if (m_outlineColours.GetCount() > 0) { wxExpr *outlineExpr = new wxExpr(wxExprList); node = m_outlineColours.GetFirst(); while (node) { outlineExpr->Append(new wxExpr((long)node->GetData())); node = node->GetNext(); } wxString outlineObjectsStr; outlineObjectsStr.Printf(wxT("outline_objects%d"), whichAngle); clause->AddAttributeValue(outlineObjectsStr, outlineExpr); } if (m_fillColours.GetCount() > 0) { wxExpr *fillExpr = new wxExpr(wxExprList); node = m_fillColours.GetFirst(); while (node) { fillExpr->Append(new wxExpr((long)node->GetData())); node = node->GetNext(); } wxString fillObjectsStr; fillObjectsStr.Printf(wxT("fill_objects%d"), whichAngle); clause->AddAttributeValue(fillObjectsStr, fillExpr); }}void wxPseudoMetaFile::ReadAttributes(wxExpr *clause, int whichAngle){ wxString widthStr; widthStr.Printf(wxT("meta_width%d"), whichAngle); wxString heightStr; heightStr.Printf(wxT("meta_height%d"), whichAngle); wxString outlineStr; outlineStr.Printf(wxT("outline_op%d"), whichAngle); wxString rotateableStr; rotateableStr.Printf(wxT("meta_rotateable%d"), whichAngle); clause->GetAttributeValue(widthStr, m_width); clause->GetAttributeValue(heightStr, m_height); clause->GetAttributeValue(outlineStr, m_outlineOp); int iVal = (int) m_rotateable; clause->GetAttributeValue(rotateableStr, iVal); m_rotateable = (iVal != 0); // Read GDI objects wxChar buf[50]; int i = 1; bool keepGoing = true; while (keepGoing) { wxSprintf(buf, _T("gdi%d_%d"), whichAngle, i); wxExpr *expr = NULL; clause->GetAttributeValue(buf, &expr); if (!expr) { keepGoing = false; } else { wxExpr *idExpr = expr->Nth(0); switch (idExpr->IntegerValue()) { case gyTYPE_PEN: { int penWidth = (int)expr->Nth(1)->IntegerValue(); int penStyle = (int)expr->Nth(2)->IntegerValue(); unsigned char penRed = (unsigned char)expr->Nth(3)->IntegerValue(); unsigned char penGreen = (unsigned char)expr->Nth(4)->IntegerValue(); unsigned char penBlue = (unsigned char)expr->Nth(5)->IntegerValue(); wxColour col(penRed, penGreen, penBlue); wxPen *p = wxThePenList->FindOrCreatePen(col, penWidth, penStyle); if (!p) p = wxBLACK_PEN; m_gdiObjects.Append(p); break; } case gyTYPE_BRUSH: { int brushStyle = (int)expr->Nth(1)->IntegerValue(); unsigned char brushRed = (unsigned char)expr->Nth(2)->IntegerValue(); unsigned char brushGreen = (unsigned char)expr->Nth(3)->IntegerValue(); unsigned char brushBlue = (unsigned char)expr->Nth(4)->IntegerValue(); wxColour col(brushRed, brushGreen, brushBlue); wxBrush *b = wxTheBrushList->FindOrCreateBrush(col, brushStyle); if (!b) b = wxWHITE_BRUSH; m_gdiObjects.Append(b); break; } case gyTYPE_FONT: { int fontPointSize = (int)expr->Nth(1)->IntegerValue(); int fontFamily = (int)expr->Nth(2)->IntegerValue(); int fontStyle = (int)expr->Nth(3)->IntegerValue(); int fontWeight = (int)expr->Nth(4)->IntegerValue(); int fontUnderlined = (int)expr->Nth(5)->IntegerValue(); m_gdiObjects.Append(wxTheFontList->FindOrCreateFont(fontPointSize, fontFamily, fontStyle, fontWeight, (fontUnderlined != 0))); break; } default: { // Place holder m_gdiObjects.Append(NULL); break; } } i ++; } } // Now read in the operations keepGoing = true; i = 1; while (keepGoing) { wxSprintf(buf, _T("op%d_%d"), whichAngle, i); wxExpr *expr = NULL; clause->GetAttributeValue(buf, &expr); if (!expr) { keepGoing = false; } else { wxExpr *idExpr = expr->Nth(0); int opId = (int)idExpr->IntegerValue(); switch (opId) { case DRAWOP_SET_PEN: case DRAWOP_SET_BRUSH: case DRAWOP_SET_FONT: case DRAWOP_SET_TEXT_COLOUR: case DRAWOP_SET_BK_COLOUR: case DRAWOP_SET_BK_MODE: { wxOpSetGDI *theOp = new wxOpSetGDI(opId, this, 0); theOp->ReadExpr(this, expr); m_ops.Append(theOp); break; } case DRAWOP_SET_CLIPPING_RECT: case DRAWOP_DESTROY_CLIPPING_RECT: { wxOpSetClipping *theOp = new wxOpSetClipping(opId, 0.0, 0.0, 0.0, 0.0); theOp->ReadExpr(this, expr); m_ops.Append(theOp); break; } case DRAWOP_DRAW_LINE: case DRAWOP_DRAW_RECT: case DRAWOP_DRAW_ROUNDED_RECT: case DRAWOP_DRAW_ELLIPSE: case DRAWOP_DRAW_POINT: case DRAWOP_DRAW_ARC: case DRAWOP_DRAW_TEXT: { wxOpDraw *theOp = new wxOpDraw(opId, 0.0, 0.0, 0.0, 0.0); theOp->ReadExpr(this, expr); m_ops.Append(theOp); break; } case DRAWOP_DRAW_SPLINE: case DRAWOP_DRAW_POLYLINE: case DRAWOP_DRAW_POLYGON: { wxOpPolyDraw *theOp = new wxOpPolyDraw(opId, 0, NULL); theOp->ReadExpr(this, expr); m_ops.Append(theOp); break; } default: break; } } i ++; } wxString outlineObjectsStr; outlineObjectsStr.Printf(wxT("outline_objects%d"), whichAngle); // Now read in the list of outline and fill operations, if any wxExpr *expr1 = clause->AttributeValue(outlineObjectsStr); if (expr1) { wxExpr *eachExpr = expr1->GetFirst(); while (eachExpr) { m_outlineColours.Append((wxObject *)eachExpr->IntegerValue()); eachExpr = eachExpr->GetNext(); } } wxString fillObjectsStr; fillObjectsStr.Printf(wxT("fill_objects%d"), whichAngle); expr1 = clause->AttributeValue(fillObjectsStr); if (expr1) { wxExpr *eachExpr = expr1->GetFirst(); while (eachExpr) { m_fillColours.Append((wxObject *)eachExpr->IntegerValue()); eachExpr = eachExpr->GetNext(); } }}#endif// Does the copying for this objectvoid wxPseudoMetaFile::Copy(wxPseudoMetaFile& copy){ copy.Clear(); copy.m_currentRotation = m_currentRotation; copy.m_width = m_width; copy.m_height = m_height; copy.m_rotateable = m_rotateable; copy.m_fillBrush = m_fillBrush; copy.m_outlinePen = m_outlinePen; copy.m_outlineOp = m_outlineOp; // Copy the GDI objects wxNode *node = m_gdiObjects.GetFirst(); while (node) { wxObject *obj = (wxObject *)node->GetData(); copy.m_gdiObjects.Append(obj); node = node->GetNext(); } // Copy the operations node = m_ops.GetFirst(); while (node) { wxDrawOp *op = (wxDrawOp *)node->GetData(); copy.m_ops.Append(op->Copy(©)); node = node->GetNext(); } // Copy the outline/fill operations node = m_outlineColours.GetFirst(); while (node) { copy.m_outlineColours.Append((wxObject *)node->GetData()); node = node->GetNext(); } node = m_fillColours.GetFirst(); while (node) { copy.m_fillColours.Append((wxObject *)node->GetData()); node = node->GetNext(); }}/* * Pass size of existing image; scale height to * fit width and return new width and height. * */bool wxPseudoMetaFile::LoadFromMetaFile(const wxString& filename, double *rwidth, double *rheight){ if (!wxFileExists(filename)) return false; wxXMetaFile *metaFile = new wxXMetaFile; if (!metaFile->ReadFile(filename)) { delete metaFile; return false; } double lastX = 0.0; double lastY = 0.0; // Convert from metafile records to wxDrawnShape records wxNode *node = metaFile->metaRecords.GetFirst(); while (node) { wxMetaRecord *record = (wxMetaRecord *)node->GetData(); switch (record->metaFunction) { case META_SETBKCOLOR: { wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_BK_COLOUR, this, 0); op->m_r = (unsigned char)record->param1; op->m_g = (unsigned char)record->param2; op->m_b = (unsigned char)record->param3; m_ops.Append(op); break; } case META_SETBKMODE: { wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_BK_MODE, this, 0, (int)record->param1); m_ops.Append(op); break; } case META_SETMAPMODE: { break; }// case META_SETROP2:// case META_SETRELABS:// case META_SETPOLYFILLMODE:// case META_SETSTRETCHBLTMODE:// case META_SETTEXTCHAREXTRA: case META_SETTEXTCOLOR: { wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR, this, 0); op->m_r = (unsigned char)record->param1; op->m_g = (unsigned char)record->param2; op->m_b = (unsigned char)record->param3; m_ops.Append(op); break; }// case META_SETTEXTJUSTIFICATION:// case META_SETWINDOWORG:// case META_SETWINDOWEXT:// case META_SETVIEWPORTORG:// case META_SETVIEWPORTEXT:// case META_OFFSETWINDOWORG:// case META_SCALEWINDOWEXT:// case META_OFFSETVIEWPORTORG:// case META_SCALEVIEWPORTEXT: case META_LINETO: { wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_LINE, (double)lastX, (double)lastY, (double)record->param1, (double)record->param2); m_ops.Append(op); break; } case META_MOVETO: { lastX = (double)record->param1; lastY = (double)record->param2; break; } case META_EXCLUDECLIPRECT: {/* wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT); rec->param4 = getshort(handle); // m_y2 rec->param3 = getshort(handle); // x2 rec->param2 = getshort(handle); // y1 rec->param1 = getshort(handle); // x1*/ break; } case META_INTERSECTCLIPRECT: {/* rec->param4 = getshort(handle); // m_y2 rec->param3 = getshort(handle); // x2 rec->param2 = getshort(handle); // y1 rec->param1 = getshort(handle); // x1*/ break; }// case META_ARC: // DO!!! case META_ELLIPSE: { wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_ELLIPSE, (double)record->param1, (double)record->param2, (double)(record->param3 - record->param1), (double)(record->param4 - record->param2)); m_ops.Append(op); break; }// case META_FLOODFILL:// case META_PIE: // DO!!! case META_RECTANGLE: { wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_RECT, (double)record->param1, (double)record->param2, (double)(record->param3 - record->param1), (double)(record->param4 - record->param2)); m_ops.Append(op); break; } case META_ROUNDRECT: { wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT, (double)record->param1, (double)record->param2, (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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -