void RenderLine(uint8 *pStart, float xOff, float vLineTop, float vLineBottom, int nCursor, int nSelStart, int nSelEnd, View *pcView, bool bSelected) { static char zLine[9]; sprintf(zLine, "%08x", (uint32)(pStart - GetBuffer())); Rect cRect(xOff + GetX() + 2, vLineTop, xOff + GetX() + GetWidth(), vLineBottom); pcView->DrawText(cRect, zLine); }
void TextEditor::paintEvent(QPaintEvent *e) { int width = viewport()->width(), height = fontMetrics().height(); QRect cRect(0, cursorRect().y(), viewport()->width(), height); const int cursorPos = textCursor().block().position(); QPainter p(viewport()); // good for highlighting line during paused execution: p.fillRect(cRect, QBrush(QColor(215, 227, 255))); if (m_pc != NULL && m_program->getStatus() == PAUSED) { QColor highlightColor = QColor(255, 240, 117); // yellow highlightLine(p, m_pc, highlightColor, width, height); // highlightColor = highlightColor.lighter(105); // cerr << "<<<Painting: size = " << m_lastInstructions.size() << endl; foreach(ParseNode *parseNode, m_lastInstructions) { highlightColor = highlightColor.lighter(120); if (highlightColor == Qt::white) { //cerr << "\t" << i << " painted!\n"; break; } if (!parseNode->isValid()) continue; const QTextBlock *block = parseNode->getTextBlock(); if (block != NULL && block->isValid() && parseNode != m_pc && cursorPos != block->position()) highlightLine(p, parseNode, highlightColor, width, height); }
void RenderLine(uint8 *pStart, float xOff, float vLineTop, float vLineBottom, int nCursor, int nSelStart, int nSelEnd, View *pcView, bool bSelected) { Color32_s sCursCol(40,40,40); Color32_s sCursLineCol(255,235,186); if( ! bSelected ) { sCursCol = lighten_color(sCursCol); sCursLineCol = lighten_color(sCursLineCol); } float vCharWidth = GetCharWidth(); float vCharHeight = GetCharHeight(); uint8 *pEnd = GetBuffer() + GetBufferLength(); static char zLine[(3 * BYTES_PER_LINE) + 1]; uint8 *p = pStart; for( int x = 0; x < 3 * BYTES_PER_LINE; x+=3 ) { if( p < pEnd ) { zLine[x] = get_nibble_char(*p, true); zLine[x + 1] = get_nibble_char(*p, false); p++; } else { zLine[x] = ' '; zLine[x + 1] = ' '; } zLine[x + 2] = ' '; } Rect cRect(xOff + GetX() + 2, vLineTop, xOff + GetX() + GetWidth() - 2, vLineBottom); pcView->SetFgColor(Color32_s(0,0,0)); if( nSelStart < 0 ) { if( nCursor >= 0 ) pcView->FillRect(cRect, sCursLineCol); pcView->DrawText(cRect, zLine); if( nCursor >= 0 ) { float vCursorX = cRect.left + (3 * vCharWidth * nCursor); if( m_bSecondChar ) vCursorX += vCharWidth; pcView->SetFgColor(sCursCol); pcView->DrawLine(Point(vCursorX, vLineTop), Point(vCursorX, vLineBottom)); vCursorX++; pcView->DrawLine(Point(vCursorX, vLineTop), Point(vCursorX, vLineBottom)); } } else { IPoint cSel1((int)(nSelStart * 3 * vCharWidth), (int)vCharHeight); IPoint cSel2((int)((nSelEnd * 3 * vCharWidth) + (vCharWidth * 2)), (int)vCharHeight); pcView->DrawSelectedText(cRect, zLine, cSel1, cSel2, SEL_CHAR); } }
void BitmapView::Erase( const BRect& cFrame ) { if ( m_pcBitmap != NULL ) { BRect cBmBounds = m_pcBitmap->Bounds(); int nWidth = int(cBmBounds.Width()) + 1; int nHeight = int(cBmBounds.Height()) + 1; SetDrawingMode( B_OP_COPY ); for ( int nDstY = int(cFrame.top) ; nDstY <= cFrame.bottom ; ) { int y = nDstY % nHeight; int nCurHeight = min( int(cFrame.bottom) - nDstY + 1, nHeight - y ); for ( int nDstX = int(cFrame.left) ; nDstX <= cFrame.right ; ) { int x = nDstX % nWidth; int nCurWidth = min( int(cFrame.right) - nDstX + 1, nWidth - x ); BRect cRect( 0, 0, nCurWidth - 1, nCurHeight - 1 ); DrawBitmap( m_pcBitmap, cRect.OffsetByCopy( x, y ), cRect.OffsetByCopy( nDstX, nDstY ) ); nDstX += nCurWidth; } nDstY += nCurHeight; } } else { rgb_color color = { 0x00, 0x60, 0x6b, 0}; SetHighColor(color); FillRect(cFrame); } }
void __fastcall TfrmMainFormServer::lstModulesDrawItem( TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State) { TRect cRect(0, 0, lstModules->Width, lstModules->Height); TCanvas* pCanvas = ((TListBox*)Control)->Canvas; pCanvas->FillRect(Rect); //This clears the rect Graphics::TBitmap* bitmap = new Graphics::TBitmap(); AnsiString moduleName = lstModules->Items->Strings[Index]; if(Index == 0){ imgList->GetBitmap(1, bitmap); //table image }else{ imgList->GetBitmap(0, bitmap); //table image } pCanvas->Draw(Rect.Left + 1, Rect.Top, bitmap); delete bitmap; pCanvas->TextOut(Rect.Left + 22, Rect.Top + 2, moduleName); }
BOOL GetRegionfromBitmap(RECT r, CRgn *pRgn, CBitmap *pBitmap, COLORREF keyColor, COLORREF cTolerance) { if (!pBitmap) return FALSE; if (!pRgn) return FALSE; BYTE lr = (BYTE)max(0, (int)GetRValue(keyColor) - (int)GetRValue(cTolerance)); BYTE lg = (BYTE)max(0, (int)GetGValue(keyColor) - (int)GetGValue(cTolerance)); BYTE lb = (BYTE)max(0, (int)GetBValue(keyColor) - (int)GetBValue(cTolerance)); BYTE hr = (BYTE)min((int)0xff, (int)GetRValue(keyColor) + (int)GetRValue(cTolerance)); BYTE hg = (BYTE)min((int)0xff, (int)GetGValue(keyColor) + (int)GetGValue(cTolerance)); BYTE hb = (BYTE)min((int)0xff, (int)GetBValue(keyColor) + (int)GetBValue(cTolerance)); CDC memDC; CBitmap *pOldMemBmp = NULL; CRect cRect(r); int x, y; int n=0; //number of transparent pixels CRgn rgnTemp; memDC.CreateCompatibleDC(NULL); pOldMemBmp = memDC.SelectObject(pBitmap); pRgn->CreateRectRgn(0, 0, cRect.Width(), cRect.Height()); //COLORREF m_Color = memDC.GetPixel(0, 0); for (x = 0; x <= r.right - r.left; x++) { for (y = 0; y <= r.bottom - r.top; y++) { COLORREF cr = memDC.GetPixel(x,y); BYTE b = GetRValue(cr); if (lr <= b && b <= hr) { b = GetGValue(cr); if (lg <= b && b <= hg) { b = GetBValue(cr); if (lb <= b && b <= hb) { rgnTemp.CreateRectRgn(x, y, x + 1, y + 1); pRgn->CombineRgn(pRgn, &rgnTemp, RGN_XOR); rgnTemp.DeleteObject(); ++n; } } } } } if (pOldMemBmp) memDC.SelectObject(pOldMemBmp); memDC.DeleteDC(); return n > 0; }
QRect QPixmap::rect() const { kdDebug(10) << "QPixmap::" << __FUNCTION__ << "()" << endl; if ( d->m_pcBitmap != NULL ) { BRect cBounds = d->m_pcBitmap->Bounds(); QRect cRect( QPoint( cBounds.left, cBounds.top ), QPoint( cBounds.right, cBounds.bottom ) ); return( cRect ); } else { return( QRect( 0, 0, 0, 0 ) ); } }
cPixmap *cTrueColorDemo::CreateTextPixmap(const char *s, int Line, int Layer, tColor ColorFg, tColor ColorBg, const cFont *Font) { const int h = Font->Height(s); int w = Font->Width(s); cPixmap *Pixmap = osd->CreatePixmap(Layer, cRect((osd->Width() - w) / 2, Line, w, h)); if (Pixmap) { Pixmap->Clear(); Pixmap->SetAlpha(0); Pixmap->DrawText(cPoint(0, 0), s, ColorFg, ColorBg, Font); } return Pixmap; }
void RenderLine(uint8 *pStart, float xOff, float vLineTop, float vLineBottom, int nCursor, int nSelStart, int nSelEnd, View *pcView, bool bSelected) { Color32_s sCursCol(40,40,40); Color32_s sCursLineCol(255,235,186); if( ! bSelected ) { sCursCol = lighten_color(sCursCol); sCursLineCol = lighten_color(sCursLineCol); } float vCharWidth = GetCharWidth(); float vCharHeight = GetCharHeight(); uint8 *pEnd = GetBuffer() + GetBufferLength(); static char zLine[(BYTES_PER_LINE) + 1]; for( int x = 0; x < BYTES_PER_LINE; x++ ) { uint8 *p = pStart + x; zLine[x] = p >= pEnd || *p < 32 || *p > 126?'.':*p; } Rect cRect(xOff + GetX() + 2, vLineTop, xOff + GetX() + GetWidth() - 2, vLineBottom); pcView->SetFgColor(Color32_s(0,0,0)); if( nSelStart < 0 ) { if( nCursor >= 0 ) pcView->FillRect(cRect, sCursLineCol); pcView->DrawText(cRect, zLine); if( nCursor >= 0 ) { float vCursorX = cRect.left + (vCharWidth * nCursor); pcView->SetFgColor(sCursCol); pcView->DrawLine(Point(vCursorX, vLineTop), Point(vCursorX, vLineBottom)); vCursorX++; pcView->DrawLine(Point(vCursorX, vLineTop), Point(vCursorX, vLineBottom)); } } else { IPoint cSel1((int)(nSelStart * vCharWidth), (int)vCharHeight); IPoint cSel2((int)((nSelEnd * vCharWidth) + 1), (int)vCharHeight); pcView->DrawSelectedText(cRect, zLine, cSel1, cSel2, SEL_CHAR); } }
int CNotifyWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; // TODO: この位置に固有の作成用コードを追加してください CRect cRect( 0, 0, lpCreateStruct->cx, lpCreateStruct->cy); CString cStrTitle; GetWindowText( cStrTitle); CDC* pcDC = GetDC(); pcDC->DrawText( cStrTitle, cRect, DT_LEFT | DT_CALCRECT | DT_SINGLELINE); ReleaseDC( pcDC); CalcWindowRect( cRect); MoveWindow( cRect); SetTimer( 5500, 500, NULL); return 0; }
QwtArray<QwtDoubleInterval> QwtCircleClipper::clipCircle( const QwtDoublePoint &pos, double radius) const { QList<QwtDoublePoint> points; for ( int edge = 0; edge < NEdges; edge++ ) points += cuttingPoints((Edge)edge, pos, radius); QwtArray<QwtDoubleInterval> intv; if ( points.size() <= 0 ) { QwtDoubleRect cRect(0, 0, 2 * radius, 2* radius); cRect.moveCenter(pos); if ( contains(cRect) ) intv += QwtDoubleInterval(0.0, 2 * M_PI); } else { QList<double> angles; for ( int i = 0; i < points.size(); i++ ) angles += toAngle(pos, points[i]); qSort(angles); const int in = contains(qwtPolar2Pos(pos, radius, angles[0] + (angles[1] - angles[0]) / 2)); if ( in ) { for ( int i = 0; i < angles.size() - 1; i += 2) intv += QwtDoubleInterval(angles[i], angles[i+1]); } else { for ( int i = 1; i < angles.size() - 1; i += 2) intv += QwtDoubleInterval(angles[i], angles[i+1]); intv += QwtDoubleInterval(angles.last(), angles.first()); } } return intv; }
void ScrollView::scrollBy(int dx, int dy) { wxWindow* win = nativeWindow(); if (!win) return; wxPoint scrollOffset = m_data->viewStart; wxPoint orig(scrollOffset); wxPoint newScrollOffset = scrollOffset + wxPoint(dx, dy); wxRect vRect(win->GetVirtualSize()); wxRect cRect(win->GetClientSize()); // clamp to scroll area if (newScrollOffset.x < 0) newScrollOffset.x = 0; else if (newScrollOffset.x + cRect.width > vRect.width) newScrollOffset.x = max(0, vRect.width - cRect.width - 1); if (newScrollOffset.y < 0) newScrollOffset.y = 0; else if (newScrollOffset.y + cRect.height > vRect.height) newScrollOffset.y = max(0, vRect.height - cRect.height - 1); if (newScrollOffset == scrollOffset) return; m_data->viewStart = newScrollOffset; wxPoint delta(orig - newScrollOffset); if (m_data->hasStaticBackground) win->Refresh(); else win->ScrollWindow(delta.x, delta.y); adjustScrollbars(); }
void ScrollView::platformSetScrollPosition(const IntPoint& scrollPoint) { wxWindow* win = platformWidget(); wxPoint scrollOffset = m_data->viewStart; wxPoint orig(scrollOffset); wxPoint newScrollOffset(scrollPoint); wxRect vRect(win->GetVirtualSize()); wxRect cRect(win->GetClientSize()); // clamp to scroll area if (newScrollOffset.x < 0) newScrollOffset.x = 0; else if (newScrollOffset.x + cRect.width > vRect.width) newScrollOffset.x = max(0, vRect.width - cRect.width); if (newScrollOffset.y < 0) newScrollOffset.y = 0; else if (newScrollOffset.y + cRect.height > vRect.height) newScrollOffset.y = max(0, vRect.height - cRect.height); if (newScrollOffset == scrollOffset) return; m_data->viewStart = newScrollOffset; wxPoint delta(orig - newScrollOffset); if (canBlitOnScroll()) win->ScrollWindow(delta.x, delta.y); else win->Refresh(); adjustScrollbars(); }
void cTrueColorDemo::Action(void) { cPixmap *FadeInPixmap = NULL; cPixmap *FadeOutPixmap = NULL; cPixmap *MovePixmap = NULL; cPixmap *NextPixmap = NULL; cPixmap *TilePixmap = NULL; cPixmap *ScrollPixmap = NULL; cPixmap *AnimPixmap = NULL; int FrameTime = 40; // ms int FadeTime = 1000; // ms int MoveTime = 4000; // ms int TileTime = 6000; // ms int ScrollWaitTime = 1000; // ms int ScrollLineTime = 200; // ms int ScrollTotalTime = 8000; // ms uint64_t Start = 0; uint64_t ScrollStartTime = 0; int ScrollLineNumber = 0; cPoint MoveStart, MoveEnd; cPoint TileStart, TileEnd; cPoint ScrollStart, ScrollEnd; int Line = osd->Height() / 20; int StartLine = Line; cPoint OldCursor; int State = 0; while (Running()) { cPixmap::Lock(); bool Animated = false; uint64_t Now = cTimeMs::Now(); if (FadeInPixmap) { double t = std::min(double(Now - Start) / FadeTime, 1.0); int Alpha = t * ALPHA_OPAQUE; FadeInPixmap->SetAlpha(Alpha); if (t >= 1) FadeInPixmap = NULL; Animated = true; } if (FadeOutPixmap) { double t = std::min(double(Now - Start) / FadeTime, 1.0); int Alpha = ALPHA_OPAQUE - t * ALPHA_OPAQUE; FadeOutPixmap->SetAlpha(Alpha); if (t >= 1) FadeOutPixmap = NULL; Animated = true; } if (MovePixmap) { double t = std::min(double(Now - Start) / MoveTime, 1.0); int x = MoveStart.X() + t * (MoveEnd.X() - MoveStart.X()); int y = MoveStart.Y() + t * (MoveEnd.Y() - MoveStart.Y()); cRect r = MovePixmap->ViewPort(); r.SetPoint(x, y); MovePixmap->SetViewPort(r); if (t >= 1) MovePixmap = NULL; Animated = true; } if (TilePixmap) { double t = std::min(double(Now - Start) / TileTime, 1.0); int x = TileStart.X() + t * (TileEnd.X() - TileStart.X()); int y = TileStart.Y() + t * (TileEnd.Y() - TileStart.Y()); TilePixmap->SetDrawPortPoint(cPoint(x, y)); if (t >= 1) { destroyablePixmap = TilePixmap; TilePixmap = NULL; } Animated = true; } if (ScrollPixmap) { if (int(Now - Start) > ScrollWaitTime) { if (ScrollStartTime) { double t = std::min(double(Now - ScrollStartTime) / ScrollLineTime, 1.0); int x = ScrollStart.X() + t * (ScrollEnd.X() - ScrollStart.X()); int y = ScrollStart.Y() + t * (ScrollEnd.Y() - ScrollStart.Y()); ScrollPixmap->SetDrawPortPoint(cPoint(x, y)); if (t >= 1) { if (int(Now - Start) < ScrollTotalTime) { cRect r = ScrollPixmap->DrawPort(); r.SetPoint(-r.X(), -r.Y()); ScrollPixmap->Pan(cPoint(0, 0), r); const cFont *Font = cFont::GetFont(fontOsd); cString s = cString::sprintf("Line %d", ++ScrollLineNumber); ScrollPixmap->DrawRectangle(cRect(0, ScrollPixmap->ViewPort().Height(), ScrollPixmap->DrawPort().Width(), ScrollPixmap->DrawPort().Height()), clrTransparent); ScrollPixmap->DrawText(cPoint(0, ScrollPixmap->ViewPort().Height()), s, clrYellow, clrTransparent, Font); ScrollStartTime = Now; } else { FadeOutPixmap = ScrollPixmap; ScrollPixmap = NULL; Start = cTimeMs::Now(); } } } else ScrollStartTime = Now; } Animated = true; } if (AnimPixmap) { int d = AnimPixmap->ViewPort().Height(); if (clockwise) d = -d; cPoint p = AnimPixmap->DrawPort().Point().Shifted(0, d); if (clockwise && p.Y() <= -AnimPixmap->DrawPort().Height()) p.SetY(0); else if (!clockwise && p.Y() > 0) p.SetY(-(AnimPixmap->DrawPort().Height() - AnimPixmap->ViewPort().Height())); AnimPixmap->SetDrawPortPoint(p); } if (!Animated) { switch (State) { case 0: { if (cFont *Font = cFont::CreateFont(DefaultFontOsd, osd->Height() / 10)) { FadeInPixmap = CreateTextPixmap("VDR", Line, 1, clrYellow, clrTransparent, Font); if (FadeInPixmap) Line += FadeInPixmap->DrawPort().Height(); delete Font; Start = cTimeMs::Now(); } State++; } break; case 1: { FadeInPixmap = CreateTextPixmap("Video Disk Recorder", Line, 3, clrYellow, clrTransparent); if (FadeInPixmap) Line += FadeInPixmap->DrawPort().Height(); Start = cTimeMs::Now(); State++; } break; case 2: { FadeInPixmap = CreateTextPixmap("True Color OSD Demo", Line, 1, clrYellow, clrTransparent); if (FadeInPixmap) Line += FadeInPixmap->DrawPort().Height(); Start = cTimeMs::Now(); State++; } break; case 3: { if (cFont *Font = cFont::CreateFont(DefaultFontOsd, osd->Height() / 10)) { NextPixmap = CreateTextPixmap("Millions of colors", Line, 1, clrYellow, clrTransparent, Font); delete Font; if (NextPixmap) { FadeInPixmap = NextPixmap; Start = cTimeMs::Now(); StartLine = Line; Line += NextPixmap->DrawPort().Height(); } } State++; } break; case 4: { Line += osd->Height() / 10; int w = osd->Width() / 2; int h = osd->Height() - Line - osd->Height() / 10; cImage Image(cSize(w, h)); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) Image.SetPixel(cPoint(x, y), HsvToColor(360 * double(x) / w, 1 - double(y) / h, 1) | 0xDF000000); } if (cPixmap *Pixmap = osd->CreatePixmap(2, cRect((osd->Width() - w) / 2, Line, w, h))) { Pixmap->DrawImage(cPoint(0, 0), Image); toggleablePixmap = Pixmap; } State++; } break; case 5: { if (NextPixmap) { MovePixmap = NextPixmap; MoveStart = MovePixmap->ViewPort().Point(); MoveEnd.Set(osd->Width() - MovePixmap->ViewPort().Width(), osd->Height() - MovePixmap->ViewPort().Height()); Start = cTimeMs::Now(); } State++; } break; case 6: { TilePixmap = CreateTextPixmap("Tiled Pixmaps", StartLine, 1, clrRed, clrWhite); if (TilePixmap) { TilePixmap->SetViewPort(TilePixmap->ViewPort().Grown(TilePixmap->DrawPort().Width(), TilePixmap->DrawPort().Height())); TilePixmap->SetAlpha(200); TilePixmap->SetTile(true); TileStart = TilePixmap->DrawPort().Point(); TileEnd = TileStart.Shifted(TilePixmap->ViewPort().Width(), TilePixmap->ViewPort().Height()); MovePixmap = TilePixmap; MoveStart = MovePixmap->ViewPort().Point(); MoveEnd.Set(10, osd->Height() - MovePixmap->ViewPort().Height() - 10); Start = cTimeMs::Now(); } State++; } break; case 7: { const cFont *Font = cFont::GetFont(fontOsd); const char *Text = "Scrolling Pixmaps"; int w = Font->Width(Text); int h = Font->Height(); if (cPixmap *Pixmap = osd->CreatePixmap(2, cRect((osd->Width() - w) / 2, StartLine, w, 2 * h), cRect(0, 0, w, 3 * h))) { Pixmap->Clear(); Pixmap->DrawText(cPoint(0, 0), Text, clrYellow, clrTransparent, Font); cString s = cString::sprintf("Line %d", ++ScrollLineNumber); Pixmap->DrawText(cPoint(0, Pixmap->ViewPort().Height()), s, clrYellow, clrTransparent, Font); ScrollPixmap = Pixmap; ScrollStart.Set(0, 0); ScrollEnd.Set(0, -h); Start = cTimeMs::Now(); } State++; } break; case 8: { const cFont *Font = cFont::GetFont(fontSml); const char *Text = "Animation"; const int Size = Font->Width(Text) + 10; const int NumDots = 12; const int AnimFrames = NumDots; // Temporarily using pixmap layer 0 to have the text alpha blended: AnimPixmap = osd->CreatePixmap(0, cRect((osd->Width() - Size) / 2, StartLine, Size, Size), cRect(0, 0, Size, Size * AnimFrames)); if (AnimPixmap) { AnimPixmap->SetAlpha(0); AnimPixmap->Clear(); const int Diameter = Size / 5; int xc = Size / 2 - Diameter / 2; for (int Frame = 0; Frame < AnimFrames; Frame++) { AnimPixmap->DrawEllipse(cRect(0, Frame * Size, Size, Size), 0xDDFFFFFF); int yc = Frame * Size + Size / 2 - Diameter / 2; int Color = 0xFF; int Delta = Color / NumDots / 3; for (int a = 0; a < NumDots; a++) { double t = 2 * M_PI * (Frame + a) / NumDots; int x = xc + ((Size - Diameter) / 2 - 5) * cos(t); int y = yc + ((Size - Diameter) / 2 - 5) * sin(t); AnimPixmap->DrawEllipse(cRect(x, y, Diameter, Diameter), ArgbToColor(0xFF, Color, Color, Color)); Color -= Delta; } AnimPixmap->DrawText(cPoint(0, Frame * Size), Text, clrBlack, clrTransparent, cFont::GetFont(fontSml), Size, Size, taCenter); } AnimPixmap->SetLayer(3); // now setting the actual pixmap layer FadeInPixmap = AnimPixmap; LOCK_THREAD; OldCursor = cursor = AnimPixmap->ViewPort().Point(); cursorLimits.Set(0, 0, osd->Width(), osd->Height()); cursorLimits.SetRight(cursorLimits.Right() - Size); cursorLimits.SetBottom(cursorLimits.Bottom() - Size); cursorLimits.Grow(-10, -10); Start = cTimeMs::Now(); } State++; } break; case 9: { LOCK_THREAD; if (cursor != OldCursor) { MovePixmap = AnimPixmap; MoveStart = MovePixmap->ViewPort().Point(); MoveEnd = OldCursor = cursor; MoveTime = 500; Start = cTimeMs::Now(); } } break; } } osd->Flush(); cPixmap::Unlock(); int Delta = cTimeMs::Now() - Now; if (Delta < FrameTime) cCondWait::SleepMs(FrameTime - Delta); } }
void CVideoWnd::OnPaint() { CPaintDC dc(this); //WIDTHHEIGHT CRect clrect(m_rectWnd); clrect.right -= clrect.left; clrect.bottom -= clrect.top; clrect.left = 0; clrect.top = 0; int width = clrect.right - clrect.left; int height = clrect.bottom - clrect.top; CRect cRect(clrect); CDC memDC; memDC.CreateCompatibleDC(&dc); CDC *pDC = &memDC; CBitmap NewMemBmp; NewMemBmp.CreateCompatibleBitmap(&dc, width, height); CBitmap* pOldMemBmp = pDC->SelectObject(&NewMemBmp); if (!m_iStatus) { pDC->FillSolidRect(0, 0, clrect.Width(), clrect.Height(), RGB(255,255,255)); } else if (m_ImageBitmap.GetSafeHandle()) { m_ImageBitmap.BitBlt(pDC, CPoint(0,0)); } CFont dxfont; dxfont.CreateFontIndirect(&m_textfont); CFont* oldfont = (CFont *) pDC->SelectObject(&dxfont); //Draw Text int textlength = m_textstring.GetLength(); //get number of bytes pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(m_rgb); pDC->DrawText((char *)LPCTSTR(m_textstring), textlength, &m_tracker.m_rect, m_horzalign | DT_VCENTER | DT_WORDBREAK ); pDC->SelectObject(oldfont); if ((m_bBorderYes) && (regionSHAPE == m_regionType)) { double rx = cRect.Width() * m_roundrectFactor; double ry = cRect.Height() * m_roundrectFactor; double rval = (rx > ry) ? ry : rx; CPen borderPen; borderPen.CreatePen( PS_SOLID , m_borderSize, m_borderColor ); CPen* oldPen = (CPen *) pDC->SelectObject(&borderPen); LOGBRUSH logbrush; logbrush.lbStyle = BS_HOLLOW; CBrush borderBrush; borderBrush.CreateBrushIndirect(&logbrush); CBrush* oldBrush = (CBrush *) pDC->SelectObject(&borderBrush); int drawOffset = m_borderSize/2; if (m_regionPredefinedShape == regionROUNDRECT) { pDC->RoundRect(drawOffset-1, drawOffset-1, cRect.Width()-1-drawOffset, cRect.Height()-1-drawOffset, (int) rval, (int) rval); } else if (m_regionPredefinedShape == regionELLIPSE) { pDC->Ellipse(drawOffset-1,drawOffset-1, cRect.Width()-1-drawOffset, cRect.Height()-1-drawOffset); } else if (m_regionPredefinedShape == regionRECTANGLE) { pDC->Rectangle(drawOffset-1, drawOffset-1, cRect.Width()-1-drawOffset, cRect.Height()-1-drawOffset); } pDC->SelectObject(oldBrush); pDC->SelectObject(oldPen); borderPen.DeleteObject(); borderBrush.DeleteObject(); } CDC *pWinDC = &dc; pWinDC->BitBlt(0,0,clrect.Width(),clrect.Height(),pDC,0,0,SRCCOPY); pDC->SelectObject(pOldMemBmp); NewMemBmp.DeleteObject(); memDC.DeleteDC(); if (m_bTrackingOn) { m_tracker.Draw(pWinDC); } }
void CFDMSView::OnLButtonDown(UINT nFlags, CPoint point) { if (testGraph) { CRect cRect(0,0,0,0); testGraph->GetPlotBox(&cRect); if (cRect.PtInRect(point) && (m_iMouseControl & GRAPHMOUSE_DATA)) { double dX, dY; testGraph->GetDataItemAt(point,&dX,&dY); Invalidate(); } testGraph->GetXYAxisBox(&cRect); if (cRect.PtInRect(point) && (m_iMouseControl & GRAPHMOUSE_GRID)) { BOOL bVGrid, bHGrid; int iBinVector = 0; bHGrid = testGraph->GetHGridLines(); bVGrid = testGraph->GetVGridLines(); if (bHGrid) iBinVector = iBinVector | 0x01; if (bVGrid) iBinVector = iBinVector | 0x10; iBinVector--; if (iBinVector & 0x01) testGraph->SetHGridLines(TRUE); else testGraph->SetHGridLines(FALSE); if (iBinVector & 0x10) testGraph->SetVGridLines(TRUE); else testGraph->SetVGridLines(FALSE); Invalidate(TRUE); } testGraph->GetXAxisBox(&cRect); if (cRect.PtInRect(point)) { bool bInvalidate = true; int iXNumCycles,iXBaseCycle,iYNumCycles,iYBaseCycle,iYRBaseCycle; if ((nFlags & MK_CONTROL)&&(m_iMouseControl & GRAPHMOUSE_XBCYCLE)) { if (testGraph->IsXLinear()) { double minTickValue,maxTickValue,tickStep; testGraph->GetXTickLimits(&minTickValue,&maxTickValue,&tickStep); testGraph->SetXTickLimits( (3.0*minTickValue-maxTickValue)/2.0, (minTickValue+maxTickValue)/2.0, tickStep); } else { testGraph->GetNLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetNLCycles(iXNumCycles,iXBaseCycle-1,iYNumCycles,iYBaseCycle,iYRBaseCycle); } } else if ((nFlags & MK_SHIFT)&&(m_iMouseControl & GRAPHMOUSE_XBCYCLE)) { if (testGraph->IsXLinear()) { double minTickValue,maxTickValue,tickStep; testGraph->GetXTickLimits(&minTickValue,&maxTickValue,&tickStep); testGraph->SetXTickLimits( (minTickValue+maxTickValue)/2.0, (3.0*maxTickValue-minTickValue)/2.0, tickStep); } else { testGraph->GetNLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetNLCycles(iXNumCycles,iXBaseCycle+1,iYNumCycles,iYBaseCycle,iYRBaseCycle); } } else if (m_iMouseControl & GRAPHMOUSE_XLINEAR) { bool bYLinear, bXLinear; testGraph->GetLinear(&bXLinear, &bYLinear); testGraph->SetLinear(!bXLinear,bYLinear); } else bInvalidate = false; if (bInvalidate) Invalidate(TRUE); } testGraph->GetYAxisBox(&cRect); if (cRect.PtInRect(point)) { int iXNumCycles,iXBaseCycle,iYNumCycles,iYBaseCycle,iYRBaseCycle; bool bInvalidate = true; if ((nFlags & MK_CONTROL) && (m_iMouseControl & GRAPHMOUSE_LBCYCLE)) { if (testGraph->IsYLinear()) { double minTickValue,maxTickValue,tickStep; testGraph->GetYTickLimits(&minTickValue,&maxTickValue,&tickStep); testGraph->SetYTickLimits((3.0*minTickValue-maxTickValue)/2.0,(minTickValue+maxTickValue)/2.0,tickStep); } else { testGraph->GetNLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetNLCycles(iXNumCycles,iXBaseCycle,iYNumCycles,iYBaseCycle-1,iYRBaseCycle); } } else if ((nFlags & MK_SHIFT) && (m_iMouseControl & GRAPHMOUSE_LBCYCLE)) { if (testGraph->IsYLinear()) { double minTickValue,maxTickValue,tickStep; testGraph->GetYTickLimits(&minTickValue,&maxTickValue,&tickStep); testGraph->SetYTickLimits((minTickValue+maxTickValue), (3.0*maxTickValue-minTickValue), tickStep); } else { testGraph->GetNLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetNLCycles(iXNumCycles,iXBaseCycle,iYNumCycles,iYBaseCycle+1,iYRBaseCycle); } } else if ((nFlags & MK_MBUTTON) && (m_iMouseControl & GRAPHMOUSE_YLINEAR)) { bool bYLinear, bXLinear; testGraph->GetLinear(&bXLinear, &bYLinear); testGraph->SetLinear(bXLinear,!bYLinear); if (testGraph->IsYLinear()) { double minTickValue,maxTickValue,tickStep; testGraph->GetYTickLimits(&minTickValue,&maxTickValue,&tickStep); // find min and mx .. on pgraohseries Oblist // testGraph->SetYTickLimits((minTickValue+maxTickValue)/2.0, // (3.0*maxTickValue-minTickValue)/2.0, tickStep); } else { testGraph->GetNLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetNLCycles(iXNumCycles,iXBaseCycle,iYNumCycles,iYBaseCycle+1,iYRBaseCycle); } } else bInvalidate = false; if (bInvalidate) Invalidate(TRUE); } testGraph->GetYRAxisBox(&cRect); if (cRect.PtInRect(point)) { int iXNumCycles,iXBaseCycle,iYNumCycles,iYBaseCycle,iYRBaseCycle; bool bInvalidate = true; if ((nFlags & MK_CONTROL ) && (m_iMouseControl & GRAPHMOUSE_RBCYCLE)) { if (testGraph->IsYLinear()) { double minTickValue,maxTickValue,tickStep; testGraph->GetYRTickLimits(&minTickValue,&maxTickValue,&tickStep); testGraph->SetYRTickLimits((3.0*minTickValue-maxTickValue)/2.0,(minTickValue+maxTickValue)/2.0,tickStep); } else { testGraph->GetNLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetNLCycles(iXNumCycles,iXBaseCycle,iYNumCycles,iYBaseCycle,iYRBaseCycle-1); } } else if ((nFlags & MK_SHIFT) && (m_iMouseControl & GRAPHMOUSE_RBCYCLE)) { if (testGraph->IsYLinear()) { double minTickValue,maxTickValue,tickStep; testGraph->GetYRTickLimits(&minTickValue,&maxTickValue,&tickStep); testGraph->SetYRTickLimits((minTickValue+maxTickValue)/2.0, (3.0*maxTickValue-minTickValue)/2.0, tickStep); } else { testGraph->GetNLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetNLCycles(iXNumCycles,iXBaseCycle,iYNumCycles,iYBaseCycle,iYRBaseCycle+1); } } else if (m_iMouseControl & GRAPHMOUSE_YLINEAR) { bool bYLinear, bXLinear; testGraph->GetLinear(&bXLinear, &bYLinear); testGraph->SetLinear(bXLinear,!bYLinear); } else bInvalidate = false; if (bInvalidate) Invalidate(TRUE); } if (testGraph->GetHasLegendInfo() && (m_iMouseControl & GRAPHMOUSE_LEGEND)) { testGraph->GetLegendBox(&cRect); if (cRect.PtInRect(point)) { bool bFound = false; int iIndex = 0; if (testGraph->graphHasLegend) { while (testGraph->GetLegendContentsBox(iIndex,&cRect) && iIndex < 100) { if (cRect.PtInRect(point)) { bFound = true; testGraph->ToggleDisplayEqGroup(iIndex); } iIndex++; } } if (!bFound) testGraph->graphHasLegend = !testGraph->graphHasLegend; Invalidate(TRUE); } } } CView::OnLButtonDown(nFlags, point); }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> cRect::cRect(int _x1, int _y1, int _x2, int _y2) { (*this) = cRect(cPoint(_x1, _y1), cPoint(_x2, _y2)); }
void CFDMSView::OnRButtonDown(UINT nFlags, CPoint point) { if (testGraph) { CRect cRect(0,0,0,0); testGraph->GetXYAxisBox(&cRect); if (cRect.PtInRect(point) && (m_iMouseControl & GRAPHMOUSE_GRID)) { BOOL bVGrid, bHGrid; int iBinVector = 0; bHGrid = testGraph->GetHGridLines(); bVGrid = testGraph->GetVGridLines(); if (bHGrid) iBinVector = iBinVector | 0x01; if (bVGrid) iBinVector = iBinVector | 0x10; iBinVector--; if (iBinVector & 0x01) testGraph->SetHGridLines(TRUE); else testGraph->SetHGridLines(FALSE); if (iBinVector & 0x10) testGraph->SetVGridLines(TRUE); else testGraph->SetVGridLines(FALSE); Invalidate(TRUE); } testGraph->GetXAxisBox(&cRect); if (cRect.PtInRect(point) && (m_iMouseControl & GRAPHMOUSE_XCYCLE)) { int iBump = 1; if (nFlags & MK_CONTROL) iBump = -1; int iXNumCycles,iXBaseCycle,iYNumCycles,iYBaseCycle,iYRBaseCycle; if (testGraph->IsXLinear()) { testGraph->GetLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetLCycles(iXNumCycles+iBump,iXBaseCycle,iYNumCycles,iYBaseCycle,iYRBaseCycle); } else { testGraph->GetNLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetNLCycles(iXNumCycles+iBump,iXBaseCycle,iYNumCycles,iYBaseCycle,iYRBaseCycle); } Invalidate(TRUE); } testGraph->GetYAxisBox(&cRect); if (cRect.PtInRect(point) && (m_iMouseControl & GRAPHMOUSE_LCYCLE)) { int iBump = 1; if (nFlags & MK_CONTROL) iBump = -1; int iXNumCycles,iXBaseCycle,iYNumCycles,iYBaseCycle,iYRBaseCycle; if (testGraph->IsYLinear()) { testGraph->GetLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetLCycles(iXNumCycles,iXBaseCycle,iYNumCycles+iBump,iYBaseCycle,iYRBaseCycle); } else { testGraph->GetNLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetNLCycles(iXNumCycles,iXBaseCycle,iYNumCycles+iBump,iYBaseCycle,iYRBaseCycle); } Invalidate(TRUE); } testGraph->GetYRAxisBox(&cRect); if (cRect.PtInRect(point) && (m_iMouseControl & GRAPHMOUSE_RCYCLE)) { int iBump = 1; if (nFlags & MK_CONTROL) iBump = -1; int iXNumCycles,iXBaseCycle,iYNumCycles,iYBaseCycle,iYRBaseCycle; if (testGraph->IsYLinear()) { testGraph->GetLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetLCycles(iXNumCycles,iXBaseCycle,iYNumCycles+iBump,iYBaseCycle,iYRBaseCycle); } else { testGraph->GetNLCycles(&iXNumCycles,&iXBaseCycle,&iYNumCycles,&iYBaseCycle,&iYRBaseCycle); testGraph->SetNLCycles(iXNumCycles,iXBaseCycle,iYNumCycles+iBump,iYBaseCycle,iYRBaseCycle); } Invalidate(TRUE); } if (testGraph->GetHasLegendInfo() && (m_iMouseControl & GRAPHMOUSE_LEGEND)) { testGraph->GetLegendBox(&cRect); if (cRect.PtInRect(point)) { testGraph->graphHasLegend = !testGraph->graphHasLegend; Invalidate(TRUE); } } } CView::OnRButtonDown(nFlags, point); }
Bool Camera::SetupView( const Area<F32> & mirrorRect, F32 y, Area<F32> & mRect) { mRect = mirrorRect; if (rect.Width() && rect.Height()) { halfHeight = ((F32) rect.Height()) * 0.5f; halfWidth = ((F32) rect.Width()) * 0.5f; aspectHW = halfHeight / halfWidth; if (!isIso) { projMatrix.SetProjection( nearPlane, farPlane * zoom, fov / zoom, aspectHW); if (Vid::renderState.status.clipVis) { halfHeight -= (F32) 64 * aspectHW; halfWidth -= (F32) 64; } aspectHW = halfHeight / halfWidth; invProjX = aspectHW / ( projMatrix.right.x * halfHeight); invProjY = 1 / (-projMatrix.up.y * halfHeight); } else { if (Vid::renderState.status.clipVis) { halfHeight -= (F32) 64 * aspectHW; halfWidth -= (F32) 64; } aspectHW = halfHeight / halfWidth; invProjX = 1 / ( projMatrix.right.x * halfHeight); invProjY = 1 / (-projMatrix.up.y * halfHeight); } invDepth = 1.0f / (farPlane - nearPlane); F32 proj23 = projMatrix.frontw == 0 ? 1 : projMatrix.frontw; invProjX *= proj23; invProjY *= proj23; VertexTL verts[4], clipV[88]; verts[0].vv.x = mRect.p0.x; verts[0].vv.y = y; verts[0].vv.z = mRect.p0.z; verts[1].vv.x = mRect.p1.x; verts[1].vv.y = y; verts[1].vv.z = mRect.p0.z; verts[2].vv.x = mRect.p1.x; verts[2].vv.y = y; verts[2].vv.z = mRect.p1.z; verts[3].vv.x = mRect.p0.x; verts[3].vv.y = y; verts[3].vv.z = mRect.p1.z; VertexTL * v, * ve = verts + 4; for (v = verts; v < ve; v++) { viewMatrix.Transform( v->vv); } // generate on screen water verts U16 clipI[88]; U32 vCount = 4, iCount = 6; Vid::Clip::ToBuffer( clipV, clipI, verts, vCount, Vid::rectIndices, iCount); // generate on screen water rectangle mRect.Set( F32_MAX, F32_MAX, -F32_MAX, -F32_MAX); ve = clipV + vCount; for (v = clipV; v < ve; v++) { v->vv.x -= Origin().x; v->vv.y -= Origin().y; mRect.p0.x = Min<F32>( mRect.p0.x, v->vv.x); mRect.p1.x = Max<F32>( mRect.p1.x, v->vv.x); // onscreen y's are sign reversed mRect.p0.y = Min<F32>( mRect.p0.y, v->vv.y); mRect.p1.y = Max<F32>( mRect.p1.y, v->vv.y); } // real planes // F32 kx, ky, z = nearPlane; if (isIso) { kx = 1.0f * invProjX; ky = 1.0f * invProjY; } else { kx = (z * projMatrix.frontw + projMatrix.positw) * invProjX; ky = (z * projMatrix.frontw + projMatrix.positw) * invProjY; } frustrum[0].x = (-halfWidth) * kx; frustrum[0].y = (-halfHeight) * ky; frustrum[0].z = z; frustrum[2].x = ( halfWidth) * kx; frustrum[2].y = ( halfHeight) * ky; frustrum[2].z = z; Area<F32> cRect( mRect.p0.x * kx, mRect.p0.y * ky, mRect.p1.x * kx, mRect.p1.y * ky); frustrum[0].x = Max<F32>( cRect.p0.x, frustrum[0].x); frustrum[2].x = Min<F32>( cRect.p1.x, frustrum[2].x); // onscreen y's are sign reversed frustrum[0].y = Max<F32>( cRect.p0.y, frustrum[0].y); frustrum[2].y = Min<F32>( cRect.p1.y, frustrum[2].y); frustrum[1].x = frustrum[2].x; frustrum[1].y = frustrum[0].y; frustrum[1].z = z; frustrum[3].x = frustrum[0].x; frustrum[3].y = frustrum[2].y; frustrum[3].z = z; z = farPlane * zoom; if (isIso) { kx = 1.0f * invProjX; ky = 1.0f * invProjY; } else { kx = (z * projMatrix.frontw + projMatrix.positw) * invProjX; ky = (z * projMatrix.frontw + projMatrix.positw) * invProjY; } frustrum[4].x = (-halfWidth) * kx; frustrum[4].y = (-halfHeight) * ky; frustrum[4].z = z; frustrum[6].x = ( halfWidth) * kx; frustrum[6].y = ( halfHeight) * ky; frustrum[6].z = z; cRect.Set( mRect.p0.x * kx, mRect.p0.y * ky, mRect.p1.x * kx, mRect.p1.y * ky); frustrum[4].x = Max<F32>( cRect.p0.x, frustrum[4].x); frustrum[6].x = Min<F32>( cRect.p1.x, frustrum[6].x); // onscreen y's are sign reversed frustrum[4].y = Max<F32>( cRect.p0.y, frustrum[4].y); frustrum[6].y = Min<F32>( cRect.p1.y, frustrum[6].y); frustrum[5].x = frustrum[6].x; frustrum[5].y = frustrum[4].y; frustrum[5].z = z; frustrum[7].x = frustrum[4].x; frustrum[7].y = frustrum[6].y; frustrum[7].z = z; Vector origin( 0.0, 0.0, 0.0); // near planes[0].Set( frustrum[0], frustrum[1], frustrum[2]); planes[0].Normalize(); // far planes[1].Set( frustrum[4], frustrum[5], frustrum[6]); planes[1].Normalize(); // left planes[2].Set( origin, frustrum[4], frustrum[7]); planes[2].Normalize(); // right planes[3].Set( origin, frustrum[5], frustrum[6]); planes[3].Normalize(); // top planes[4].Set( origin, frustrum[4], frustrum[5]); planes[4].Normalize(); // bottom planes[5].Set( origin, frustrum[6], frustrum[7]); planes[5].Normalize(); // fixup direction of plane equations for (U32 i = 0 ; i < 8; i++) { origin += frustrum[i]; } // all plane equation normals must point towards 'origin' // which is the center of all the frustrum points origin *= 0.125f; for (i = 0; i < 6 ; i++) { if (planes[i].Evalue( origin) < 0.0f) { // change sign of plane equation planes[i] *= -1.0f; } } } if (Vid::curCamera == this) { Vid::SetCamera( *this, TRUE); } mRect.p0.x += Origin().x; mRect.p0.y += Origin().y; mRect.p1.x += Origin().x; mRect.p1.y += Origin().y; return frustrum[6].x < frustrum[4].x || frustrum[4].x > frustrum[6].x || frustrum[6].y > frustrum[4].y || frustrum[4].y < frustrum[6].y ? FALSE : TRUE; }
// ================ PlayFile - PlayRecords ======================= // BOOL COXMetaFile::PlayFile(CDC* pDC) { CRect cRect(0,0,m_rectBounds.right-m_rectBounds.left, m_rectBounds.bottom-m_rectBounds.top); return PlayEnhMetaFile(pDC->m_hDC,m_hEMF,&cRect); }