QList<QString> Chord::Simplify() const { // the simplified chord is the chord with all notes rearranged so that they are spaced as closely as possible // e.g. ['a','e','c'] simplified => ['a','c','e'] QList<QString> SimplerChord = WithoutDuplicateNotes(); SimplerChord = Chord(SimplerChord).SortedRelativeToFirstNote(); QList<QList<QString> > Inversions = Chord(SimplerChord).CreateAllInversions(); QHash< QString, QList<QString> > MinimumEnergyChordList; // map from interval pattern to list of theorynote QList< QList<int> > PatList; int Minimum = -1; for (QList<QList<QString> >::const_iterator it = Inversions.begin(); it != Inversions.end(); ++it) { QList<int> Pat = Chord(*it).ToIntervalPattern(); int sum=0; QListIterator<int> i(Pat); while (i.hasNext()) sum += i.next(); if (sum < Minimum || Minimum == -1) { Minimum = sum; MinimumEnergyChordList[PatternToKey(Pat)] = *it; PatList << Pat; } else if (sum == Minimum) { MinimumEnergyChordList[PatternToKey(Pat)] = *it; PatList << Pat; } } QList<QList<int> > SortedPatList = PatList; qSort(SortedPatList.begin(), SortedPatList.end(), PatternSort); return MinimumEnergyChordList[PatternToKey(SortedPatList[0])]; }
ChordDescriptor ChordRecognizer::RecognizeChord(const QList<QString> &TheoryNotes, bool &ChordRecognized) const { // first try to look up the non-simplified chord (to find specially named inversions) QList<QString> NoteList = Chord(TheoryNotes).WithoutDuplicateNotes(); QList<int> IntervalPattern = Chord(NoteList).ToIntervalPattern(); QString Key = Chord::PatternToKey(IntervalPattern); if (m_PatternToDescriptor.contains(Key)) { ChordRecognized = true; QPair<ChordDescriptor, unsigned int> Info = m_PatternToDescriptor[Key]; return ChordDescriptor(NoteList[Info.second], Info.first.GetModifier(), TheoryNotes[0]); } // if that failed, look for inversions of simplified chord QList<QString> SimplifiedChord = Chord(TheoryNotes).Simplify(); QList<QList<QString> > Inversions = Chord(SimplifiedChord).CreateAllInversions(); for (QList<QList<QString> >::const_iterator it = Inversions.begin(); it != Inversions.end(); ++it) { QList<int> IntervalPattern = Chord(*it).ToIntervalPattern(); QString Key = Chord::PatternToKey(IntervalPattern); if (m_PatternToDescriptor.contains(Key)) { ChordRecognized = true; QPair<ChordDescriptor, unsigned int> Info = m_PatternToDescriptor[Key]; return ChordDescriptor((*it)[Info.second], Info.first.GetModifier(), TheoryNotes[0]); } } ChordRecognized = false; return ChordDescriptor(TheoryNotes[0],"major",TheoryNotes[0]); }
void ChordRecognizer::RegisterNewChordType(const QList<QString> &TheoryNotes, const ChordDescriptor &ChordDescr) { QList<QString> SimplifiedChord = Chord(TheoryNotes).Simplify(); if (SimplifiedChord != TheoryNotes) { //qDebug() << "Warning! Registering non-minimized chord " << ChordDescr.GetBaseName() << "," // << ChordDescr.GetModifier() << "," << ChordDescr.GetSlash(); // first register the non-simplified chord as it may be a special name for an inversion QList<int> IntervalPattern = Chord(Chord(TheoryNotes).WithoutDuplicateNotes()).ToIntervalPattern(); QString Key = Chord::PatternToKey(IntervalPattern); unsigned int BaseNoteIndex = TheoryNotes.indexOf(QString(TheoryNotes[0])); /* if (m_PatternToDescriptor.contains(Key)) qDebug() << ChordDescr.GetBaseName() << "," << ChordDescr.GetModifier() << "," << ChordDescr.GetSlash() << " overwrites existing " << m_PatternToDescriptor[Key].first.GetBaseName() << "," << m_PatternToDescriptor[Key].first.GetModifier() << "," << m_PatternToDescriptor[Key].first.GetSlash(); */ if (!m_PatternToDescriptor.contains(Key)) m_PatternToDescriptor[Key] = QPair<ChordDescriptor, unsigned int>(ChordDescr, BaseNoteIndex); } QList<int> IntervalPattern = Chord(SimplifiedChord).ToIntervalPattern(); QString Key = Chord::PatternToKey(IntervalPattern); unsigned int BaseNoteIndex = SimplifiedChord.indexOf(QString(TheoryNotes[0])); /* if (m_PatternToDescriptor.contains(Key)) qDebug() << ChordDescr.GetBaseName() << "," << ChordDescr.GetModifier() << "," << ChordDescr.GetSlash() << " was prevented from overwriting existing " << m_PatternToDescriptor[Key].first.GetBaseName() << "," << m_PatternToDescriptor[Key].first.GetModifier() << "," << m_PatternToDescriptor[Key].first.GetSlash(); */ if (!m_PatternToDescriptor.contains(Key)) m_PatternToDescriptor[Key] = QPair<ChordDescriptor, unsigned int>(ChordDescr, BaseNoteIndex); }
void DrawTaiJi( HDC hdc, int x, int y, int radius, COLORREF upperLeftColor, COLORREF lowerRightColor ) { HPEN hLowerRightPen = CreatePen( 0, 1, lowerRightColor ); HPEN hUpperLeftPen = CreatePen( 0, 1, upperLeftColor ); HBRUSH hLowerRightBrush = CreateSolidBrush( lowerRightColor ); HBRUSH hUpperLeftBrush = CreateSolidBrush( upperLeftColor ); ////////////////////////////////////////////////////////////////////////// // 太极图外轮廓 ////////////////////////////////////////////////////////////////////////// SelectObject( hdc, hLowerRightPen ); SelectObject( hdc, hLowerRightBrush ); Chord( hdc, x-radius, y-radius, x+radius, y+radius, x, y+radius, x, y-radius ); SelectObject( hdc, hUpperLeftBrush ); Chord( hdc, x-radius, y-radius, x+radius, y+radius, x, y-radius, x, y+radius ); ////////////////////////////////////////////////////////////////////////// // 太极图上半部分 ////////////////////////////////////////////////////////////////////////// // 先用饼图将上面的圆的颜色画成上左方的配置颜色 SelectObject( hdc, hUpperLeftBrush ); SelectObject( hdc, hUpperLeftPen ); Chord( hdc, x-radius/2, y-radius, x+radius/2, y, x, y, x, y-radius ); // 再用上左方配置颜色的弧将上面的圆弧画出来 SelectObject( hdc, hLowerRightPen ); Arc( hdc, x-radius/2, y-radius, (int)(x+radius/2), y, x, y, x, y-radius ); SelectObject( hdc, hLowerRightBrush ); Ellipse( hdc, (int)(x-radius*0.2f), (int)(y-radius/2-radius*0.2f), (int)(x+radius*0.2f), (int)(x-radius/2+radius*0.2f) ); ////////////////////////////////////////////////////////////////////////// // 太极图下半部分 ////////////////////////////////////////////////////////////////////////// SelectObject( hdc, hLowerRightBrush ); Chord( hdc, x-radius/2, y, x+radius/2, y+radius, x, y, x, y+radius); SelectObject( hdc, hUpperLeftBrush ); Ellipse( hdc, (int)(x-radius*0.2f), (int)(y+radius/2-radius*0.2f), (int)(x+radius*0.2f), (int)(y+radius/2+radius*0.2f) ); // 删除所有对象 DeleteObject( hUpperLeftPen ); DeleteObject( hLowerRightPen ); DeleteObject( hUpperLeftBrush ); DeleteObject( hLowerRightBrush ); }
bool Chord::parseLine( const QString & line, QStringList & chords, QStringList & tokens ) { tokens = line.split(QRegExp(SPLIT_PATTERN)); int numberOfUncertainChords = 0; int numToken = 0; for (const QString & token : tokens) { if (Chord(token).isValid()) { chords << token; if ( token == "a" ) { numberOfUncertainChords++; } } // do only count tokens that contains letters or numbers etc. if (token.contains(QRegExp("[A-Za-z0-9]"))) { numToken++; } } const int numChords = chords.length(); return (double) (numChords - numberOfUncertainChords) / qMax(0, (numToken - numChords)) > 0.8; }
IntervalSequence<set<Chord> > PhraseMiner::load(const data_symb* ds) { data d = ds[0].datas; vector<int> start = d.start; vector<int> end = d.end; vector<int> symID = d.symbol; map<int, Chord> symbolMap; symb s = ds[0].symbs; int symb_size = s.symb_size; for (int i = 0; i < symb_size; ++i) { string label = s.label[i]; int globalID = s.symbol[i]; symbolMap.insert(pair<int, Chord>(globalID, Chord(globalID, set<Tone>(), label))); } vector<int> newStart; vector<int> newEnd; vector<int> newSymID; int symID_size = symID.size(); for (int i = 0; i < symID_size; i++) { if (symbolMap.find(symID[i]) != symbolMap.end()) { newStart.push_back(start[i]); newEnd.push_back(end[i]); newSymID.push_back(symID[i]); } } IntervalSet<Chord> iSet(newStart, newEnd, newSymID, symbolMap); return IntervalSequence<Chord>::convert(IntervalEventSet<Chord>(iSet)); }
int GParc ( Gwidget_t *widget, Gpoint_t gc, Gsize_t gs, double ang1, double ang2, Ggattr_t *ap ) { PIXpoint_t pc; PIXsize_t ps; double a1, a2; pc = pdrawtopix (widget, gc), ps = sdrawtopix (widget, gs); setgattr (widget, ap); a1 = ang1 * M_PI / 180, a2 = ang2 * M_PI / 180; if (WPU->gattr.fill) Chord ( GC, pc.x - ps.x, pc.y - ps.y, pc.x + ps.x, pc.y + ps.y, (int) (cos (a1) * ps.x), (int) (sin (a1) * ps.x), (int) (cos (a2) * ps.x), (int) (sin (a2) * ps.x) ); else Arc ( GC, pc.x - ps.x, pc.y - ps.y, pc.x + ps.x, pc.y + ps.y, (int) (cos (a1) * ps.x), (int) (sin (a1) * ps.x), (int) (cos (a2) * ps.x), (int) (sin (a2) * ps.x) ); return 0; }
InstrumentFunctionNoteStacking::ChordTable::ChordTable() : QVector<Chord>() { for( int i = 0; i < static_cast<int>( sizeof s_initTable / sizeof *s_initTable ); i++ ) { push_back( Chord( s_initTable[i].m_name, s_initTable[i].m_semiTones ) ); } }
Chord Chord::getTransposedVersion(int semitones) const { if (semitones == 0) return Chord(getChordText(), getBeat()); QString newRootKey = getTransposedRoot(getRootKey(), semitones); QString newChordText = newRootKey; if (hasLettersAfterRoot()) newChordText += getLettersAfterRoot(); if (hasLastPart()) newChordText += getLastPart(); if (hasBassInversion()) { QString newBassInversionRoot = getTransposedRoot(getBassInversion(), semitones); newChordText += "/" + newBassInversionRoot; } return Chord(newChordText, getBeat()); }
int ChordFile::ReadChords(FILE* f) { char buf[LINE_BUFFER_LENGTH], keyBuf[NOTE_STRING_MAX_LENGTH]; int totalBeats = 0, beats = 0; string chordStyle; while (!feof(f)) { while ((beats = ReadChord(f, buf, keyBuf, &chordStyle)) == -1); totalBeats += beats; if (chordStyle.empty()) chordStyle = CHORDSTYLES_DEFAULT; Heap.Debug<Chord>("Pushing Chord"); Chords.push_back(Chord(Key(keyBuf), beats, chordStyle)); } return totalBeats; }
static void calculate_chord(void) { WINT XStart, YStart, XEnd, YEnd; RECT rect; WINT temp; HPEN hOldPen; HBRUSH hOldBrush; do { rect.left = get_rand(0, xMax); rect.top = get_rand(0, yMax); rect.right = get_rand(0, xMax); rect.bottom = get_rand(0, yMax); if (rect.left > rect.right) { temp = rect.left; rect.left = rect.right; rect.right = temp; } if (rect.top > rect.bottom) { temp = rect.top; rect.top = rect.bottom; rect.bottom = temp; } XStart = get_rand(rect.left, rect.right); YStart = get_rand(rect.top, rect.bottom); XEnd = get_rand(rect.left, rect.right); YEnd = get_rand(rect.top, rect.bottom); hOldPen = SelectObject(hMemDC, create_pen()); hOldBrush = SelectObject(hMemDC, create_brush()); SetBkColor(hMemDC, colors[get_rand(0, num_colors)]); SetBkMode(hMemDC, get_rand(1,3)); SetROP2(hMemDC, get_rand(1,17)); Chord(hMemDC, rect.left, rect.top, rect.right, rect.bottom, XStart, YStart, XEnd, YEnd); DeleteObject(SelectObject(hMemDC, hOldPen)); DeleteObject(SelectObject(hMemDC, hOldBrush)); if (TestSemaphore(&PainterRequired) < 0) { InvalidateRect(hWnd, &rect, FALSE); UpdateWindow(hWnd); } } while ((TestSemaphore(&DemoRun)) && (!TestSemaphore(&SingleRun))); if (!TestSemaphore(&SingleRun)); Signal(&Done); }
PHP_METHOD(WinGdiPath, chord) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; int x1, y1, x2, y2, xr1, yr1, xr2, yr2; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llllllll", &x1, &y1, &x2, &y2, &xr1, &yr1, &xr2, &yr2) == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); RETURN_BOOL(Chord(dc_obj->hdc, x1, y1, x2, y2, xr1, yr1, xr2, yr2)); }
//Adds lines and figures that are on the gradients void DrawGeometry(const HDC& hdc,const RECT& rect) { HPEN hPen; HBRUSH hBrush; hPen=CreatePen(PS_SOLID,2,RGB(30,30,30)); SelectObject(hdc,hPen); hBrush=CreateSolidBrush(RGB(0,180,180)); SelectObject(hdc,hBrush); RoundRect(hdc,rect.right*15/16-10,rect.bottom*7/8,rect.right*15/16+rect.right*1/16-10,rect.bottom*7/8+rect.right*1/16,15,15); DeleteObject(hPen); DeleteObject(hBrush); hPen=CreatePen(PS_DASH,1,RGB(255,0,0)); SelectObject(hdc,hPen); hBrush=CreateSolidBrush(RGB(130,0,130)); SelectObject(hdc,hBrush); Ellipse(hdc,rect.right*3/4,rect.bottom*7/8,rect.right*3/4+rect.right*1/16,rect.bottom*7/8+rect.right*1/16); DeleteObject(hPen); DeleteObject(hBrush); hPen=(HPEN)GetStockObject(NULL_PEN); SelectObject(hdc,hPen); hBrush=CreateSolidBrush(RGB(80,80,0)); SelectObject(hdc,hBrush); Chord(hdc,rect.right*3/4,rect.bottom*3/4,rect.right*3/4+rect.right*1/16,rect.bottom*3/4+rect.right*1/16,5000,1500,100,155); DeleteObject(hPen); DeleteObject(hBrush); hPen=CreatePen(PS_DOT,1,RGB(255,255,255)); SelectObject(hdc,hPen); hBrush=CreateSolidBrush(RGB(30,30,30)); SelectObject(hdc,hBrush); Pie(hdc,rect.right*15/16-10,rect.bottom*3/4,rect.right*15/16+rect.right*1/16-10,rect.bottom*3/4+rect.right*1/16,10,500,100,15); DeleteObject(hPen); DeleteObject(hBrush); SelectObject(hdc,GetStockObject(BLACK_PEN)); SelectObject(hdc,GetStockObject(NULL_BRUSH)); }
ChordProgression ChordProgression::getStretchedVersion(int bpi) const { if (!canBeUsed(bpi)) return ChordProgression();// return a empty progression int newbeatsPerMesure = bpi/measures.size(); int currentBpi = getBeatsPerInterval(); if (currentBpi <= 0)// avoiding division by zero when calculating stretchFactor return ChordProgression(); // invalid bpi, returning empty progression float strechFactor = static_cast<float>(bpi/currentBpi); ChordProgression stretchedProgression; for (ChordProgressionMeasure originalMeasure : measures) { ChordProgressionMeasure newMeasure(newbeatsPerMesure); foreach (const Chord &chord, originalMeasure.getChords()) { int newChordBeat = chord.getBeat() * strechFactor; newMeasure.addChord(Chord(chord.getChordText(), newChordBeat)); } stretchedProgression.addMeasure(newMeasure); } return stretchedProgression; }
VOID CMimicsArcCtrl::DrawCtrl(HDC hDC, CONST RECT *pRect, BOOL bShape) { INT nPt; INT nPts; INT nMode; HPEN hOldPen; HPEN hBorderPen; POINT ptRadial[2]; double fxRadial; double fyRadial; HBRUSH hOldBrush; HBRUSH hInteriorBrush; HBITMAP hInteriorBitmap; LOGBRUSH sInteriorBrush; COLORREF nOldColor[2]; if ((hBorderPen = CreatePen(PS_GEOMETRIC | PS_ENDCAP_FLAT | PS_JOIN_MITER | m_nBorderStyle, m_nBorderSize, GetNearestColor(hDC, (!bShape) ? m_nBorderColor : VGA_COLOR_WHITE)))) { if ((hInteriorBitmap = LoadBitmap(GetModuleInstance(), (m_nInteriorHatch == HT_SOLID || m_nInteriorHatch < 0) ? MAKEINTRESOURCE(IDB_MIMICSOBJECTCTLHATCHSOLID) : ((m_nInteriorHatch == HT_HORIZONTAL) ? MAKEINTRESOURCE(IDB_MIMICSOBJECTCTLHATCHHORIZONTAL) : ((m_nInteriorHatch == HT_VERTICAL) ? MAKEINTRESOURCE(IDB_MIMICSOBJECTCTLHATCHVERTICAL) : ((m_nInteriorHatch == HT_BDIAGONAL) ? MAKEINTRESOURCE(IDB_MIMICSOBJECTCTLHATCHDIAGONALDOWN) : ((m_nInteriorHatch == HT_FDIAGONAL) ? MAKEINTRESOURCE(IDB_MIMICSOBJECTCTLHATCHDIAGONALUP) : ((m_nInteriorHatch == HT_CROSS) ? MAKEINTRESOURCE(IDB_MIMICSOBJECTCTLHATCHCROSS) : ((m_nInteriorHatch == HT_DIAGCROSS) ? MAKEINTRESOURCE(IDB_MIMICSOBJECTCTLHATCHCROSSDIAGONAL) : ((m_nInteriorHatch == HT_LPOINTS) ? MAKEINTRESOURCE(IDB_MIMICSOBJECTCTLHATCHPOINTSLOW) : ((m_nInteriorHatch == HT_MPOINTS) ? MAKEINTRESOURCE(IDB_MIMICSOBJECTCTLHATCHPOINTSMEDIUM) : MAKEINTRESOURCE(IDB_MIMICSOBJECTCTLHATCHPOINTSHIGH)))))))))))) { sInteriorBrush.lbStyle = (m_nInteriorColor != (COLORREF)-1) ? ((m_nInteriorHatch > 0) ? BS_PATTERN : BS_SOLID) : BS_HOLLOW; sInteriorBrush.lbColor = (sInteriorBrush.lbStyle == BS_SOLID) ? GetNearestColor(hDC, (!bShape) ? m_nInteriorColor : VGA_COLOR_WHITE) : 0; sInteriorBrush.lbHatch = (sInteriorBrush.lbStyle == BS_PATTERN) ? (ULONG_PTR)hInteriorBitmap : (ULONG_PTR)NULL; if ((hInteriorBrush = CreateBrushIndirect(&sInteriorBrush)) != (HBRUSH)NULL) { if ((hOldPen = (HPEN)SelectObject(hDC, hBorderPen)) != (HPEN)NULL) { if ((hOldBrush = (HBRUSH)SelectObject(hDC, hInteriorBrush))) { for (nPt = 0, nPts = sizeof(ptRadial) / sizeof(POINT); nPt < nPts; nPt++) { fxRadial = (INT)((double)(pRect->left + pRect->right) / 2.0 + ((double)(pRect->right - pRect->left + pRect->bottom - pRect->top) / 2.0)*cos(2.0*M_PI - m_ptRadial[nPt])); fyRadial = (INT)((double)(pRect->top + pRect->bottom) / 2.0 + ((double)(pRect->right - pRect->left + pRect->bottom - pRect->top) / 2.0)*sin(2.0*M_PI - m_ptRadial[nPt])); ptRadial[nPt].x = (fxRadial >= 0.0) ? (INT)(fxRadial + 0.5) : (INT)(fxRadial - 0.5); ptRadial[nPt].y = (fyRadial >= 0.0) ? (INT)(fyRadial + 0.5) : (INT)(fyRadial - 0.5); } for (nMode = SetBkMode(hDC, OPAQUE), nOldColor[0] = SetBkColor(hDC, GetNearestColor(hDC, (!bShape) ? m_nInteriorColor : VGA_COLOR_WHITE)), nOldColor[1] = SetTextColor(hDC, GetNearestColor(hDC, (!bShape) ? m_nHatchColor : VGA_COLOR_WHITE)); m_nStyle & MIMICSARCCTRL_TYPE_ARC; ) { Arc(hDC, pRect->left + m_nBorderSize / 2, pRect->top + m_nBorderSize / 2, pRect->right - m_nBorderSize / 2 - m_nBorderSize % 2, pRect->bottom - m_nBorderSize / 2 - m_nBorderSize % 2, ptRadial[0].x, ptRadial[0].y, ptRadial[1].x, ptRadial[1].y); break; } for (; m_nStyle & MIMICSARCCTRL_TYPE_PIE; ) { Pie(hDC, pRect->left + m_nBorderSize / 2, pRect->top + m_nBorderSize / 2, pRect->right - m_nBorderSize / 2 - m_nBorderSize % 2, pRect->bottom - m_nBorderSize / 2 - m_nBorderSize % 2, ptRadial[0].x, ptRadial[0].y, ptRadial[1].x, ptRadial[1].y); break; } for (; m_nStyle & MIMICSARCCTRL_TYPE_CHORD; ) { Chord(hDC, pRect->left + m_nBorderSize / 2, pRect->top + m_nBorderSize / 2, pRect->right - m_nBorderSize / 2 - m_nBorderSize % 2, pRect->bottom - m_nBorderSize / 2 - m_nBorderSize % 2, ptRadial[0].x, ptRadial[0].y, ptRadial[1].x, ptRadial[1].y); break; } SetBkMode(hDC, nMode); SetBkColor(hDC, nOldColor[0]); SetTextColor(hDC, nOldColor[1]); SelectObject(hDC, hOldBrush); } SelectObject(hDC, hOldPen); } DeleteObject(hInteriorBrush); } DeleteObject(hInteriorBitmap); } DeletePen(hBorderPen); } }
// Filled Shapes void chrod(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { ACL_ASSERT_BEGIN_PAINT; Chord(g_hmemdc,x1, y1, x2, y2, x3, y3, x4, y4); }
//-------------------------------------------------------------------------- // WindowProc() -> Processa as mensagens enviadas para o programa //-------------------------------------------------------------------------- LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // Variáveis para manipulação da parte gráfica do programa HDC hDC = NULL; PAINTSTRUCT psPaint; // Canetas e pincéis HPEN hPen = NULL; HPEN hPenOld = NULL; HBRUSH hBrush = NULL; HBRUSH hBrushOld = NULL; // Verifica qual foi a mensagem enviada switch(uMsg) { case WM_CREATE: // Janela foi criada { // Retorna 0, significando que a mensagem foi processada corretamente return(0); } break; case WM_PAINT: // Janela (ou parte dela) precisa ser atualizada { // Obtém identificador do DC e preenche PAINTSTRUCT hDC = BeginPaint(hWnd, &psPaint); // Cria e seleciona nova caneta no DC e salva caneta antiga hPen = CreatePen(PS_SOLID, 1, RGB(0, 128, 0)); hPenOld = (HPEN)SelectObject(hDC, hPen); // Cria e seleciona novo pincel no DC e salva pincel antigo hBrush = CreateSolidBrush(RGB(255, 255, 0)); hBrushOld = (HBRUSH)SelectObject(hDC, hBrush); // Desenha elipse Ellipse(hDC, 80, 100, 180, 200); // Desenha combinação de arco e corda Chord(hDC, 10, 10, 100, 100, 80, 80, 50, 25); // Desenha "pizza" Pie(hDC, 110, 10, 200, 100, 180, 80, 150, 25); // Desenha "pizza" no formato Pac-Man Pie(hDC, 210, 10, 400, 200, 380, 50, 380, 130); // Restaura pincel antigo e deleta novo pincel SelectObject(hDC, hBrushOld); DeleteObject(hBrush); // Restaura caneta antiga e deleta nova caneta SelectObject(hDC, hPenOld); DeleteObject(hPen); // Libera DC e valida área EndPaint(hWnd, &psPaint); return(0); } break; case WM_CLOSE: // Janela foi fechada { // Destrói a janela DestroyWindow(hWnd); return(0); } break; case WM_DESTROY: // Janela foi destruída { // Envia mensagem WM_QUIT para o loop de mensagens PostQuitMessage(0); return(0); } break; default: // Outra mensagem { /* Deixa o Windows processar as mensagens que não foram verificadas na função */ return(DefWindowProc(hWnd, uMsg, wParam, lParam)); } } }
void FBlueprintSpawnNodeCommands::RegisterCommands() { const FString ConfigSection = TEXT("BlueprintSpawnNodes"); const FString SettingName = TEXT("Node"); TArray< FString > NodeSpawns; GConfig->GetArray(*ConfigSection, *SettingName, NodeSpawns, GEditorPerProjectIni); for(int32 x = 0; x < NodeSpawns.Num(); ++x) { FString ClassName; if(!FParse::Value(*NodeSpawns[x], TEXT("Class="), ClassName)) { // Could not find a class name, cannot continue with this line continue; } FString CommandLabel; UClass* FoundClass = FindObject<UClass>(ANY_PACKAGE, *ClassName, true); TSharedPtr< FNodeSpawnInfo > InfoPtr; if(FoundClass && FoundClass->IsChildOf(UEdGraphNode::StaticClass())) { // The class name matches that of a UEdGraphNode, so setup a spawn info that can generate UEdGraphNode graph actions UEdGraphNode* GraphNode = Cast<UEdGraphNode>(FoundClass->GetDefaultObject()); CommandLabel = GraphNode->GetNodeTitle(ENodeTitleType::ListView).ToString(); if(CommandLabel.Len() == 0) { CommandLabel = FoundClass->GetName(); } InfoPtr = MakeShareable( new FEdGraphNodeSpawnInfo( FoundClass ) ); } else if(UFunction* FoundFunction = FindObject<UFunction>(ANY_PACKAGE, *ClassName, true)) { // The class name matches that of a function, so setup a spawn info that can generate function graph actions InfoPtr = MakeShareable( new FFunctionNodeSpawnInfo((UFunction*)FoundFunction)); CommandLabel = FoundFunction->GetName(); } else { // Check for a macro graph that matches the passed in class name for (TObjectIterator<UBlueprint> BlueprintIt; BlueprintIt; ++BlueprintIt) { UBlueprint* MacroBP = *BlueprintIt; if(MacroBP->BlueprintType == BPTYPE_MacroLibrary) { // getting 'top-level' of the macros for (TArray<UEdGraph*>::TIterator GraphIt(MacroBP->MacroGraphs); GraphIt; ++GraphIt) { UEdGraph* MacroGraph = *GraphIt; // The class name matches that of a macro, so setup a spawn info that can generate macro graph actions if(MacroGraph->GetName() == ClassName) { CommandLabel = MacroGraph->GetName(); InfoPtr = MakeShareable( new FMacroNodeSpawnInfo(MacroGraph)); } } } } } // If spawn info was created, setup a UI Command for keybinding. if(InfoPtr.IsValid()) { TSharedPtr< FUICommandInfo > CommandInfo; FKey Key; bool bShift = false; bool bCtrl = false; bool bAlt = false; bool bCmd = false; // Parse the keybinding information FString KeyString; if( FParse::Value(*NodeSpawns[x], TEXT("Key="), KeyString) ) { Key = *KeyString; } if( Key.IsValid() ) { FParse::Bool(*NodeSpawns[x], TEXT("Shift="), bShift); FParse::Bool(*NodeSpawns[x], TEXT("Alt="), bAlt); FParse::Bool(*NodeSpawns[x], TEXT("Ctrl="), bCtrl); FParse::Bool(*NodeSpawns[x], TEXT("Cmd="), bCmd); } FInputChord Chord(Key, EModifierKey::FromBools(bCtrl, bAlt, bShift, bCmd)); FText CommandLabelText = FText::FromString( CommandLabel ); FText Description = FText::Format( NSLOCTEXT("BlueprintEditor", "NodeSpawnDescription", "Hold down the bound keys and left click in the graph panel to spawn a {0} node."), CommandLabelText ); FUICommandInfo::MakeCommandInfo( this->AsShared(), CommandInfo, FName(*NodeSpawns[x]), CommandLabelText, Description, FSlateIcon(FEditorStyle::GetStyleSetName(), *FString::Printf(TEXT("%s.%s"), *this->GetContextName().ToString(), *NodeSpawns[x])), EUserInterfaceActionType::Button, Chord ); InfoPtr->CommandInfo = CommandInfo; NodeCommands.Add(InfoPtr); } } TSharedPtr<FNodeSpawnInfo> AddActorRefAction = MakeShareable(new FActorRefSpawnInfo); UI_COMMAND(AddActorRefAction->CommandInfo, "Add Selected Actor Reference(s)", "Spawns node(s) which reference the currently selected actor(s) in the level.", EUserInterfaceActionType::Button, FInputChord(EKeys::R)); NodeCommands.Add(AddActorRefAction); }
void DrawPixels(HWND hwnd) { PAINTSTRUCT ps; RECT r; GetClientRect(hwnd, &r); if (r.bottom == 0) return; HDC hdc = BeginPaint(hwnd, &ps); // pixels for (int i = 0; i < 1000; i++) { int x = rand() % r.right; int y = rand() % r.bottom; SetPixel(hdc, x, y, RGB(rand() % 255, rand() % 255, rand() % 255)); } // rectangle Rectangle(hdc, 30, 30, 240, 140); // pens and lines (stroke) HPEN hPen1 = CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); HPEN hPen2 = CreatePen(PS_DASH, 1, RGB(0, 0, 0)); HPEN hPen3 = CreatePen(PS_DOT, 1, RGB(0, 0, 0)); HPEN hPen4 = CreatePen(PS_DASHDOT, 1, RGB(0, 0, 0)); HPEN hPen5 = CreatePen(PS_DASHDOTDOT, 1, RGB(0, 0, 0)); HPEN holdPen = SelectObject(hdc, hPen1); MoveToEx(hdc, 50, 30, NULL); LineTo(hdc, 200, 30); SelectObject(hdc, hPen2); MoveToEx(hdc, 50, 50, NULL); LineTo(hdc, 200, 50); SelectObject(hdc, hPen2); MoveToEx(hdc, 50, 70, NULL); LineTo(hdc, 200, 70); SelectObject(hdc, hPen3); MoveToEx(hdc, 50, 90, NULL); LineTo(hdc, 200, 90); SelectObject(hdc, hPen4); MoveToEx(hdc, 50, 110, NULL); LineTo(hdc, 200, 110); SelectObject(hdc, holdPen); DeleteObject(hPen1); DeleteObject(hPen2); DeleteObject(hPen3); DeleteObject(hPen4); DeleteObject(hPen5); // brushes and fill HPEN hPen = CreatePen(PS_NULL, 1, RGB(0, 0, 0)); holdPen = SelectObject(hdc, hPen); HBRUSH hBrush1 = CreateSolidBrush(RGB(121, 90, 0)); HBRUSH hBrush2 = CreateSolidBrush(RGB(240, 63, 19)); HBRUSH hBrush3 = CreateSolidBrush(RGB(240, 210, 18)); HBRUSH hBrush4 = CreateSolidBrush(RGB(9, 189, 21)); HBRUSH holdBrush = SelectObject(hdc, hBrush1); int top = 200; int size = 70; Rectangle(hdc, 30, top, 100, top+size); SelectObject(hdc, hBrush2); Rectangle(hdc, 110, top, 180, top+size); SelectObject(hdc, hBrush3); Rectangle(hdc, 30, top+70, 100, top+size+70); SelectObject(hdc, hBrush4); Rectangle(hdc, 110, top+70, 180, top+size+70); SelectObject(hdc, holdPen); SelectObject(hdc, holdBrush); DeleteObject(hPen); DeleteObject(hBrush1); DeleteObject(hBrush2); DeleteObject(hBrush3); DeleteObject(hBrush4); // draw shapes int left = 370; Ellipse(hdc, left, 30, left + 60, 90); RoundRect(hdc, left+80, 30, left+160, 90, 15, 20); Chord(hdc, 270, 30, 360, 90, 270, 45, 360, 45); const POINT polygon[10] = { left+30, 145, left+85, 165, left+105, 110, left+65, 125, left+30, 105 }; const POINT bezier[4] = {280, 160, 320, 160, 325, 110, 350, 110}; Polygon(hdc, polygon, 5); PolyBezier(hdc, bezier, 4); // draw text DWORD color; HFONT hFont, holdFont; static wchar_t *ver1 = L"Not marble, nor the gilded monuments"; static wchar_t *ver2 = L"Of princes, shall outlive this powerful rhyme;"; static wchar_t *ver3 = L"But you shall shine more bright in these contents"; static wchar_t *ver4 = L"Than unswept stone, besmear'd with sluttish time."; static wchar_t *ver5 = L"When wasteful war shall statues overturn,"; static wchar_t *ver6 = L"And broils root out the work of masonry,"; static wchar_t *ver7 = L"Nor Mars his sword, nor war's quick fire shall burn"; static wchar_t *ver8 = L"The living record of your memory."; static wchar_t *ver9 = L"'Gainst death, and all oblivious enmity"; static wchar_t *ver10 = L"Shall you pace forth; your praise shall still find room"; static wchar_t *ver11 = L"Even in the eyes of all posterity"; static wchar_t *ver12 = L"That wear this world out to the ending doom."; static wchar_t *ver13 = L"So, till the judgment that yourself arise,"; static wchar_t *ver14 = L"You live in this, and dwell in lovers' eyes."; color = GetSysColor(COLOR_BTNFACE); SetBkColor(hdc, color); hFont = CreateFontW(15, 0, 0, 0, FW_MEDIUM, 0, 0, 0, 0, 0, 0, 0, 0, L"Georgia"); holdFont = SelectObject(hdc, hFont); left = 270; top = 160; TextOutW(hdc, left, top + 20, ver1, lstrlenW(ver1)); TextOutW(hdc, left, top + 40, ver2, lstrlenW(ver2)); TextOutW(hdc, left, top + 60, ver3, lstrlenW(ver3)); TextOutW(hdc, left, top + 80, ver4, lstrlenW(ver4)); TextOutW(hdc, left, top + 100, ver5, lstrlenW(ver5)); TextOutW(hdc, left, top + 120, ver6, lstrlenW(ver6)); TextOutW(hdc, left, top + 140, ver7, lstrlenW(ver7)); TextOutW(hdc, left, top + 160, ver8, lstrlenW(ver8)); TextOutW(hdc, left, top + 180, ver9, lstrlenW(ver9)); TextOutW(hdc, left, top + 200, ver10, lstrlenW(ver10)); TextOutW(hdc, left, top + 220, ver11, lstrlenW(ver11)); TextOutW(hdc, left, top + 240, ver12, lstrlenW(ver12)); TextOutW(hdc, left, top + 260, ver13, lstrlenW(ver13)); TextOutW(hdc, left, top + 280, ver14, lstrlenW(ver14)); SelectObject(hdc, holdFont); DeleteObject(hFont); // draw bitmap BITMAP bitmap; HDC hdcMem; HGDIOBJ oldBitmap; hdcMem = CreateCompatibleDC(hdc); oldBitmap = SelectObject(hdcMem, hBitmap); GetObject(hBitmap, sizeof(bitmap), &bitmap); BitBlt(hdc, 550, 5, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, oldBitmap); DeleteDC(hdcMem); EndPaint(hwnd, &ps); }
static void DrawOrFillArc( Display *display, Drawable d, GC gc, int x, int y, /* left top */ unsigned int width, unsigned int height, int start, /* start: three-o'clock (deg*64) */ int extent, /* extent: relative (deg*64) */ int fill) /* ==0 draw, !=0 fill */ { HDC dc; HBRUSH brush, oldBrush; HPEN pen, oldPen; TkWinDCState state; int clockwise = (extent < 0); /* non-zero if clockwise */ int xstart, ystart, xend, yend; double radian_start, radian_end, xr, yr; if (d == None) { return; } dc = TkWinGetDrawableDC(display, d, &state); SetROP2(dc, tkpWinRopModes[gc->function]); /* * Compute the absolute starting and ending angles in normalized radians. * Swap the start and end if drawing clockwise. */ start = start % (64*360); if (start < 0) { start += (64*360); } extent = (start+extent) % (64*360); if (extent < 0) { extent += (64*360); } if (clockwise) { int tmp = start; start = extent; extent = tmp; } radian_start = XAngleToRadians(start); radian_end = XAngleToRadians(extent); /* * Now compute points on the radial lines that define the starting and * ending angles. Be sure to take into account that the y-coordinate * system is inverted. */ xr = x + width / 2.0; yr = y + height / 2.0; xstart = (int)((xr + cos(radian_start)*width/2.0) + 0.5); ystart = (int)((yr + sin(-radian_start)*height/2.0) + 0.5); xend = (int)((xr + cos(radian_end)*width/2.0) + 0.5); yend = (int)((yr + sin(-radian_end)*height/2.0) + 0.5); /* * Now draw a filled or open figure. Note that we have to increase the * size of the bounding box by one to account for the difference in pixel * definitions between X and Windows. */ pen = SetUpGraphicsPort(gc); oldPen = SelectObject(dc, pen); if (!fill) { /* * Note that this call will leave a gap of one pixel at the end of the * arc for thin arcs. We can't use ArcTo because it's only supported * under Windows NT. */ SetBkMode(dc, TRANSPARENT); Arc(dc, x, y, (int) (x+width+1), (int) (y+height+1), xstart, ystart, xend, yend); } else { brush = CreateSolidBrush(gc->foreground); oldBrush = SelectObject(dc, brush); if (gc->arc_mode == ArcChord) { Chord(dc, x, y, (int) (x+width+1), (int) (y+height+1), xstart, ystart, xend, yend); } else if (gc->arc_mode == ArcPieSlice) { Pie(dc, x, y, (int) (x+width+1), (int) (y+height+1), xstart, ystart, xend, yend); } DeleteObject(SelectObject(dc, oldBrush)); } DeleteObject(SelectObject(dc, oldPen)); TkWinReleaseDrawableDC(d, dc, &state); }
/*************************************************************************** * bConicCommon - The mother of all conic translations. * They are Arc, Chord, Pie, Ellipse, Rectangle and RoundRect. **************************************************************************/ BOOL bConicCommon (PLOCALDC pLocalDC, INT x1, INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4, DWORD mrType) { SHORT sx1, sx2, sx3, sx4, sy1, sy2, sy3, sy4 ; LONG nPointls ; POINTL aptl[4] ; BOOL b ; // If we're recording the drawing orders for a path // then just pass the drawing order to the helper DC. // Do not emit any Win16 drawing orders. if (pLocalDC->flags & RECORDING_PATH) { switch(mrType) { case EMR_ARC: b = Arc(pLocalDC->hdcHelper, x1, y1, x2, y2, x3, y3, x4, y4) ; break ; case EMR_CHORD: b = Chord(pLocalDC->hdcHelper, x1, y1, x2, y2, x3, y3, x4, y4) ; break ; case EMR_ELLIPSE: b = Ellipse(pLocalDC->hdcHelper, x1, y1, x2, y2) ; break ; case EMR_PIE: b = Pie(pLocalDC->hdcHelper, x1, y1, x2, y2, x3, y3, x4, y4) ; break ; case EMR_RECTANGLE: b = Rectangle(pLocalDC->hdcHelper, x1, y1, x2, y2) ; break ; case EMR_ROUNDRECT: b = RoundRect(pLocalDC->hdcHelper, x1, y1, x2, y2, x3, y3) ; break ; default: RIP("MF3216: bConicCommon, bad mrType"); break ; } ASSERTGDI(b, "MF3216: bConicCommon, in path render failed\n") ; return(b) ; } // Do the transformations. // And emit the Win16 drawing orders. if (pLocalDC->flags & STRANGE_XFORM) { b = bRenderCurveWithPath(pLocalDC, (LPPOINT) NULL, (PBYTE) NULL, 0, x1, y1, x2, y2, x3, y3, x4, y4, 0, 0.0f, 0.0f, mrType); return(b); } // Do the simple transform case. // Compute the number of points nPointls = (LONG) (sizeof(aptl) / sizeof(POINTL)) ; // Assign all the coordinates into an array for conversion. aptl[0].x = x1 ; aptl[0].y = y1 ; aptl[1].x = x2 ; aptl[1].y = y2 ; aptl[2].x = x3 ; aptl[2].y = y3 ; aptl[3].x = x4 ; aptl[3].y = y4 ; // Take care of the arc direction. switch (mrType) { case EMR_ARC: case EMR_CHORD: case EMR_PIE: vDoArcReflection(pLocalDC, &aptl[2]) ; break ; default: break ; } // Do the Record-time World to Play-time Page transformations. // The radial definitions need only a world to page xform, // and the ellipse definitions for roundrects only require // a magnitude transformation. if (mrType != EMR_ROUNDRECT) { b = bXformRWorldToPPage(pLocalDC, (PPOINTL) aptl, nPointls) ; if (!b) goto exit1 ; } else { /* For roundrects do a Record-time-World to Play-time-Page transform of the bounding box only. Then a magnatude only transform of the corner ellipse definitions. */ b = bXformRWorldToPPage(pLocalDC, (PPOINTL) aptl, 2) ; if (!b) goto exit1 ; aptl[2].x = iMagnitudeXform(pLocalDC, aptl[2].x, CX_MAG) ; aptl[2].y = iMagnitudeXform(pLocalDC, aptl[2].y, CY_MAG) ; aptl[3].x = iMagnitudeXform(pLocalDC, aptl[3].x, CX_MAG) ; aptl[3].y = iMagnitudeXform(pLocalDC, aptl[3].y, CY_MAG) ; } // The bounding boxes for // all the conics and rectangles that are handled by this // common routine are inclusive-inclusive, and they must // be transformed to the inclusive-exclusive Win16 form. b = bIncIncToIncExcXform(pLocalDC, (PRECTL) &aptl[0]) ; if (!b) goto exit1 ; // Assign the converted coordinates variables suited to // the Win16 metafile. sx1 = LOWORD(aptl[0].x) ; sy1 = LOWORD(aptl[0].y) ; sx2 = LOWORD(aptl[1].x) ; sy2 = LOWORD(aptl[1].y) ; sx3 = LOWORD(aptl[2].x) ; sy3 = LOWORD(aptl[2].y) ; sx4 = LOWORD(aptl[3].x) ; sy4 = LOWORD(aptl[3].y) ; // Emit the Win16 drawing orders to the Win16 metafile. switch(mrType) { case EMR_ARC: b = bEmitWin16Arc(pLocalDC, sx1, sy1, sx2, sy2, sx3, sy3, sx4, sy4) ; break ; case EMR_CHORD: b = bEmitWin16Chord(pLocalDC, sx1, sy1, sx2, sy2, sx3, sy3, sx4, sy4) ; break ; case EMR_ELLIPSE: b = bEmitWin16Ellipse(pLocalDC, sx1, sy1, sx2, sy2) ; break ; case EMR_PIE: b = bEmitWin16Pie(pLocalDC, sx1, sy1, sx2, sy2, sx3, sy3, sx4, sy4) ; break ; case EMR_RECTANGLE: b = bEmitWin16Rectangle(pLocalDC, sx1, sy1, sx2, sy2) ; break ; case EMR_ROUNDRECT: b = bEmitWin16RoundRect(pLocalDC, sx1, sy1, sx2, sy2, sx3, sy3) ; break ; default: RIP("MF3216: bConicCommon, bad mrType"); break ; } exit1: return (b) ; }