void ChartWindow::OnPaint(Canvas &canvas) { canvas.ClearWhite(); ChartRenderer renderer(look, canvas, canvas.GetRect()); DrawChart(renderer); }
int main(void) { int h; // initialize a flag bool flag = false; // keep asking for input until it's vaild do { // ask for the height printf("height: "); // record users' input h = GetInt(); // check the input flag = CheckInput(h); } while (flag == false); // draw the chart DrawChart(h); return 0; }
void GDisplay::OnPaint(HDC hDC) { // Standard Setup HDC hMemDC = ::CreateCompatibleDC(hDC); if (hMemDC) { UINT dx = X_SHIFT_TO_CHART; UINT dy = Y_SHIFT_TO_CHART; RECT rcClient; ::SetRect(&rcClient, 0, 0, m_nClientWidth, m_nClientHeight); HBITMAP hBmp = ::CreateCompatibleBitmap(hDC, m_nClientWidth, m_nClientHeight); HGDIOBJ hOldBmp = ::SelectObject(hMemDC, hBmp); // Draw only on hMemDC // Delegate main work to the DrawChart function // Lock lock(&g_csSimData); DrawChart(hMemDC, &rcClient, dx, dy); lock.Release(); // My Logo !!! //DrawLogo(hMemDC, rcClient.right - 120, rcClient.bottom - 30); // Copies the source rectangle directly to the destination rectangle ::BitBlt(hDC, 0, 0, m_nClientWidth, m_nClientHeight, hMemDC, 0, 0, SRCCOPY); // Standard End ::SelectObject(hMemDC, hOldBmp); ::DeleteDC(hMemDC); ::DeleteObject(hBmp); } else { TRACE2("Memory DC was not created: %#X, Error code: %d\n", hDC, GetLastError()); } }
bool _HYChartWindow::_ProcessOSEvent (Ptr vEvent) { static long lastH = -1, lastV = -1; if (!_HYTWindow::_ProcessOSEvent (vEvent)) { if (components.lLength == 0) { return false; } _HYPullDown *p1 = (_HYPullDown*)GetObject (4); if (p1&&(p1->GetSelection()>=8)&&(ySeries.lLength)) { _HY_GTK_UI_Message *theMessage = (_HY_GTK_UI_Message*)vEvent; gdouble xc, yc; gdk_event_get_coords (theMessage->theEvent,&xc,&yc); switch (theMessage->theEvent->type) { case GDK_BUTTON_PRESS: { if (((GdkEventButton*)theMessage->theEvent)->button != 1) { return false; } lastH = xc-theWindow->allocation.x-windowContent->allocation.x; lastV = yc-theWindow->allocation.y-windowContent->allocation.y; if (FindClickedCell(lastH, lastV)!=0) { // the chart lastH = -1; lastV = -1; } else { gdk_pointer_grab (theWindow->window,false, (GdkEventMask)(GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK), theWindow->window, NULL, ((GdkEventButton*)theMessage->theEvent)->time); return true; } break; } case GDK_BUTTON_RELEASE: { if (lastH>=0) { gdk_pointer_ungrab (((GdkEventButton*)theMessage->theEvent)->time); lastH = -1; lastV = -1; return true; } break; } case GDK_MOTION_NOTIFY: { if (lastH>=0) { long newH = xc-theWindow->allocation.x-windowContent->allocation.x, newV = yc-theWindow->allocation.y-windowContent->allocation.y; bool redraw = false; _Parameter stepper = pi_const/180.; if (abs(newH-lastH)>abs(newV-lastV)) { stepper *= 1+log (fabs(newH-lastH))/log(2.0); if (newH-lastH<0) { if (xyAngle>0.0) { xyAngle -= stepper; if (xyAngle<0) { xyAngle = 0; } redraw = true; } } else if (xyAngle<pi_const/2) { xyAngle += stepper; if (xyAngle>pi_const/2) { xyAngle = pi_const/2; } redraw = true; } } else { if (newV==lastV) { return false; } stepper *= 1+log (fabs(newV-lastV))/log(2.0); if (newV-lastV>0) { if (zAngle<pi_const/2) { zAngle += stepper; if (zAngle>pi_const/2) { zAngle = pi_const/2; } redraw = true; } } else if (zAngle>0.0) { zAngle -= stepper; if (zAngle<0) { zAngle = 0; } redraw = true; } } if (redraw) { ComputeProjectionSettings(); projectionMatrix = ComputeProjectionMatrix (); forceUpdateForScrolling = true; DrawChart(); forceUpdateForScrolling = false; } lastH = newH; lastV = newV; } break; } } } return false; } return true; }