void insertRect(TY** ppY,const TRect& rect){ TY* pY=*ppY; if (rect.y1 <= pY->y0){ //之前 insertAtFront(ppY,rect); }else if (rect.y0 >= pY->y1){ //之后 insertRectNext(pY,rect); }else if (getIsCover(pY,rect)){ //包含 return; }else{ //相交 TRect nRect(rect); if (nRect.y1 > pY->y1){ //长出一截的部分交给下一个Y TRect backRect(nRect.x0,pY->y1,nRect.x1,nRect.y1); nRect.y1=pY->y1; insertRectNext(pY,backRect); }else if (nRect.y1< pY->y1){ //短一截,分裂Y clipY(pY,nRect.y1); } //nRect.y1==pY->y1 if (nRect.y0 < pY->y0){ TRect frontRect(nRect.x0,nRect.y0,nRect.x1,pY->y0); nRect.y0=pY->y0; YAddAX(pY,nRect.x0,nRect.x1); insertAtFront(ppY,frontRect); }else if (nRect.y0< pY->y0){ clipY(pY,nRect.y0); YAddAX(pY->nextY,nRect.x0,nRect.x1); }else{ //nRect.y0== pY->y0 YAddAX(pY,nRect.x0,nRect.x1); } } }
void UIScrollBar::onPaint(UIPainter& painter) { RectangleShape backRect(FloatRect(0.f, 0.f, size.x, size.y), Color(121, 121, 121)); painter.graphicsDevice->setModelMatrix(painter.baseMatrix * backRect.getTransform().getMatrix()); painter.graphicsDevice->draw(backRect); if (linkedView) { paddleHeight = linkedView->size.y / linkedView->childrenRect().height; paddleHeight *= size.y; } RectangleShape backRect2(FloatRect(2.f, 2.f + paddleOffset, size.x - 4.f, paddleHeight - 4.f), Color(21, 21, 21)); painter.graphicsDevice->setModelMatrix(painter.baseMatrix * backRect2.getTransform().getMatrix()); painter.graphicsDevice->draw(backRect2); }
void WTextSourceViewerLine::paintEvent ( QPaintEvent * ev_p ) { QPainter p(this); bool place_for_comment=!commented_lines.isEmpty(); p.setRenderHint(QPainter::SmoothPixmapTransform ); p.setRenderHint( QPainter::Antialiasing); p.setClipRect(ev_p->rect()); p.translate(1,-translation_y); p.setFont(font()); p.setPen(QPen(Qt::black,0)); QAbstractTextDocumentLayout::PaintContext context; QRect r=ev_p->rect(); if (text_document_p) { QRectF lineRect; int last_line=0; QPointF folding_pos_close; QPointF folding_pos_open_start; QPointF folding_pos_open_end; bool has_folding_close=false; bool has_folding_open=false; bool last_block_contains_instrumentation=true; for (QTextBlock textBlock=text_document_p->begin(); textBlock!=text_document_p->end(); textBlock=textBlock.next()) { TextSourceInstrumentationData *instrumentationData=dynamic_cast<TextSourceInstrumentationData*> (textBlock.userData()); if (instrumentationData) { int current_line = instrumentationData->current_line; lineRect=text_document_p->documentLayout()->blockBoundingRect(textBlock); QRectF line_text_area(char_space*(2.0f+ (place_for_comment?1:0) ),lineRect.top(),width()-char_space*2.0f,lineRect.height()); QRectF comment_area(char_space*2,lineRect.top(),img_comment_scaled.width(),img_comment_scaled.height()); bool instrumentation_point=false; for (QVector<TextSourceInstrumentationData::InstrumentationData>::const_iterator it=instrumentationData->instrumentations.begin();it!=instrumentationData->instrumentations.end();++it) { Instrumentation::status_t st=(*it).status(instrumentationData->coverage_level,instrumentationData->coverage_method); if ( st != Instrumentation::STATUS_NONE ) { instrumentation_point=true; break; } } if (instrumentation_point) { QRectF backRect(0,lineRect.top(),width(),lineRect.height()); p.drawText(line_text_area,Qt::AlignVCenter|Qt::AlignLeft,QString::number(current_line)); last_block_contains_instrumentation=true; if (has_folding_open) drawFoldingLineVisible(p,folding_pos_open_start,folding_pos_open_end); bool current_line_has_comment=commented_lines.contains(current_line); if (current_line_has_comment) p.drawImage(comment_area,img_comment_scaled); if (last_line+1!=current_line) { if (has_folding_close) drawFoldingLineHidden(p,folding_pos_close); if (current_line_has_comment || !place_for_comment) folding_pos_close.setX(char_space*1.5f); else folding_pos_close.setX(char_space*2.5f); folding_pos_close.setY((lineRect.bottom()+lineRect.top())/2); drawFoldingLineHidden(p,folding_pos_close); } else { if (current_line_has_comment || !place_for_comment) folding_pos_close.setX(char_space*1.5f); else folding_pos_close.setX(char_space*2.5f); folding_pos_close.setY((lineRect.bottom()+lineRect.top())/2); } has_folding_open=false; has_folding_close=true; } else { if ( (has_folding_close) && (last_line+1!=current_line) ) drawFoldingLineHidden(p,folding_pos_close); if (place_for_comment) folding_pos_open_end.setX(char_space*2.5f); else folding_pos_open_end.setX(char_space*1.5f); folding_pos_open_end.setY((lineRect.bottom()+lineRect.top())/2); if (last_block_contains_instrumentation) folding_pos_open_start=folding_pos_open_end; p.drawText(line_text_area,Qt::AlignVCenter|Qt::AlignLeft,QString::number(current_line)); last_block_contains_instrumentation=false; has_folding_close=false; has_folding_open=true; } last_line=current_line; } } if (has_folding_close) drawFoldingLineHidden(p,folding_pos_close); if (has_folding_open) drawFoldingLineVisible(p,folding_pos_open_start,folding_pos_open_end); } r.translate(-1,+translation_y); context.clip=r; }
OnPostFrontendRender.Connect([] () { if (!g_consoleFlag) { return; } static bool stringRectSet = false; static CRect stringRect; if (!stringRectSet) { TheFonts->GetStringMetrics(L"a", 16.0f, 1.0f, "Lucida Console", stringRect); } CRect backRect(0.0f, 0.0f, GetScreenResolutionX(), (16.0f * 25) + 16.0f); CRGBA backColor(0, 0x2b, 0x36, 220); CRGBA frontColor(0xee, 0xe8, 0xd5); TheFonts->DrawRectangle(backRect, backColor); backRect.SetRect(backRect.fX1, backRect.fY2, backRect.fX2, backRect.fY2 + 5.0f); backColor.red *= 0.8; backColor.green *= 0.8; backColor.blue *= 0.8; backColor.alpha = 250; TheFonts->DrawRectangle(backRect, backColor); for (int i = 0; i < 25; i++) {
CRect TranscriptWindow::DrawButton( CDC& dc, CRect& rect, bool centre, const char* text, Button button, bool enable) { // Select the font and measure the text in it CFont* oldFont = dc.SelectObject(theApp.GetFont(InformApp::FontDisplay)); CSize size = dc.GetTextExtent(text); // Adjust the width of the button if (centre) { rect.left = rect.right-(size.cx/2)-m_layout.margin.cx; rect.right = rect.left+size.cx+m_layout.margin.cx*2; } else rect.left = rect.right-size.cx-m_layout.margin.cx*2; // Determine the button's state CPoint mousePoint = GetCurrentMessage()->pt; ScreenToClient(&mousePoint); bool over = (rect.PtInRect(mousePoint) != 0); bool down = (m_buttonDown == button); if (theOS.IsAppThemed()) { // Open the button theme HTHEME theme = theOS.OpenThemeData(this,L"Button"); if (theme) { UINT state = PBS_NORMAL; if (!enable) state = PBS_DISABLED; else if (over && down) state = PBS_PRESSED; else if (down) state = PBS_HOT; else if (over && (m_buttonDown == Button())) state = PBS_HOT; // Draw the themed control frame theOS.DrawThemeBackground(theme,&dc,BP_PUSHBUTTON,state,rect); // Get the background size CRect backRect(rect); theOS.GetThemeBackgroundContentRect(theme,&dc,BP_PUSHBUTTON,state,backRect); // Draw the themed button text CStringW textW(text); theOS.DrawThemeText(theme,&dc,BP_PUSHBUTTON,state,textW, DT_CENTER|DT_VCENTER|DT_SINGLELINE,DTT_GRAYED,backRect); // Close the button theme theOS.CloseThemeData(theme); } } else { UINT state = DFCS_BUTTONPUSH; if (!enable) state |= DFCS_INACTIVE; else if (over && down) state |= DFCS_PUSHED; // Draw the control background dc.DrawFrameControl(rect,DFC_BUTTON,state); // Work out the bounding rectangle for the button text CRect textRect(rect); textRect.DeflateRect((rect.Width()-size.cx)/2,(rect.Height()-size.cy)/2); if (state & DFCS_PUSHED) { textRect.top++; textRect.left++; } // Draw the button text dc.DrawState(textRect.TopLeft(),textRect.Size(),text, (state & DFCS_INACTIVE) ? DSS_DISABLED : DSS_NORMAL,TRUE,0,(HBRUSH)0); } // Select the previous font dc.SelectObject(oldFont); // Store the button rectangle if (enable) m_buttons.push_back(std::make_pair(rect,button)); // Return the button rectangle return rect; }
void TranscriptWindow::OnDraw(CDC* pDC) { CRect clientRect; GetClientRect(clientRect); CDC dc; dc.CreateCompatibleDC(pDC); // Create an off-screen bitmap for drawing CDibSection bitmap; if (bitmap.CreateBitmap(pDC->GetSafeHdc(),clientRect.Width(),clientRect.Height()) == FALSE) return; CBitmap* oldBitmap = CDibSection::SelectDibSection(dc,&bitmap); dc.SetBkMode(TRANSPARENT); dc.FillSolidRect(clientRect,theApp.GetColour(InformApp::ColourBack)); if (m_skein->IsActive()) { CFont* oldFont = dc.SelectObject(theApp.GetFont(InformApp::FontDisplay)); CPen linePen(PS_SOLID,1,theApp.GetColour(InformApp::ColourBorder)); CPen* oldPen = dc.SelectObject(&linePen); int y = 0; int yinput = m_layout.fontSize.cy+(2*m_layout.margin.cy); // If the transcript is taller than the window, work out the drawing origin if (GetHeight() > clientRect.Height()) { SCROLLINFO scroll; ::ZeroMemory(&scroll,sizeof scroll); scroll.cbSize = sizeof scroll; GetScrollInfo(SB_VERT,&scroll); y -= scroll.nPos; } // Clear the map of visible buttons and expected texts m_buttons.clear(); m_expecteds.clear(); // Loop over the transcript nodes std::deque<NodeLayout>::const_iterator nodeIt; for (nodeIt = m_layout.nodes.begin(); nodeIt != m_layout.nodes.end(); ++nodeIt) { const NodeLayout& nl = *nodeIt; // Is this node visible? CRect nodeRect(0,y,1,y+m_layout.fontSize.cy+nl.height+(4*m_layout.margin.cy)+1); CRect intersection; if (intersection.IntersectRect(nodeRect,clientRect) == FALSE) { // Not visible, so increase the y position and try the next node y += yinput+nl.height+(2*m_layout.margin.cy); continue; } // Get the text associated with the node const CStringW& transcript = nl.node->GetTranscriptText(); const CStringW& expected = nl.node->GetExpectedText(); const CStringW& line = nl.node->GetLine(); // Fill in the background of the input line dc.FillSolidRect(0,y+1,clientRect.Width(),yinput, theApp.GetColour(InformApp::ColourTransInput)); // Fill in the background of the transcript text COLORREF back; if (transcript.IsEmpty()) back = theApp.GetColour(InformApp::ColourTransUnset); else { back = theApp.GetColour(nl.node->GetChanged() ? InformApp::ColourTransDiffers : InformApp::ColourTransSame); } CRect backRect(0,y+yinput,m_layout.columnWidth, y+m_layout.fontSize.cy+nl.height+(4*m_layout.margin.cy)); dc.FillSolidRect(backRect,back); // Fill in the background of the expected text if (expected.IsEmpty()) back = theApp.GetColour(InformApp::ColourTransUnset); else { switch (nl.node->GetDiffers()) { case Skein::Node::ExpectedSame: back = theApp.GetColour(InformApp::ColourTransSame); break; case Skein::Node::ExpectedNearlySame: back = RGB(255,255,127); break; case Skein::Node::ExpectedDifferent: back = theApp.GetColour(InformApp::ColourTransDiffers); break; default: ASSERT(FALSE); back = theApp.GetColour(InformApp::ColourTransDiffers); break; } } backRect.OffsetRect(m_layout.columnWidth+1,0); dc.FillSolidRect(backRect,Brighter(back)); // If this is the first node in the transcript, draw a horizontal line at the top if (nl.node == m_skein->GetRoot()) { dc.MoveTo(0,y); dc.LineTo(clientRect.Width(),y); } // Draw a horizontal line below the node's input dc.MoveTo(0,y+yinput); dc.LineTo(clientRect.Width(),y+yinput); // Draw a final horizontal line below the text boxes dc.MoveTo(0,y+yinput+nl.height+(2*m_layout.margin.cy)); dc.LineTo(clientRect.Width(),y+yinput+nl.height+(2*m_layout.margin.cy)); // Draw a dividing line between the two text boxes dc.MoveTo(m_layout.columnWidth,y+yinput); dc.LineTo(m_layout.columnWidth,y+yinput+nl.height+(2*m_layout.margin.cy)); // If this is the last played knot in the skein, draw a yellow border around it if (nl.node == m_skeinPlayed) { CRect backRect(0,y,clientRect.Width(), y+m_layout.fontSize.cy+nl.height+(4*m_layout.margin.cy)); DrawInsideRect(dc,backRect,CSize(m_layout.margin.cx*3/4,m_layout.margin.cy*7/8), theApp.GetColour(InformApp::ColourTransPlayed)); } // If this is the knot selected in the skein, draw a blue border around it if (nl.node == m_skeinSelected) { CRect backRect(0,y,clientRect.Width(), y+m_layout.fontSize.cy+nl.height+(4*m_layout.margin.cy)); DrawInsideRect(dc,backRect,CSize(m_layout.margin.cx*3/8,m_layout.margin.cy*7/16), theApp.GetColour(InformApp::ColourTransSelect)); } // Draw the buttons at the end of the input line, and store their positions int btnHeight = m_layout.fontSize.cy+m_layout.margin.cy; CRect btnRect( CPoint(clientRect.Width()-(m_layout.margin.cy/2),y+(m_layout.margin.cy/2)), CSize(0,btnHeight)); btnRect = DrawButton(dc,btnRect,false,"Show knot",Button(nl.node,ButtonShow),true); btnRect.right = btnRect.left-(m_layout.margin.cy/2); DrawButton(dc,btnRect,false,"Play to here",Button(nl.node,ButtonPlay),true); // Write the node's input dc.SetTextColor(theApp.GetColour(InformApp::ColourText)); CRect textRect(m_layout.margin.cx,y+m_layout.margin.cy, btnRect.left-m_layout.margin.cx,y+yinput); theOS.DrawText(&dc,line,line.GetLength(),textRect,DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS); // Draw the 'bless' button, and store its position y += yinput; btnRect.right = m_layout.columnWidth; btnRect.top = y+(((nl.height+(2*m_layout.margin.cy))-btnHeight)/2); btnRect.bottom = btnRect.top+btnHeight; DrawButton(dc,btnRect,true,"Bless",Button(nl.node,ButtonBless),nl.node->CanBless()); // Write the text in the text boxes textRect = CRect(m_layout.margin.cx,y+m_layout.margin.cy, m_layout.columnWidth-m_layout.centreMargin,y+m_layout.margin.cy+nl.height); DrawText(dc,textRect,transcript,nl.node->GetTranscriptDiffs()); textRect.OffsetRect(m_layout.columnWidth+m_layout.centreMargin-m_layout.margin.cx,0); DrawText(dc,textRect,expected,nl.node->GetExpectedDiffs()); textRect.InflateRect(theApp.MeasureFont(m_edit.GetFont()).cx/4,0); m_expecteds.push_back(std::make_pair(backRect,Expected(nl.node,textRect))); // Advance the y position y += nl.height+(2*m_layout.margin.cy); } dc.SelectObject(oldPen); dc.SelectObject(oldFont); // If the edit window is visible, exclude the area under it to reduce flicker if (m_edit.IsWindowVisible()) { CRect editRect; m_edit.GetWindowRect(&editRect); ScreenToClient(&editRect); pDC->ExcludeClipRect(editRect); } } // Copy to the on-screen device context pDC->BitBlt(0,0,clientRect.Width(),clientRect.Height(),&dc,0,0,SRCCOPY); dc.SelectObject(oldBitmap); }