LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hwndEraserWeight; static HWND hwndStrokeWeight; static HWND hwndPenTool; static HWND hwndLineTool; static HWND hwndPolygonTool; static HWND hwndEllipseTool; static HWND hwndBezierTool; static HWND hwndEraserTool; static HWND hwndFillCheck; static POINT pen; static BOOL firstLine; static POINT newLine; static BOOL firstPolygon; static RECT newPolygon; static BOOL firstEllipse; static RECT newEllipse; static BOOL firstBezier; static BOOL secondBezier; static BOOL thirdBezier; static POINT pointsforBezier[4]; static HRGN lastRegion; static BOOL regionDeleted; int xMouse, yMouse; static RECT drawingArea = {15, 180, 580, 640}; RECT rectRED = {255, 100, 375, 115}; RECT rectGREEN = {255, 120, 375, 135}; RECT rectBLUE = {255, 140, 375, 155}; RECT rectTemp; HDC hdc = GetDC(hwnd); COLORREF strokeRGB; int strokeWeight; COLORREF fillRGB; HBRUSH fillBrush; PAINTSTRUCT ps; HPEN strokePen; POINT point; RECT rect; HBRUSH hBrush; int xFillPreview =240 ; int yFillPreview = 50; int xStrokePreview = 320; int yStrokePreview = 50; UINT fillRED = 255; UINT fillGREEN = 255; UINT fillBLUE = 255; UINT strokeRED = 0; UINT strokeGREEN = 0; UINT strokeBLUE = 0; HDC hdcMem; BITMAP bitmap; HBITMAP hbmpimage = NULL; hbmpimage = (HBITMAP)LoadImage(hInstance, "aesthetic1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); GetObject(hbmpimage, sizeof(bitmap), &bitmap); switch(message) { case WM_CREATE: CreateWindowEx( 0, "Button", "Tools", WS_VISIBLE | WS_CHILD | BS_GROUPBOX, 5, 5, 100, 160, hwnd, 0, hInstance, NULL); CreateWindowEx( 0, "Button", "Style", WS_VISIBLE | WS_CHILD | BS_GROUPBOX, 520, 5, 135, 120, hwnd, 0, hInstance, NULL); CreateWindowEx( 0, "Button", "Color", WS_VISIBLE | WS_CHILD | BS_GROUPBOX, 220, 5, 180, 160, hwnd, 0, hInstance, NULL); CreateWindowEx( 0, "Static", "Fill", WS_VISIBLE | WS_CHILD | SS_CENTER, 240, 25, 45, 20, hwnd, (HMENU)0, hInstance, NULL); CreateWindowEx( 0, "Static", "Stroke", WS_VISIBLE | WS_CHILD | SS_CENTER, 320, 25, 45, 20, hwnd, (HMENU)0, hInstance, NULL); CreateWindowEx( 0, "Static", "R", WS_VISIBLE | WS_CHILD | SS_LEFT, 240, 100, 10, 15, hwnd, (HMENU)0, hInstance, NULL); CreateWindowEx( 0, "Static", "G", WS_VISIBLE | WS_CHILD | SS_LEFT, 240, 120, 10, 15, hwnd, (HMENU)0, hInstance, NULL); CreateWindowEx( 0, "Static", "B", WS_VISIBLE | WS_CHILD | SS_LEFT, 240, 140, 10, 15, hwnd, (HMENU)0, hInstance, NULL); hwndPenTool = CreateWindowEx( 0, "Button", "Pen", WS_VISIBLE | WS_CHILD | WS_GROUP | BS_AUTORADIOBUTTON, 15, 30, 80, 18, hwnd, (HMENU)IDB_PEN, hInstance, NULL); Button_SetCheck(hwndPenTool, BST_CHECKED); hwndLineTool = CreateWindowEx( 0, "Button", "Line", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 15, 55, 80, 18, hwnd, (HMENU)IDB_LINE, hInstance, NULL); hwndPolygonTool = CreateWindowEx( 0, "Button", "Polygon", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 15, 80, 80, 18, hwnd, (HMENU)IDB_POLYGON, hInstance, NULL); hwndEllipseTool = CreateWindowEx( 0, "Button", "Ellipse", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 15, 105, 80, 18, hwnd, (HMENU)IDB_ELLIPSE, hInstance, NULL); hwndBezierTool = CreateWindowEx( 0, "Button", "Bezier", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 15, 130, 80, 18, hwnd, (HMENU)IDB_BEZIER, hInstance, NULL); hwndFillCheck = CreateWindowEx( 0, "Button", "Fill", WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX, 530, 30, 80, 18, hwnd, (HMENU)0, hInstance, NULL); CreateWindowEx( 0, "Static", "Stroke", WS_VISIBLE | WS_CHILD, 530, 60, 80, 20, hwnd, (HMENU)0, hInstance, NULL); hwndStrokeWeight = CreateWindowEx( 0, "Edit", "1", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER, 620, 60, 20, 20, hwnd, (HMENU)0, hInstance, NULL); hwndEraserTool = CreateWindowEx( 0, "Button", "Eraser", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 530, 90, 80, 20, hwnd, (HMENU)IDB_ERASER, hInstance, NULL); hwndEraserWeight = CreateWindowEx( 0, "Edit", "1", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER, 620, 90, 20, 20, hwnd, (HMENU)0, hInstance, NULL); return 0; case WM_COMMAND: switch (LOWORD(wParam)) { default: DefWindowProc(hwnd, WM_COMMAND, wParam, lParam); break; } return 0; case WM_LBUTTONDOWN: xMouse = GET_X_LPARAM(lParam); yMouse = GET_Y_LPARAM(lParam); if((xMouse > rectRED.left)&&(xMouse <= rectRED.right)) { strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20); if((yMouse > rectRED.top)&&(yMouse <= rectRED.bottom)) { strokeRED = (xMouse - rectRED.left) * 255 / (rectRED.right - rectRED.left); strokeGREEN = GetGValue(strokeRGB); strokeBLUE = GetBValue(strokeRGB); updateColorPreview(hdc, RGB(strokeRED, strokeGREEN, strokeBLUE), xStrokePreview, yStrokePreview); } else if((yMouse > rectGREEN.top)&&(yMouse <= rectGREEN.bottom)) { strokeRED = GetRValue(strokeRGB); strokeGREEN = (xMouse - rectGREEN.left) * 255 / (rectGREEN.right - rectGREEN.left); strokeBLUE = GetBValue(strokeRGB); updateColorPreview(hdc, RGB(strokeRED, strokeGREEN, strokeBLUE), xStrokePreview, yStrokePreview); } else if((yMouse > rectBLUE.top)&&(yMouse <= rectBLUE.bottom)) { strokeRED = GetRValue(strokeRGB); strokeGREEN = GetGValue(strokeRGB); strokeBLUE = (xMouse - rectBLUE.left) * 255 / (rectBLUE.right - rectBLUE.left); updateColorPreview(hdc, RGB(strokeRED, strokeGREEN, strokeBLUE), xStrokePreview, yStrokePreview); } return 0; } if((xMouse > drawingArea.left)&&(xMouse < drawingArea.right)&&(yMouse > drawingArea.top)&&(yMouse < drawingArea.bottom)) { strokeWeight = getWeight(hwndStrokeWeight); point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight); xMouse = point.x; yMouse = point.y; if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndPenTool) == BST_CHECKED)) { pen.x = xMouse; pen.y = yMouse; } if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndLineTool) == BST_CHECKED)) { newLine.x = xMouse; newLine.y = yMouse; firstLine = true; } if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndPolygonTool) == BST_CHECKED)) { newPolygon.left = xMouse; newPolygon.top = yMouse; firstPolygon = true; } if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndEllipseTool) == BST_CHECKED)) { newEllipse.left = xMouse; newEllipse.top = yMouse; firstEllipse = true; } if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndBezierTool) == BST_CHECKED)) { pointsforBezier[0] = point; firstBezier = true; secondBezier = false; thirdBezier = false; } } return 0; case WM_LBUTTONUP: xMouse = GET_X_LPARAM(lParam); yMouse = GET_Y_LPARAM(lParam); strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20); fillRGB = GetPixel(hdc, xFillPreview + 20, yFillPreview + 20); strokeWeight = getWeight(hwndStrokeWeight); if(firstLine) { point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight); xMouse = point.x; yMouse = point.y; strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB); SelectObject(hdc, strokePen); MoveToEx(hdc, xMouse, yMouse, NULL); LineTo(hdc, newLine.x, newLine.y); DeleteObject(strokePen); firstLine = false; } if(firstPolygon) { point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight); newPolygon.right = point.x; newPolygon.bottom = point.y; strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB); fillBrush = (Button_GetCheck(hwndFillCheck) == BST_CHECKED)? CreateSolidBrush(fillRGB) : (HBRUSH)GetStockObject(NULL_BRUSH); SelectObject(hdc, strokePen); SelectObject(hdc, fillBrush); Rectangle(hdc, newPolygon.left, newPolygon.top, newPolygon.right, newPolygon.bottom); DeleteObject(strokePen); DeleteObject(fillBrush); lastRegion = getLastRectRegion(newPolygon, strokeWeight, ®ionDeleted); firstPolygon = false; } if(firstEllipse) { point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight); newEllipse.right = point.x; newEllipse.bottom = point.y; strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB); fillBrush = (Button_GetCheck(hwndFillCheck) == BST_CHECKED)? CreateSolidBrush(fillRGB) : (HBRUSH)GetStockObject(NULL_BRUSH); SelectObject(hdc, strokePen); SelectObject(hdc, fillBrush); Ellipse(hdc, newEllipse.left, newEllipse.top, newEllipse.right, newEllipse.bottom); DeleteObject(strokePen); DeleteObject(fillBrush); lastRegion = getLastEllipticRegion(newEllipse, strokeWeight, ®ionDeleted); firstEllipse = false; } if(firstBezier) { point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight); pointsforBezier[1] = point; firstBezier = false; secondBezier = true; thirdBezier = false; } return 0; case WM_RBUTTONDOWN: xMouse = GET_X_LPARAM(lParam); yMouse = GET_Y_LPARAM(lParam); if((xMouse > rectRED.left)&&(xMouse <= rectRED.right)) { fillRGB = GetPixel(hdc, xFillPreview + 20, yFillPreview + 20); if((yMouse > rectRED.top)&&(yMouse <= rectRED.bottom)) { fillRED = (xMouse - rectRED.left) * 255 / (rectRED.right - rectRED.left); fillGREEN = GetGValue(fillRGB); fillBLUE = GetBValue(fillRGB); updateColorPreview(hdc, RGB(fillRED, fillGREEN, fillBLUE), xFillPreview, yFillPreview); } else if((yMouse > rectGREEN.top)&&(yMouse <= rectGREEN.bottom)) { fillRED = GetRValue(fillRGB); fillGREEN = (xMouse - rectGREEN.left) * 255 / (rectGREEN.right - rectGREEN.left); fillBLUE = GetBValue(fillRGB); updateColorPreview(hdc, RGB(fillRED, fillGREEN, fillBLUE), xFillPreview, yFillPreview); } else if((yMouse > rectBLUE.top)&&(yMouse <= rectBLUE.bottom)) { fillRED = GetRValue(fillRGB); fillGREEN = GetGValue(fillRGB); fillBLUE = (xMouse - rectBLUE.left) * 255 / (rectBLUE.right - rectBLUE.left); updateColorPreview(hdc, RGB(fillRED, fillGREEN, fillBLUE), xFillPreview, yFillPreview); } return 0; } if((xMouse > drawingArea.left)&&(xMouse < drawingArea.right)&&(yMouse > drawingArea.top)&&(yMouse < drawingArea.bottom)) { strokeWeight = getWeight(hwndStrokeWeight); point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight); xMouse = point.x; yMouse = point.y; if((wParam == MK_RBUTTON)&&(Button_GetCheck(hwndBezierTool) == BST_CHECKED)&&(secondBezier)) { pointsforBezier[2] = point; firstBezier = false; secondBezier = false; thirdBezier = true; } } if(regionDeleted) { InvalidateRgn(hwnd, lastRegion, TRUE); DeleteObject(lastRegion); regionDeleted = false; } return 0; case WM_RBUTTONUP: xMouse = GET_X_LPARAM(lParam); yMouse = GET_Y_LPARAM(lParam); strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20); fillRGB = GetPixel(hdc, xFillPreview + 20, yFillPreview + 20); strokeWeight = getWeight(hwndStrokeWeight); point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight); xMouse = point.x; yMouse = point.y; if(thirdBezier) { pointsforBezier[3] = point; strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB); SelectObject(hdc, strokePen); PolyBezier(hdc, pointsforBezier, 4); DeleteObject(strokePen); firstBezier = false; secondBezier = false; thirdBezier = false; } return 0; case WM_MOUSEMOVE: xMouse = GET_X_LPARAM(lParam); yMouse = GET_Y_LPARAM(lParam); if((xMouse > drawingArea.left)&&(xMouse < drawingArea.right) &&(yMouse > drawingArea.top)&&(yMouse < drawingArea.bottom)) { strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20); fillRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20); if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndPenTool) == BST_CHECKED)) { strokePen = CreatePen(PS_SOLID, 1, strokeRGB); SelectObject(hdc, strokePen); MoveToEx(hdc, xMouse, yMouse, NULL); LineTo(hdc, pen.x, pen.y); DeleteObject(strokePen); pen.x = xMouse; pen.y = yMouse; } if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndEraserTool) == BST_CHECKED)) { strokeWeight = getWeight(hwndEraserWeight); point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight); xMouse = point.x; yMouse = point.y; rect.left = point.x - (strokeWeight/2); rect.right = point.x + (strokeWeight/2); rect.top = point.y - (strokeWeight/2); rect.bottom = point.y + (strokeWeight/2); InvalidateRect(hwnd, &rect, FALSE); SendMessage(hwnd, WM_PAINT, 0, 0); ValidateRect(hwnd, &rect); } } return 0; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); updateColorPreview(hdc, RGB(255, 255, 255), xFillPreview, yFillPreview); updateColorPreview(hdc, RGB(0, 0, 0), xStrokePreview, yStrokePreview); hdcMem = CreateCompatibleDC(hdc); SelectObject(hdcMem, hbmpimage); BitBlt(hdc, 600, 40, 280, 600, hdcMem, 0, 0, SRCCOPY); DeleteDC(hdcMem); rectTemp.top = rectRED.top; rectTemp.bottom = rectRED.bottom; for(int i = 0; i < (rectRED.right - rectRED.left); i++) { int r; r = i * 255 / (rectRED.right - rectRED.left); rectTemp.left = rectRED.left + i; rectTemp.right = rectRED.left + i + 1; hBrush = CreateSolidBrush(RGB(r, 0, 0)); FillRect(hdc, &rectTemp, hBrush); DeleteObject(hBrush); } rectTemp.top = rectGREEN.top; rectTemp.bottom = rectGREEN.bottom; for(int i = 0; i < (rectGREEN.right - rectGREEN.left); i++) { int g; g = i * 255 / (rectGREEN.right - rectGREEN.left); rectTemp.left = rectGREEN.left + i; rectTemp.right = rectGREEN.left + i + 1; hBrush = CreateSolidBrush(RGB(0, g, 0)); FillRect(hdc, &rectTemp, hBrush); DeleteObject(hBrush); } rectTemp.top = rectBLUE.top; rectTemp.bottom = rectBLUE.bottom; for(int i = 0; i < (rectBLUE.right - rectBLUE.left); i++) { int b; b = i * 255 / (rectBLUE.right - rectBLUE.left); rectTemp.left = rectBLUE.left + i; rectTemp.right = rectBLUE.left + i + 1; hBrush = CreateSolidBrush(RGB(0, 0, b)); FillRect(hdc, &rectTemp, hBrush); DeleteObject(hBrush); } SelectObject(hdc, CreatePen(PS_SOLID, 1, RGB(0,0,0))); SelectObject(hdc, (HBRUSH)GetStockObject(WHITE_BRUSH)); Rectangle(hdc, drawingArea.left, drawingArea.top, drawingArea.right, drawingArea.bottom); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage (0); return 0; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }
/// Function name : drawSplashWindow // Description : Paints the splash window and the progress of the load game data operation // // HWND hWnd : [in] Splash window // VOID drawSplashWindow(SPLASH_WINDOW_DATA* pWindowData) { BLENDFUNCTION oBlendData; // Alpha blending data DC_STATE* pDCState; // DC state POINT ptOrigin; // Drawing origin into the memory DC SIZE siWindowSize; // Size of the splash window RECT rcProgressText; // Progress stage text drawing rectangle TCHAR* szProgressText; // Progress stage text HDC hScreenDC, hMemoryDC; // Memory DC UINT iCurrentProgress, // Operation progress : 0 <= n <= 10000 iProgressBarLength; // Length of the progress bar, in pixels // Prepare utilZeroObject(&oBlendData, BLENDFUNCTION); siWindowSize = siLogoBitmap; ptOrigin.x = 0; ptOrigin.y = 0; /// Create DC, Pen, Font, Bitmap and progress text hScreenDC = GetDC(NULL); hMemoryDC = CreateCompatibleDC(hScreenDC); pDCState = utilCreateDeviceContextState(hMemoryDC); szProgressText = loadString(getCurrentOperationStageID(getMainWindowData()->pOperationPool), 128); /// Create bitmap pWindowData->hLogoBitmap = (HBITMAP)LoadImage(getResourceInstance(), TEXT("LOGO_BITMAP"), IMAGE_BITMAP, siLogoBitmap.cx, siLogoBitmap.cy, LR_CREATEDIBSECTION); // Setup DC utilSetDeviceContextBitmap(pDCState, pWindowData->hLogoBitmap); utilSetDeviceContextPen(pDCState, pWindowData->hProgressPen); utilSetDeviceContextFont(pDCState, pWindowData->hProgressFont, clProgressBar); utilSetDeviceContextBackgroundMode(pDCState, TRANSPARENT); // Request per-pixel alpha blending oBlendData.BlendOp = AC_SRC_OVER; oBlendData.AlphaFormat = AC_SRC_ALPHA; oBlendData.SourceConstantAlpha = 255; // Calculate progress and text rectangles iCurrentProgress = getCurrentOperationProgress(getMainWindowData()->pOperationPool); iProgressBarLength = (ptProgressBarEnd.x - ptProgressBarStart.x) * iCurrentProgress / iProgressBarMaximum; SetRect(&rcProgressText, ptProgressBarStart.x - 20, ptProgressBarStart.y + 3, ptProgressBarEnd.x + 20, ptProgressBarEnd.y + 20); /// [PROGRESS] Draw progress bar MoveToEx(hMemoryDC, ptProgressBarStart.x, ptProgressBarStart.y, NULL); LineTo(hMemoryDC, (ptProgressBarStart.x + iProgressBarLength), ptProgressBarEnd.y); /// [TEXT] Draw progress text DrawText(hMemoryDC, szProgressText, lstrlen(szProgressText), &rcProgressText, DT_SINGLELINE WITH DT_CENTER); /// [LOGO] Paint alpha-blended logo if (!UpdateLayeredWindow(pWindowData->hWnd, NULL, NULL, &siWindowSize, hMemoryDC, &ptOrigin, 0, &oBlendData, ULW_ALPHA)) ERROR_CHECK("updating layered window", FALSE); // [CHECK] Are we running in windows 7 or newer? if (getAppWindowsVersion() >= WINDOWS_7) /// [WINDOWS 7] Display progress in the taskbar utilSetWindowProgressValue(getAppWindow(), iCurrentProgress, iProgressBarMaximum); // Cleanup utilDeleteDeviceContextState(pDCState); DeleteDC(hMemoryDC); DeleteBitmap(pWindowData->hLogoBitmap); ReleaseDC(NULL, hScreenDC); utilDeleteString(szProgressText); }
static void DrawLine(void *data, long x1, long y1, long x2, long y2) { MoveToEx((HDC)data, x1, y1, NULL); LineTo((HDC)data,x2,y2); }
void DrawLayers(HDC hdc, int x, int y, int width, int height, int type) { double maxHeight = CSnow::current()->getSnowHeight(); double temperatureRange = 40;//max(abs(bottomTemperature - topTemperature), abs(topTemperature)); if(temperatureRange == 0)temperatureRange = 1; if (maxHeight == 0) return; HBRUSH brush; int h; int topT, bottomT; int rightMargin = 40; RECT rect; CLayer *layer; HPEN pen = CreatePen(0, 1, 0); //HPEN boldPen = CreatePen(0, 3, 0); HPEN oldPen = (HPEN)SelectObject(hdc, pen); HPEN dotPen = CreatePen(PS_DASH, 1, RGB(0,0,0)); LOGFONT lFont; ZeroMemory(&lFont, sizeof(lFont)); lFont.lfHeight = 16; lFont.lfWeight = FW_BOLD; wcscpy_s(lFont.lfFaceName, WINDOW_FONT); HFONT font = CreateFontIndirect(&lFont); HFONT oldFont = SelectFont(hdc, font); SetBkMode(hdc, TRANSPARENT); int dy = 0; for (int l = 0; l < CSnow::current()->getLayersNum(); l++) { layer = CSnow::current()->getLayer(l); //if (type)h = height*CSnow::current()->getLayer(l)->GetHeight(t)/maxHeight; //else h = height*CSnow::current()->getLayer(l)->GetDensity(t)/maxHeight; h = (int)(height*layer->GetHeight()/maxHeight); if (h == 0) continue; //draw layer brush = CreateSolidBrush((type) ? layer->GetParticleColor() : layer->GetDensityColor()); rect.left = x; rect.right = x + width - rightMargin; rect.top = y + height - dy - (int)h; rect.bottom = y + height - dy; FillRect(hdc, &rect, brush); DeleteObject(brush); //draw layer temperature topT = (int)((width - rightMargin)*layer->GetTopTemperature()/temperatureRange); bottomT = (int)((width - rightMargin)*layer->GetBottomTemperature()/temperatureRange); SelectObject(hdc, dotPen); SetBkMode(hdc, OPAQUE); MoveToEx(hdc, x + width - rightMargin + topT - 1, rect.top, NULL); LineTo(hdc, x + width - rightMargin + bottomT - 1, rect.bottom); SetBkMode(hdc, TRANSPARENT); SelectObject(hdc, pen); if(layer->GetSelection()) { HPEN boldPen = CreatePen(0, 3, ((type) ? layer->GetParticleSelectionColor() : 0)); SelectObject(hdc, boldPen); MoveToEx(hdc, rect.left + 1, rect.top + 1, NULL); LineTo(hdc, rect.left + 1, rect.bottom - 1); LineTo(hdc, rect.right - 2, rect.bottom - 1); LineTo(hdc, rect.right - 2, rect.top + 1); LineTo(hdc, rect.left + 1, rect.top + 1); SelectObject(hdc, pen); DeleteObject(boldPen); } MoveToEx(hdc, x + width - rightMargin + 10, rect.top, NULL); LineTo(hdc, x + width - rightMargin + 10, rect.bottom); TEXTMETRIC tMetric; GetTextMetrics(hdc, &tMetric); if (h > tMetric.tmHeight/2) { SetTextAlign(hdc, TA_LEFT); SetTextColor(hdc, 0x0); TextOut(hdc, x + width - rightMargin + 14, (rect.bottom + rect.top)/2 - tMetric.tmHeight/2, layer->ToString(CLayer::HEIGHT, 4).c_str(), layer->ToString(CLayer::HEIGHT, 4).size()); SetTextAlign(hdc, TA_CENTER); SetTextColor(hdc, 0xffffff); TextOut(hdc, (x + width - rightMargin)/2, (rect.bottom + rect.top)/2 - tMetric.tmHeight/2, layer->ToString((type) ? CLayer::PARTICLE : CLayer::DENSITY, 4).c_str(), layer->ToString((type) ? CLayer::PARTICLE : CLayer::DENSITY, 4).size()); } dy += h; MoveToEx(hdc, x, y + height - dy, NULL); LineTo(hdc, x + width - rightMargin + 16, y + height - dy); //draw grid MoveToEx(hdc, x, y + height - dy + 3, NULL); LineTo(hdc, x, y + height - dy - 3); MoveToEx(hdc, x + (width - rightMargin)/4, y + height - dy + 3, NULL); LineTo(hdc, x + (width - rightMargin)/4, y + height - dy - 3); MoveToEx(hdc, x + (width - rightMargin)/2, y + height - dy + 3, NULL); LineTo(hdc, x + (width - rightMargin)/2, y + height - dy - 3); MoveToEx(hdc, x + (width - rightMargin)/4*3, y + height - dy +3, NULL); LineTo(hdc, x + (width - rightMargin)/4*3, y + height - dy - 3); MoveToEx(hdc, x + (width - rightMargin) - 1, y + height - dy + 3, NULL); LineTo(hdc, x + (width - rightMargin) - 1, y + height - dy - 3); } SelectObject(hdc, oldPen); SelectFont(hdc, &oldFont); DeleteObject(pen); DeleteObject(dotPen); DeleteFont(font); }
//************************************************************************ // lut_draw // PARAMETERS: // LPRECT lpArea- The area to update. // BOOL bOn- draw ON or draw OFF? // // DESCRIPTION: // Draws the given range from lpData. If lpData==NULL then it // will use lpdata->Map (setup in lut_compute). Draws handles // unless (dwFlags & MS_NOHANDLES). // RETURNS: // //************************************************************************ LOCAL void lut_draw(LPLUTCTL lpdata, HDC hDC, LPRECT lpArea, BOOL bOn) //*********************************************************************** { LFIXED rateX, rateY, lVal; BOOL bInvX = FALSE, bInvY = FALSE; POINT offset; POINT DataOut[256]; int OldROP; int i, lut, nLuts, maxx, maxy, num; LPTR lpLut; RGBS rgb; HPEN hOldPen, hPen; RECT rArea; POINT point; if ((lpdata->nLuts <= 0) || !lpdata->lpLut) return; // subtract one cause we are using PolyLine rArea = *lpArea; --rArea.bottom; --rArea.right; // bInvX = (lpdata->dwStyle & MS_INVERTX); // bInvY = (lpdata->dwStyle & MS_INVERTY); offset.x = (bInvX ? rArea.right : rArea.left); offset.y = (bInvY ? rArea.top: rArea.bottom); for (lut = 0; lut < lpdata->nLuts; ++lut) { // determine source data lpLut = lpdata->lpLut; lpLut += lut; nLuts = lpdata->nLuts; maxx = RectWidth(&rArea)-1; maxy = RectHeight(&rArea)-1; rateX = FGET(maxx, MAXVAL); rateY = FGET(maxy, MAXVAL); // convert to screen coords if (rateX < FUNITY) { // go through pixels rateX = FGET(MAXVAL, maxx); num = maxx+1; for (i=0; i<num; i++) { DataOut[i].x = i; DataOut[i].y = FMUL(lpLut[FMUL(i,rateX)*nLuts], rateY); } } else { // go through map lVal = 0; num = 256; for (i=0; i<num;i++) { DataOut[i].x = FROUND(lVal); DataOut[i].y = FMUL(lpLut[i*nLuts], rateY); lVal += rateX; } } // convert to screen coords for (i=0; i<num;i++) { DataOut[i].x = (bInvX ? (offset.x-DataOut[i].x) : (offset.x+DataOut[i].x)); DataOut[i].y = (bInvY ? (offset.y+DataOut[i].y) : (offset.y-DataOut[i].y)); } // draw line rgb = lpdata->Colors[lut]; hPen = CreatePen(PS_SOLID, 1, RGB(rgb.red, rgb.green, rgb.blue)); hOldPen = (HPEN)SelectObject(hDC, hPen); Polyline(hDC, DataOut, num); // make sure we draw on endpoint MoveToEx(hDC, DataOut[num-1].x, DataOut[num-1].y, &point); LineTo(hDC, DataOut[num-1].x+1, DataOut[num-1].y-1); SelectObject(hDC, hOldPen); DeleteObject(hPen); } }
void CtrlDisAsmView::drawBranchLine(HDC hdc, std::map<u32,int>& addressPositions, BranchLine& line) { HPEN pen; u32 windowEnd = manager.getNthNextAddress(windowStart,visibleRows); int topY; int bottomY; if (line.first < windowStart) { topY = -1; } else if (line.first >= windowEnd) { topY = rect.bottom+1; } else { topY = addressPositions[line.first] + rowHeight/2; } if (line.second < windowStart) { bottomY = -1; } else if (line.second >= windowEnd) { bottomY = rect.bottom+1; } else { bottomY = addressPositions[line.second] + rowHeight/2; } if ((topY < 0 && bottomY < 0) || (topY > rect.bottom && bottomY > rect.bottom)) { return; } // highlight line in a different color if it affects the currently selected opcode if (line.first == curAddress || line.second == curAddress) { pen = CreatePen(0,0,0x257AFA); } else { pen = CreatePen(0,0,0xFF3020); } HPEN oldPen = (HPEN) SelectObject(hdc,pen); int x = pixelPositions.arrowsStart+line.laneIndex*8; if (topY < 0) // first is not visible, but second is { MoveToEx(hdc,x-2,bottomY,0); LineTo(hdc,x+2,bottomY); LineTo(hdc,x+2,0); if (line.type == LINE_DOWN) { MoveToEx(hdc,x,bottomY-4,0); LineTo(hdc,x-4,bottomY); LineTo(hdc,x+1,bottomY+5); } } else if (bottomY > rect.bottom) // second is not visible, but first is { MoveToEx(hdc,x-2,topY,0); LineTo(hdc,x+2,topY); LineTo(hdc,x+2,rect.bottom); if (line.type == LINE_UP) { MoveToEx(hdc,x,topY-4,0); LineTo(hdc,x-4,topY); LineTo(hdc,x+1,topY+5); } } else { // both are visible if (line.type == LINE_UP) { MoveToEx(hdc,x-2,bottomY,0); LineTo(hdc,x+2,bottomY); LineTo(hdc,x+2,topY); LineTo(hdc,x-4,topY); MoveToEx(hdc,x,topY-4,0); LineTo(hdc,x-4,topY); LineTo(hdc,x+1,topY+5); } else { MoveToEx(hdc,x-2,topY,0); LineTo(hdc,x+2,topY); LineTo(hdc,x+2,bottomY); LineTo(hdc,x-4,bottomY); MoveToEx(hdc,x,bottomY-4,0); LineTo(hdc,x-4,bottomY); LineTo(hdc,x+1,bottomY+5); } } SelectObject(hdc,oldPen); DeleteObject(pen); }
void RenderOffscreen(HDC hDestDC) { HDC hdc = hDestDC; // CreateCompatibleDC(hWndMain); int err=GetLastError(); HBITMAP hOldBitmap = SelectObject(hdc, hbmpOffscreen); RECT rect; HPEN hPen; double dx, dy, px, py, AngRad, dDeltaAng; int pos, p1; long CenterX, CenterY; hPen = SelectObject(hdc, CreatePen(PS_SOLID, 3, 0L)); GetClientRect(hWndMain, &rect); /* Draw the table */ CenterX = (rect.right - rect.left)/2; CenterY = (rect.bottom - rect.top)/2; Ellipse(hdc, CenterX - 100, CenterY - 100, CenterX + 100, CenterY + 100); /* Draw the chopsticks */ dDeltaAng = 360 / PHILOSOPHERS; for (pos = 0; pos < PHILOSOPHERS; pos++) //FIXIT { /* Draw the chopsticks */ AngRad = (pos * dDeltaAng)/57.29577951; dx = CenterX + (sin(AngRad)*60); dy = CenterY - (cos(AngRad)*60); MoveToEx(hdc, (int)dx, (int)dy, NULL); dx = CenterX + (sin(AngRad)*85); dy = CenterY - (cos(AngRad)*85); LineTo(hdc, (int)dx, (int)dy); //Draw the plate AngRad = ((pos * dDeltaAng+dDeltaAng / 2))/57.29577951; dx = CenterX + (sin(AngRad) * 72); dy = CenterY - (cos(AngRad) * 72); Ellipse(hdc, (int)dx-12, (int)dy-12, (int)dx+12, (int)dy+12); } /* delete the black pen */ DeleteObject(SelectObject(hdc, hPen)); /* Draw the philosophers */ for(pos = 0; pos < PHILOSOPHERS; pos++) { /* select a pen for each philosopher */ switch (gDinerState[pos]) { case RESTING: hPen = SelectObject(hdc, CreatePen(PS_SOLID, 3, RGB(0, 255, 0))); break; case WAITING: case EATING: hPen = SelectObject(hdc, CreatePen(PS_SOLID, 3, RGB(255, 0, 0))); break; default: hPen = SelectObject(hdc, CreatePen(PS_SOLID, 3, 0L)); } AngRad = ((pos * dDeltaAng) + dDeltaAng / 2)/57.29577951; px = CenterX + (sin(AngRad)*150); py = CenterY - (cos(AngRad)*150); /* Draw the Philosopher */ Ellipse(hdc, (int)px-25, (int)py-25, (int)px+25, (int)py+25); //Draw the left arm if (gChopstickState[pos] == pos) { MoveToEx(hdc, (int)px, (int)py, NULL); AngRad = (pos * dDeltaAng)/57.29577951; dx = CenterX + (sin(AngRad)*85); dy = CenterY - (cos(AngRad)*85); LineTo(hdc, (int)dx, (int)dy); } //Draw the right arm p1 = pos + 1; if (p1 == PHILOSOPHERS) p1 = 0; if (gChopstickState[p1] == pos) { MoveToEx(hdc, (int)px, (int)py, NULL); AngRad = (p1 * dDeltaAng)/57.29577951; dx = CenterX + (sin(AngRad)*85); dy = CenterY - (cos(AngRad)*85); LineTo(hdc, (int)dx, (int)dy); } /* Delete the pen */ DeleteObject(SelectObject(hdc, hPen)); } //for pos BitBlt( hDestDC, rect.left, rect.top, rect.right - rect.left, rect.bottom-rect.top, hdc, rect.left, rect.top, SRCCOPY ); GetLastError(); SelectObject(hdc, hOldBitmap); // DeleteDC(hWndMain, hdc); }
void draw_meter(THRESHOLDOBJ * st) { PAINTSTRUCT ps; HDC hdc; char szdata[20]; RECT rect; int act,width,mid,height,bottom,y1,y2; HBRUSH actbrush,bkbrush; HPEN bkpen; float min, max; GetClientRect(st->displayWnd, &rect); //width=rect.right>>1; width=(int)((float)rect.right/200.0f*st->barsize); mid=rect.right>>1; min=st->in_ports[0].in_min; max=st->in_ports[0].in_max; hdc = BeginPaint (st->displayWnd, &ps); bottom=rect.bottom-10; height=(bottom-rect.top-20); act=bottom-(int)(size_value(min,max,st->gained_value,0.0f,(float)height,0)); y1 =bottom-(int)(size_value(min,max,(float)st->from_input,0.0f,(float)height,0)); y2 =bottom-(int)(size_value(min,max,(float)st->to_input,0.0f,(float)height,0)); if (act>bottom) act=bottom; if (act<bottom-height) act=bottom-height; actbrush=CreateSolidBrush(st->color); bkbrush=CreateSolidBrush(st->bkcolor); bkpen =CreatePen (PS_SOLID,1,st->bkcolor); if (st->redraw) FillRect(hdc, &rect,bkbrush); SelectObject (hdc, bkpen); SelectObject (hdc, bkbrush); if (st->bigadapt) { Rectangle(hdc,15,st->old_y1,50,st->old_y1+15); MoveToEx(hdc,5, st->old_y1,NULL); LineTo(hdc,rect.right, st->old_y1); } if (st->smalladapt) { Rectangle(hdc,15,st->old_y2,50,st->old_y2+15); MoveToEx(hdc,5, st->old_y2,NULL); LineTo(hdc,rect.right, st->old_y2); } if ((st->last_value<act)&&(!st->redraw)) { SelectObject (hdc, bkbrush); Rectangle(hdc,mid-width,st->last_value,mid+width,act); } else { SelectObject (hdc, actbrush); Rectangle(hdc,mid-width,bottom,mid+width,act); } if ((st->fontsize>0)) { RECT txtpos;int x; SelectObject(hdc, st->font); SetBkMode(hdc, OPAQUE); SetBkColor(hdc, st->fontbkcolor); SetTextColor(hdc,st->fontcolor); //wsprintf(szdata, "%d ",(int)(st->gained_value+0.5f)); //ExtTextOut( hdc, rect.right-40,10, 0, &rect,szdata, strlen(szdata), NULL ) ; txtpos.left=5;txtpos.right=50; txtpos.top=0;txtpos.bottom=0; sprintf(szdata, " %.2f ",st->from_input); DrawText(hdc, szdata, -1, &txtpos, DT_CALCRECT); x=txtpos.bottom; txtpos.top=y1-x;txtpos.bottom=txtpos.top+x; DrawText(hdc, szdata, -1, &txtpos, DT_SINGLELINE | DT_CENTER | DT_VCENTER); txtpos.left=5;txtpos.right=50; txtpos.top=0;txtpos.bottom=0; sprintf(szdata, " %.2f ",st->to_input); DrawText(hdc, szdata, -1, &txtpos, DT_CALCRECT); txtpos.top=y2+1;txtpos.bottom+=y2+1; DrawText(hdc, szdata, -1, &txtpos, DT_SINGLELINE | DT_CENTER | DT_VCENTER); } SelectObject (hdc, DRAW.pen_ltblue); MoveToEx(hdc,5, y1,NULL); LineTo(hdc,rect.right, y1); st->old_y1=y1; MoveToEx(hdc,5, y2,NULL); LineTo(hdc,rect.right, y2); st->old_y2=y2; DeleteObject(actbrush); DeleteObject(bkbrush); DeleteObject(bkpen); st->last_value=act; st->redraw=0; EndPaint( st->displayWnd, &ps ); }
void Graphics::moveTo(int x, int y) { MoveToEx(m_dc->m_dc, x, y, NULL); }
void CEditView::Draw( HDC hDC, LPRECT prcClipBox, CSelection *pSel ) const { // prcClipBox is control-relative, not view-relative int nRowStart = ( max( m_rcView.top, prcClipBox->top ) - m_rcView.top ) / m_cyLine; int ySnap = m_rcView.top + nRowStart * m_cyLine; nRowStart += m_nTopIndex; int nRowEnd = m_nTopIndex + ( min( prcClipBox->bottom, m_rcView.bottom ) - m_rcView.top ) / m_cyLine; //#define _DRAWCHARGRID #ifdef _DRAWCHARGRID { RECT rc; if ( IntersectRect( &rc, prcClipBox, &m_rcView ) ) { rc.left = GetLeftMargin( TRUE, TRUE ); HPEN hPen = CreatePen( PS_SOLID, 0, RGB( 192, 192, 192 ) ); HPEN hPenOld = ( HPEN ) SelectObject( hDC, hPen ); int xStart = m_rcView.left + GetLeftMargin( TRUE, TRUE ) + ( ( prcClipBox->left - m_rcView.left ) / m_cxChar ) * m_cxChar; int xEnd = min( prcClipBox->right, m_rcView.right ); int yStart = ySnap; int yEnd = min( prcClipBox->bottom, m_rcView.bottom ); for ( int y = yStart; y <= yEnd; y += m_cyLine ) { MoveToEx( hDC, rc.left, y, NULL ); LineTo( hDC, rc.right, y ); } for ( int x = xStart; x <= xEnd; x += m_cxChar ) { MoveToEx( hDC, x, rc.top, NULL ); LineTo( hDC, x, rc.bottom ); } SelectObject( hDC, hPenOld ); DeleteObject( hPen ); } } #endif int nLastLine = m_pBuffer->GetLineCount() - 1; nLastLine = min( nLastLine, nRowEnd ); int nSelStartCol, nSelStartRow, nSelEndCol, nSelEndRow; BOOL bColumnSel = FALSE; int cxCaret = 0; if ( pSel ) { pSel->GetNormalizedViewSelection( nSelStartCol, nSelStartRow, nSelEndCol, nSelEndRow ); bColumnSel = pSel->IsColumnSel(); cxCaret = pSel->GetCaretWidth(); } int cxLeftMargin1 = GetLeftMargin( FALSE ); COLORREF crVDividerLines = m_pCtrl->GetVDividerLineColor(); // draw the left margin in a different color if ( cxLeftMargin1 ) { COLORREF crMargin = m_pCtrl->GetLeftMarginColor(); if ( crMargin != CLR_INVALID ) { RECT rc = m_rcView; rc.right = rc.left + cxLeftMargin1; SetBkColor( hDC, crMargin ); ExtTextOut( hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL ); } } // draw the line numbers in a different color int cxLeftMargin2 = GetLeftMargin( TRUE ); if ( cxLeftMargin2 != cxLeftMargin1 ) { COLORREF crLineNumbers = m_pCtrl->GetLineNumberBackColor(); if ( crLineNumbers != CLR_INVALID ) { RECT rc = m_rcView; rc.left = m_rcView.left + cxLeftMargin1; rc.right = m_rcView.left + cxLeftMargin2; SetBkColor( hDC, crLineNumbers ); ExtTextOut( hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL ); } } // draw the divider lines if ( crVDividerLines != CLR_INVALID ) { if ( cxLeftMargin1 ) DrawVDividerLine( hDC, m_rcView, m_rcView.left + cxLeftMargin1 ); if ( cxLeftMargin1 != cxLeftMargin2 ) DrawVDividerLine( hDC, m_rcView, m_rcView.left + cxLeftMargin2 ); } int cxLeftMargin3 = GetLeftMargin( TRUE, TRUE ); // draw the stuff in the left margin in one pass, rather than with each // line. This is much faster. int y = ySnap; int xLineNumber = m_rcView.left + cxLeftMargin1; int nLineNumRadix; BOOL bLineNumbers; // if line numbering, select the font once, or else things slow down a bit // if done for each line if ( ( bLineNumbers = m_pCtrl->LineNumberingEnabled( nLineNumRadix ) ) == TRUE ) { SetTextCharacterExtra( hDC, 0 ); SelectObject( hDC, m_pCtrl->GetLineNumberFont() ); SetTextColor( hDC, m_pCtrl->GetLineNumberForeColor() ); ::SetBkMode( hDC, TRANSPARENT ); } int cyDescentShiftNormal = m_pCtrl->m_font->cyDescentShift; int nLine; for ( nLine = nRowStart; nLine <= nLastLine; nLine++ ) { // draw the bookmark and images if present if ( cxLeftMargin1 > 0 ) { BOOL bHasBookmark = m_pBuffer->HasBookmark( nLine ); BYTE byImages = m_pBuffer->GetMarginImages( nLine ); if ( bHasBookmark || byImages ) { DrawLeftMarginImages( hDC, bHasBookmark, byImages, m_rcView.left, y ); } } // Draw the line number if asked to if ( bLineNumbers ) { DrawLineNumber( nLine, nLineNumRadix, hDC, xLineNumber, y - cyDescentShiftNormal ); } y += m_cyLine; } int x = m_rcView.left + cxLeftMargin3; int xDividerStart = m_rcView.left + cxLeftMargin2; // draw the text for ( nLine = nRowStart, y = ySnap; nLine <= nLastLine; nLine++, y += m_cyLine ) DrawLine( nLine, hDC, x, y, xDividerStart ); // draw the selection as a separate pass, because the text will overlap slightly // (for tighter display), and the invert code would end up double-inverting the // overlapping regions, resulting in normal display. if ( pSel ) { for ( nLine = nRowStart, y = ySnap; nLine <= nLastLine; nLine++, y += m_cyLine ) { if ( ( nLine >= nSelStartRow ) && ( nLine <= nSelEndRow ) ) { RECT rcInvert; rcInvert.top = y; rcInvert.bottom = y + m_cyLine; if ( bColumnSel ) { int xSel = nSelStartCol - m_nLeftIndex; xSel = max( 0, xSel ); rcInvert.left = m_rcView.left + xSel * m_cxChar + cxLeftMargin3; xSel = nSelEndCol - m_nLeftIndex; xSel = max( 0, xSel ); rcInvert.right = m_rcView.left + xSel * m_cxChar + cxLeftMargin3; if ( rcInvert.left == rcInvert.right ) { // Is a column selection and is 'empty' -- make selection appear as a // giant insertion cursor rcInvert.right = rcInvert.left + cxCaret; } } else { int xSel = ( nLine == nSelStartRow ) ? nSelStartCol - m_nLeftIndex : 0; xSel = max( 0, xSel ); rcInvert.left = m_rcView.left + xSel * m_cxChar + cxLeftMargin3; rcInvert.left = max( rcInvert.left, x ); xSel = ( nLine == nSelEndRow ) ? ( nSelEndCol - m_nLeftIndex ) : ( m_nRightIndex - m_nLeftIndex + 1 ); rcInvert.right = m_rcView.left + xSel * m_cxChar + cxLeftMargin3; rcInvert.right = max( rcInvert.right, x ); } int xMaxLeft = m_rcView.left + cxLeftMargin2; rcInvert.left = max( rcInvert.left, xMaxLeft ); rcInvert.right = max( rcInvert.right, xMaxLeft ); InvertRect( hDC, &rcInvert ); } } } if ( m_pCtrl->ShowHScrollBar() && m_pCtrl->ShowVScrollBar() ) { // Draw the size box HBRUSH hbr = CreateSolidBrush( GetSysColor( COLOR_BTNFACE ) ); RECT rcBox = m_rcAll; rcBox.left = rcBox.right - GetSystemMetrics( SM_CXVSCROLL ); rcBox.top = rcBox.bottom - GetSystemMetrics( SM_CYHSCROLL ); FillRect( hDC, &rcBox, hbr ); DeleteObject( hbr ); } }
int LinkTimeControl::PaintFCurves( ParamDimensionBase *dim, HDC hdc, Rect& rcGraph, Rect& rcPaint, float tzoom, int tscroll, float vzoom, int vscroll, DWORD flags ) { const int n = NumKeys(); if ( n == 0 ) return 0; Interval valid; int h = rcGraph.h()-1; HPEN dpen,spen; BOOL init=FALSE; Interval range = GetTimeRange(TIMERANGE_ALL); SetBkMode(hdc,TRANSPARENT); dpen = CreatePen(PS_DOT,0,GetColorManager()->GetColor(kFunctionCurveFloat)); spen = CreatePen(PS_SOLID,0,GetColorManager()->GetColor(kFunctionCurveFloat)); SIZE size; GetTextExtentPoint( hdc, _T("0"), 1, &size ); float val; TimeValue leftTime = ScreenToTime(rcPaint.left,tzoom,tscroll); TimeValue rightTime = ScreenToTime(rcPaint.right,tzoom,tscroll); int x, y; // dotted line to left of keys if ( leftTime < range.Start() ) { SelectObject(hdc,dpen); GetValue(range.Start(),&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); MoveToEx(hdc,rcPaint.left,y,NULL); LineTo(hdc,TimeToScreen(range.Start(),tzoom,tscroll),y); } SelectObject(hdc,spen); // first node text { TimeValue t = GetKeyTime( 0 ); if ( t >= leftTime && t <= rightTime ) { GetValue(t,&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); x = TimeToScreen(t,tzoom,tscroll); INode* node = fOwner->GetNode( 0 ); DLTextOut( hdc, x, y-1-size.cy, node ? node->GetName() : _T("World") ); } } // solid line between keys for ( int i=1; i<n; ++i ) { TimeValue t0 = GetKeyTime( i-1 ); TimeValue t1 = GetKeyTime( i ); if ( t1 < leftTime || t0 > rightTime ) continue; GetValue(t0,&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); MoveToEx(hdc,TimeToScreen(t0,tzoom,tscroll),y,NULL); x = TimeToScreen(t1,tzoom,tscroll); LineTo(hdc,x,y); GetValue(t1,&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); LineTo(hdc,x,y); INode* node = fOwner->GetNode( i ); DLTextOut( hdc, x, y-1-size.cy, node ? node->GetName() : _T("World") ); } // dotted line to right of keys if ( rightTime > range.End() ) { SelectObject(hdc,dpen); GetValue(range.End(),&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); MoveToEx(hdc,TimeToScreen(range.End(),tzoom,tscroll),y,NULL); LineTo(hdc,rcPaint.right,y); } SelectObject( hdc, spen ); HBRUSH hUnselBrush = CreateSolidBrush(GetColorManager()->GetColor(kTrackbarKeys)); HBRUSH hSelBrush = CreateSolidBrush(GetColorManager()->GetColor(kTrackbarSelKeys)); // render keys themselves for ( int i=0; i<n; ++i ) { TimeValue t = GetKeyTime( i ); if ( t < leftTime || t > rightTime ) continue; GetValue(t,&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); x = TimeToScreen(t,tzoom,tscroll); SelectObject( hdc, IsKeySelected( i ) ? hSelBrush : hUnselBrush ); Rectangle(hdc,x-3,y-3,x+3,y+3); } SetBkMode(hdc,OPAQUE); SelectObject(hdc,GetStockObject(BLACK_PEN)); DeleteObject(spen); DeleteObject(dpen); DeleteObject(hUnselBrush); DeleteObject(hSelBrush); return 0; }
void CEditView::DrawLine( int nLine, HDC hDC, int x, int y, int xDividerStart ) const { int nLineLen = m_pBuffer->GetLineLength( nLine ); BOOL bUseColor = ( m_pCtrl->UseColorSyntax() && ( nLineLen <= MAXCOL ) ); int nViewCol = m_nLeftIndex; int nBuffColStart = m_pBuffer->ConvertViewColToBufferCol( nLine, nViewCol, FALSE ); int xLeft = x; // highlight this line if appropriate BOOL bHighlight = m_pBuffer->IsHighlighted( nLine ); if ( bHighlight ) { // fill out the rest of the line with the highlight RECT rc = m_rcView; rc.left = x; rc.top = y; rc.bottom = y + m_cyLine; SetBkColor( hDC, m_pCtrl->GetHighlightedLineColor() ); ExtTextOut( hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL ); } BOOL bMBCS = DBCS_ACTIVE; #ifdef _UNICODE int nRightIndex = m_nRightIndex; #else int nRightIndex = m_nRightIndex + bMBCS * 2; // always paint two more TCHARs so multibyte chars aren't truncated #endif if ( nBuffColStart < nLineLen ) // else nothing to draw { // wait for nLine to become available (in case of background syntax parsing) m_pBuffer->WaitForLine( nLine ); LPCTSTR pszLineStart = m_pBuffer->GetLineText( nLine ); register LPCTSTR psz = pszLineStart + nBuffColStart; LPCTSTR pszStart = psz; ////////////////////////////////////////////////////////////////////////// // Step 1: Expand tabs // BOOL bViewWhitespace = m_pCtrl->DisplayWhitespace(); TCHAR szLine[ 1000 ]; CharFill( szLine, _T(' '), ARRAY_SIZE( szLine ) ); int cbTab = m_pBuffer->GetTabSize(); LPTSTR pszBuff = szLine; TCHAR chTab, chSpace; if ( bMBCS ) { chTab = _T('^'); chSpace = _T('`'); } else { chTab = _T('»'); chSpace = _T('·'); } while ( *psz && ( nViewCol <= nRightIndex ) ) { if ( *psz == _T('\t') ) { int nSpaces = ( ( nViewCol / cbTab ) * cbTab ) + cbTab - nViewCol; if ( nSpaces ) { if ( bViewWhitespace ) { if ( psz != pszStart || m_nLeftIndex == m_pBuffer->ConvertBufferColToViewCol( nLine, nBuffColStart ) ) { *pszBuff = chTab; } } pszBuff += nSpaces; nViewCol += nSpaces; } } else { if ( bViewWhitespace && *psz == _T(' ') ) { *pszBuff++ = chSpace; } else { *pszBuff++ = *psz; } nViewCol++; } psz++; } ////////////////////////////////////////////////////////////////////////// // Step 2: Parse the line and assign colors to everything // DWORD clrLine[ 100 ]; // hiword = token, loword = token offset in szLine int nColors = 0; if ( bUseColor ) { psz = pszLineStart; int nParseLen = m_pBuffer->ConvertViewColToBufferCol( nLine, nRightIndex ) + 20; // +20 is a reasonable max token length nParseLen = min( nParseLen, nLineLen ); nViewCol = 0; int nBuffCol = 0; int nFirstColorViewCol = m_nLeftIndex; BOOL bColorIsVisible = nViewCol >= nFirstColorViewCol; CLineParser Parser( m_pBuffer, nLine, nParseLen ); // pick up where the last line left off -- in a multi-line comment block (or not) clrLine[ nColors++ ] = MAKELPARAM( 0, ( WORD ) ( Parser.m_bInComment ? CBuffer::eMultiLineCommentStart : ( Parser.m_bInString ? CBuffer::eStringDelim : ( Parser.m_bInTag ? CBuffer::eTagText : CBuffer::eText ) ) ) ); while ( Parser.MoreComing() ) { Parser.AcceptToken(); int nTokenStartCol = nViewCol; nBuffCol += Parser.m_nTokenLen; if ( Parser.m_bHasTab ) { ASSERT( Parser.m_eToken == CBuffer::eText || Parser.m_eToken == CBuffer::eTagText || Parser.m_eToken == CBuffer::eStringDelim || Parser.m_eToken == CBuffer::eSingleLineComment ); nViewCol = m_pBuffer->ConvertBufferColToViewCol( nLine, nBuffCol ); } else { nViewCol += Parser.m_nTokenLen; } if ( !bColorIsVisible ) { // Assume this token (unless in a comment) will be the first token to cross the left edge clrLine[ 0 ] = MAKELPARAM( 0, ( WORD )( Parser.m_bInComment ? CBuffer::eMultiLineCommentStart : ( Parser.m_bInString ? CBuffer::eStringDelim : Parser.m_eToken ) ) ); if ( nViewCol > nFirstColorViewCol ) { ////////////////////////// // token is now in view // bColorIsVisible = TRUE; nTokenStartCol = nFirstColorViewCol; } } // record the token position if ( nTokenStartCol > nRightIndex ) { break; } if ( bColorIsVisible && !Parser.m_bWasInComment && !Parser.m_bIsCommentEndToken && !Parser.m_bWasInString && !Parser.m_bIsStringEndToken ) { clrLine[ nColors++ ] = MAKELPARAM( nTokenStartCol - m_nLeftIndex, ( WORD ) Parser.m_eToken ); } clrLine[ nColors ] = MAKELPARAM( ( nViewCol > m_nLeftIndex ? nViewCol : nRightIndex ) - m_nLeftIndex, ( WORD ) Parser.m_eToken ); // don't blow past the local array and corrupt the stack! if ( nColors >= ARRAY_SIZE( clrLine ) - 1 ) { nColors = 0; goto no_color; } } } else { no_color: clrLine[ nColors++ ] = MAKELPARAM( 0, ( WORD ) CBuffer::eText ); // draw text only as far as is necessary. We don't want to paint extra characters that aren't // in the buffer. If underline font used on plain text, the underline will extend to the edge of the window. // we don't want that. int nViewColEnd = m_pBuffer->ConvertBufferColToViewCol( nLine, nLineLen ); nViewColEnd = min( nRightIndex, nViewColEnd ); nViewColEnd = max( m_nLeftIndex, nViewColEnd ); clrLine[ nColors ] = MAKELPARAM( nViewColEnd - m_nLeftIndex, ( WORD ) CBuffer::eText ); } ////////////////////////////////////////////////////////////////////////// // Step 3: Output the line // ASSERT( nColors ); BOOL bFirstToken = TRUE; for ( int i = 0; i < nColors; i++ ) { DWORD dwColorInfo = clrLine[ i ]; CBuffer::LangToken eToken = ( CBuffer::LangToken ) HIWORD( dwColorInfo ); SetTextColor( hDC, m_pCtrl->GetTokenColor( eToken, TRUE ) ); COLORREF crBk = bHighlight ? m_pCtrl->GetHighlightedLineColor() : m_pCtrl->GetTokenColor( eToken, FALSE ); if ( crBk != CLR_INVALID ) { SetBkColor( hDC, crBk ); SetBkMode( hDC, OPAQUE ); } else { SetBkMode( hDC, TRANSPARENT ); } long cxExtraSpacing, cyDescentShift; SelectObject( hDC, m_pCtrl->GetTokenFont( eToken, cxExtraSpacing, cyDescentShift, m_pCtrl->m_font ) ); SetTextCharacterExtra( hDC, cxExtraSpacing ); int nTokenStart = LOWORD( dwColorInfo ); int nTokenNext = LOWORD( clrLine[ i + 1 ] ); int cbToken = nTokenNext - nTokenStart; if ( cbToken ) { #ifndef _UNICODE // The first visible token on the left of the line might be cutoff right // in the middle of a multi-byte char. We need to account for this by not // rendering the character (just leave whitespace). if ( bFirstToken && _ismbstrail( ( const unsigned char * ) pszLineStart, ( const unsigned char * ) pszStart ) ) { // scan backwards to the lead byte LPCTSTR pszLead = pszStart; while ( _ismbstrail( ( const unsigned char * ) pszLineStart, ( const unsigned char * ) --pszLead ) ) ; int cbChar = pszStart - pszLead; nTokenStart += cbChar; cbToken -= cbChar; x += ( cbChar * m_cxChar ); } #endif bFirstToken = FALSE; ExtTextOut( hDC, x, y - cyDescentShift, 0, NULL, szLine + nTokenStart, cbToken, NULL ); x += ( cbToken * m_cxChar ); } // don't worry about deselecting the font -- it will be cleaned up by any // calling method (as an optimization) } } ////////////////////////////////////////////////////////////////////////// // Step 4: give the parent window a crack at painting, too. // DWORD dwStyle = m_pBuffer->GetLineStyle( nLine ); if ( HAS_FLAG( dwStyle, CML_OWNERDRAW ) ) { CM_DRAWLINEDATA dld; dld.hDC = hDC; dld.rcLine.left = xLeft; dld.rcLine.top = y; dld.rcLine.right = m_rcView.right; dld.rcLine.bottom = y + m_cyLine; dld.nLine = nLine; dld.nLeftCol = m_nLeftIndex; dld.nRightCol = m_nRightIndex; dld.lParam = m_pBuffer->GetItemData( nLine ); dld.dwStyle = dwStyle; m_pCtrl->NotifyParent( CMN_DRAWLINE, ( NMHDR * ) &dld ); } // Draw divider line underneath the line if appropriate if ( m_pBuffer->HasDivider( nLine ) ) { COLORREF crDividerLine = m_pCtrl->GetHDividerLineColor(); COLORREF crWindow = m_pCtrl->GetWindowColor( TRUE ); // if line will blend in with the background, make it visible (opposite of window color). if ( crDividerLine == CLR_INVALID || crDividerLine == crWindow ) crDividerLine = ( ~crWindow & 0x00ffffff ); HPEN hPen = CreatePen( PS_SOLID, CY_DIVIDERLINE, crDividerLine ); HPEN hPenOld = ( HPEN ) SelectObject( hDC, hPen ); int yLine = y + m_cyLine - 1; MoveToEx( hDC, xDividerStart, yLine, NULL ); LineTo( hDC, m_rcView.right, yLine ); SelectObject( hDC, hPenOld ); DeleteObject( hPen ); } }
static void myDrawAxesSprite( const ON_Viewport& viewport, HDC hdc ) { // Use simple Windows calls to draw world axes sprite in lower left corner. // Note that Windows has screen (0,0) in the upper left corner; i.e, // screen "y" increases downwards. if ( !hdc ) return; const int axes_size = 30; int port_left, port_right, port_top, port_bottom; if ( !viewport.GetScreenPort( &port_left, &port_right, &port_bottom, &port_top, NULL, NULL ) ) return; const int scr_width = port_right - port_left; // no "+1" here const int scr_height = port_bottom - port_top; // no "+1" here if (4*axes_size >= scr_width ) return; if (4*axes_size >= scr_height ) return; int x0 = 3*axes_size/2; int y0 = port_bottom - 3*axes_size/2; int indx[3] = {0,1,2}; double scr_coord[3][2]; viewport.GetCoordinateSprite( axes_size, x0, y0, indx, scr_coord ); #define LXSIZE 3 #define LYSIZE 3 #define LOFF 3 // draw 3 axes from back to front HPEN axis_pen[3]; axis_pen[0] = CreatePen( PS_SOLID, 2, RGB(255,0,0) ); axis_pen[1] = CreatePen( PS_SOLID, 2, RGB(0,255,0) ); axis_pen[2] = CreatePen( PS_SOLID, 2, RGB(0,0,255) ); HGDIOBJ saved_pen = SelectObject( hdc, axis_pen[0] ); int i, k, x, y, lx, ly; for (i=0;i<3;i++) { k = indx[i]; x = (int)scr_coord[k][0]; y = (int)scr_coord[k][1]; // use direction of screen vector to determine letter placement lx = x-x0; ly = y-y0; if (abs(lx) > abs(ly)) { // center letter to right/left of axis end lx = (x >= x0) ? x + LXSIZE+LOFF : x - LXSIZE-LOFF; ly = y; } else if (abs(ly) > abs(lx)) { // center letter above/below axis end lx = x; ly = (y >= y0) ? y + LYSIZE+LOFF : y - LYSIZE-LOFF; } else if (lx) { // diagonal axis - center letter on axis lx = (x >= x0) ? x + LXSIZE+LOFF : x - LXSIZE-LOFF; ly = (y >= y0) ? y + LYSIZE+LOFF : y - LYSIZE-LOFF; } else { // axis is perp to screen - center letter at axis end lx = x; ly = y; } SelectObject( hdc, axis_pen[k] ); // draw axis MoveToEx( hdc, x0, y0, NULL ); LineTo( hdc, x, y ); // draw axis label switch (k) { case 0: // X MoveToEx( hdc, lx-LXSIZE, ly-LYSIZE, NULL ); LineTo( hdc, lx+LXSIZE, ly+LYSIZE ); MoveToEx( hdc, lx-LXSIZE, ly+LYSIZE, NULL ); LineTo( hdc, lx+LXSIZE, ly-LYSIZE ); break; case 1: // Y MoveToEx( hdc, lx-LXSIZE, ly-LYSIZE, NULL ); LineTo( hdc, lx, ly ); LineTo( hdc, lx+LXSIZE, ly-LYSIZE ); MoveToEx( hdc, lx, ly, NULL ); LineTo( hdc, lx, ly+LYSIZE ); break; case 2: // Z MoveToEx( hdc, lx-LXSIZE, ly-LYSIZE, NULL ); LineTo( hdc, lx+LXSIZE, ly-LYSIZE ); LineTo( hdc, lx-LXSIZE, ly+LYSIZE ); LineTo( hdc, lx+LXSIZE, ly+LYSIZE ); break; } } SelectObject( hdc, saved_pen ); DeleteObject( axis_pen[0] ); DeleteObject( axis_pen[1] ); DeleteObject( axis_pen[2] ); #undef LXSIZE #undef LYSIZE #undef LOFF }
/** * Below CheckMessageBoxProc adds everyones favorite "don't show again" checkbox to the dialog * much of the layout code (especially for XP and older windows versions) is copied with changes * from a GPL'ed project emabox at SourceForge. **/ LRESULT CALLBACK CheckMessageBoxProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_COMMAND: { if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == 2025) { const LRESULT res = SendMessage((HWND)lParam, BM_GETSTATE, 0, 0); bool bCheckedAfter = ((res & BST_CHECKED) == 0); // Update usedata ExMessageBox::SetUserData((void*)(bCheckedAfter ? BST_CHECKED : BST_UNCHECKED)); //-V204 SendMessage((HWND)lParam, BM_SETCHECK, bCheckedAfter ? BST_CHECKED : BST_UNCHECKED, 0); } } break; case WM_ERASEBKGND: { // Vista+ has grey strip #ifdef FLYLINKDC_SUPPORT_WIN_XP if (CompatibilityManager::isOsVistaPlus()) #endif { RECT rc = {0}; HDC dc = (HDC)wParam; // Fill the entire dialog GetClientRect(hWnd, &rc); FillRect(dc, &rc, GetSysColorBrush(COLOR_WINDOW)); // Calculate strip height RECT rcButton = {0}; GetWindowRect(FindWindowEx(hWnd, NULL, L"BUTTON", NULL), &rcButton); int stripHeight = (rcButton.bottom - rcButton.top) + 24; // Fill the strip rc.top += (rc.bottom - rc.top) - stripHeight; FillRect(dc, &rc, GetSysColorBrush(COLOR_3DFACE)); // Make a line HGDIOBJ oldPen = SelectObject(dc, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DLIGHT))); MoveToEx(dc, rc.left - 1, rc.top, (LPPOINT)NULL); LineTo(dc, rc.right, rc.top); DeleteObject(SelectObject(dc, oldPen)); return S_OK; } } break; case WM_CTLCOLORSTATIC: { // Vista+ has grey strip if ( #ifdef FLYLINKDC_SUPPORT_WIN_XP CompatibilityManager::isOsVistaPlus() && #endif ((HWND)lParam == GetDlgItem(hWnd, 2025))) { HDC hdc = (HDC)wParam; SetBkMode(hdc, TRANSPARENT); return (LRESULT)GetSysColorBrush(COLOR_3DFACE); } } break; case WM_INITDIALOG: { RECT rc = {0}; HWND current = NULL; int iWindowWidthBefore; int iWindowHeightBefore; int iClientHeightBefore; int iClientWidthBefore; pair<LPCTSTR, UINT> checkdata = (*(pair<LPCTSTR, UINT>*)ExMessageBox::GetUserData()); GetClientRect(hWnd, &rc); iClientHeightBefore = rc.bottom - rc.top; iClientWidthBefore = rc.right - rc.left; GetWindowRect(hWnd, &rc); iWindowWidthBefore = rc.right - rc.left; iWindowHeightBefore = rc.bottom - rc.top; // Create checkbox (resized and moved later) HWND check = CreateWindow(L"BUTTON", checkdata.first, WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_VCENTER | BS_CHECKBOX, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWnd, (HMENU)2025, GetModuleHandle(NULL), NULL ); // Assume checked by default SendMessage(check, BM_SETCHECK, checkdata.second, 0); //-V106 ExMessageBox::SetUserData((void*)checkdata.second); //-V204 // Apply default font const int cyMenuSize = GetSystemMetrics(SM_CYMENUSIZE); const int cxMenuSize = GetSystemMetrics(SM_CXMENUSIZE); const HFONT hNewFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); HFONT hOldFont; SIZE size; SendMessage(check, WM_SETFONT, (WPARAM)hNewFont, (LPARAM)TRUE); // Get the size of the checkbox HDC hdc = GetDC(check); hOldFont = (HFONT)SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT)); GetTextExtentPoint32(hdc, checkdata.first, wcslen(checkdata.first), &size); //-V107 SelectObject(hdc, hOldFont); int l_res = ReleaseDC(check, hdc); dcassert(l_res); // Checkbox dimensions int iCheckboxWidth = cxMenuSize + size.cx + 1; int iCheckboxHeight = (cyMenuSize > size.cy) ? cyMenuSize : size.cy; // Vista+ has a different kind of layout altogether #ifdef FLYLINKDC_SUPPORT_WIN_XP if (CompatibilityManager::isOsVistaPlus()) #endif { // Align checkbox with buttons (aproximately) int iCheckboxTop = int(iClientHeightBefore - (iCheckboxHeight * 1.70)); MoveWindow(check, 5, iCheckboxTop, iCheckboxWidth, iCheckboxHeight, FALSE); // Resize and re-center dialog int iWindowWidthAfter = iWindowWidthBefore + iCheckboxWidth; int iWindowLeftAfter = rc.left + (iWindowWidthBefore - iWindowWidthAfter) / 2; MoveWindow(hWnd, iWindowLeftAfter, rc.top, iWindowWidthAfter, iWindowHeightBefore, TRUE); // Go through the buttons and move them while ((current = FindWindowEx(hWnd, current, L"BUTTON", NULL)) != NULL) { if (current == check) continue; RECT rc; GetWindowRect(current, &rc); ScreenToClient(hWnd, &rc); MoveWindow(current, rc.left + iCheckboxWidth, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE); } } #ifdef FLYLINKDC_SUPPORT_WIN_XP else { RECT rt = {0}, rb = {0}; // Let's find us the label while ((current = FindWindowEx(hWnd, current, L"STATIC", NULL)) != NULL) { if (GetWindowTextLength(current) > 0) { GetWindowRect(current, &rt); ScreenToClient(hWnd, &rt); //current = NULL; [-] IRainman. break; } } // For correcting width, here just to make lines shorter int iWidthAdjustment = (rt.left + iCheckboxWidth) - iWindowWidthBefore; // Go through the buttons and move them current = NULL; while ((current = FindWindowEx(hWnd, current, L"BUTTON", NULL)) != NULL) { if (current == check) continue; GetWindowRect(current, &rb); ScreenToClient(hWnd, &rb); MoveWindow(current, rb.left + (iWidthAdjustment > 0 ? (iWidthAdjustment + 15) / 2 : 0), rb.top + iCheckboxHeight, rb.right - rb.left, rb.bottom - rb.top, FALSE); } // Move the checkbox int iCheckboxTop = rt.top + (rt.bottom - rt.top) + ((rb.top - rt.bottom) / 2); MoveWindow(check, rt.left, iCheckboxTop, iCheckboxWidth, iCheckboxHeight, FALSE); // Resize and re-center dialog int iWindowHeightAfter = iWindowHeightBefore + iCheckboxHeight; int iWindowTopAfter = rc.top + (iWindowHeightBefore - iWindowHeightAfter) / 2; int iWindowWidthAfter = (iWidthAdjustment > 0) ? iWindowWidthBefore + iWidthAdjustment + 15 : iWindowWidthBefore; int iWindowLeftAfter = rc.left + (iWindowWidthBefore - iWindowWidthAfter) / 2; MoveWindow(hWnd, iWindowLeftAfter, iWindowTopAfter, iWindowWidthAfter, iWindowHeightAfter, TRUE); } #endif // FLYLINKDC_SUPPORT_WIN_XP } break; } return ::CallWindowProc(ExMessageBox::GetMessageBoxProc(), hWnd, uMsg, wParam, lParam); // Кончается стек... бесконечная рекурсия }
//绘制实验统计数据图表 void draw_stat_chart(PHISTORY history, RECT &rect, int max_round, int min_round, double max_value, double min_value, int type) { int x = type == 0 ? rect.left : rect.right; if(type < 2) { draw_line(x, rect.top, x, rect.bottom); } int h = (rect.bottom - rect.top) / DRAW_STAT_TAG_NUM; x += type == 0 ? -DRAW_STAT_TAG_LEN : DRAW_STAT_TAG_LEN; int y = rect.bottom; double value = (max_value - min_value) / DRAW_STAT_TAG_NUM; char buf[MAX_LOADSTRING]; for(int i=0;i<=DRAW_STAT_TAG_NUM;i++) { if(type < 2) { draw_line(x, y, type == 0 ? rect.left : rect.right, y); } sprintf_s(buf, sizeof(buf), "%.1f", min_value + value * i); switch(type) { case 0: { RECT r = {gDrawClientRect.left, y - h, x, y}; DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_RIGHT | DT_BOTTOM | DT_SINGLELINE); } break; case 1: { RECT r = {x, y - h, gDrawClientRect.right, y}; DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_LEFT | DT_BOTTOM | DT_SINGLELINE); } break; default: if(i > 0) { RECT r = {x, y, gDrawClientRect.right, y + h}; DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_LEFT | DT_TOP | DT_SINGLELINE); } break; } y -= h; } PHISTORYITEM p = history->head; int height = rect.bottom - rect.top; int width = rect.right - rect.left; const int cr = type == 0 ? 4 : 3; int i = 0; while(p != NULL) { x = rect.left + width * (p->round - min_round) / (max_round - min_round); switch(type) { case 0: y = rect.bottom - (int)(height * (p->top[0].generation - min_value) / (max_value - min_value)); break; case 1: value = (double)p->round / p->top[0].generation; y = rect.bottom - (int)(height * (value - min_value) / (max_value - min_value)); break; default: value = (double)p->top[0].score / gConfig.lab_more_count; y = rect.bottom - (int)(height * (value - min_value) / (max_value - min_value)); break; } if(i > 0) { LineTo(gDrawBmpMemDC, x, y); } else { MoveToEx(gDrawBmpMemDC, x, y, NULL); Ellipse(gDrawBmpMemDC, x-cr, y-cr, x+cr, y+cr); } i++; p = p->next; } if(i > 1) { Ellipse(gDrawBmpMemDC, x-cr, y-cr, x+cr, y+cr); } switch(type) { case 0: { RECT r = {rect.left, gDrawClientRect.top, rect.right/3, rect.top}; sprintf_s(buf, sizeof(buf), "%s", "—— 子代"); DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_RIGHT | DT_VCENTER | DT_SINGLELINE); } break; case 1: { RECT r = {rect.right/3, gDrawClientRect.top, rect.right*2/3, rect.top}; sprintf_s(buf, sizeof(buf), "%s", "—— 代比"); DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE); } break; default: { RECT r = {rect.right*2/3, gDrawClientRect.top, rect.right, rect.top}; sprintf_s(buf, sizeof(buf), "%s", "—— 平均分"); DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_LEFT | DT_VCENTER | DT_SINGLELINE); } break; } }
INT_PTR CKeyProp::OnReceiveMsg(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { static COLORREF acrCustomClr[16]; switch (msg) { case WM_DRAWITEM: // Paint the color swatch if (wParam == IDC_KEY_COLOR) { DRAWITEMSTRUCT *pDraw = (DRAWITEMSTRUCT*)lParam; if (IsWindowEnabled(GetDlgItem(m_hDlg, IDC_KEY_PICK_COLOR))) { HBRUSH solidBrush = CreateSolidBrush(m_dwColor); FillRect(pDraw->hDC, &pDraw->rcItem, solidBrush); DeleteObject(solidBrush); } else // Color is disabled for this key type { // Gray the color swatch FillRect(pDraw->hDC, &pDraw->rcItem, (HBRUSH)GetStockObject(LTGRAY_BRUSH)); // 'X' out the swatch MoveToEx(pDraw->hDC, 0, 0, 0); LineTo(pDraw->hDC, pDraw->rcItem.right, pDraw->rcItem.bottom); MoveToEx(pDraw->hDC, pDraw->rcItem.right, 0, 0); LineTo(pDraw->hDC, 0, pDraw->rcItem.bottom); } FrameRect(pDraw->hDC, &pDraw->rcItem, (HBRUSH)GetStockObject(BLACK_BRUSH)); return TRUE; } break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_KEY_TYPE: if (HIWORD(wParam) == CBN_SELCHANGE) { m_iKey = (int) SendMessage(GetDlgItem(m_hDlg, IDC_KEY_TYPE), CB_GETCURSEL, 0, 0); if (m_iKey== CB_ERR) { m_iKey = DXTKEY_RGB; } UpdateControls(); return TRUE; } break; case IDC_KEY_PICK_COLOR: { CHOOSECOLOR cc; ZeroMemory(&cc, sizeof(CHOOSECOLOR)); cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = m_hDlg; cc.lpCustColors = (LPDWORD)acrCustomClr; cc.Flags = CC_RGBINIT; cc.rgbResult = m_dwColor; if (ChooseColor(&cc)) { m_dwColor = cc.rgbResult; InvalidateRect(GetDlgItem(hDlg, IDC_KEY_COLOR), 0, FALSE); } } return TRUE; } // inner switch break; } // default return FALSE; }
//画线 void draw_line(int x1, int y1, int x2, int y2) { MoveToEx(gDrawBmpMemDC, x1, y1, NULL); LineTo(gDrawBmpMemDC, x2, y2); }
bool playlist_view::draw_items(HDC dc, int start_item, int count) { // profiler(draw_items); if (!drawing_enabled) return false; static_api_ptr_t<playlist_manager> playlist_api; HDC hdc_mem = 0; RECT rect, item, item_area, bk, draw/*,text*/; GetClientRect(wnd_playlist, &rect); rect.top += get_header_height(); int item_height = get_item_height(); HBRUSH br = 0; HBITMAP hbm_mem = 0, hbm_old = 0; pfc::array_t<int, pfc::alloc_fast_aggressive> widths; int total_width = get_column_widths(widths); int t = columns.get_count(); const bit_array & p_mask = g_cache.active_get_columns_mask(); item_area.left = rect.left; item_area.right = rect.right; item_area.top = rect.top + (item_height*start_item); item_area.bottom = item_area.top + (item_height*count); item.left = 0 - horizontal_offset; item.right = item.left + total_width; item.top = 0; item.bottom = item.top + item_height; bk.top = 0; bk.left = 0; bk.bottom = item_height*count; bk.right = rect.right - rect.left; /*static */pfc::string8_fast_aggressive temp; temp.prealloc(512); /* edit01 */ hdc_mem = CreateCompatibleDC(dc); COLORREF colourfore = 0xff; hbm_mem = CreateCompatibleBitmap(dc, rect.right - rect.left, item_height*count); hbm_old = (HBITMAP)SelectObject(hdc_mem, hbm_mem); HGDIOBJ font_old = SelectObject(hdc_mem, g_font); cui::colours::helper p_helper(appearance_client_pv_impl::g_guid); //fill entire area with back colour br = CreateSolidBrush(p_helper.get_colour(cui::colours::colour_background)); FillRect(hdc_mem, &bk, br); DeleteObject(br); //need checks here because of filling background { int total = playlist_api->activeplaylist_get_item_count(); if (start_item + count + scroll_item_offset > total) //end item is NOT inclusive { count -= (start_item + count + scroll_item_offset) - total; } } int end_item = start_item + count; //draw each item int n, focus = playlist_api->activeplaylist_get_focus_item(); // static int pcount; t_size playing_index, playing_playlist; playlist_api->get_playing_item_location(&playing_playlist, &playing_index); bool b_playback = static_api_ptr_t<play_control>()->is_playing(); if (g_cache.get_active_playlist() != playing_playlist) playing_index = pfc_infinite; for (n = start_item; n < end_item; n++) { bool sel = playlist_api->activeplaylist_is_item_selected(n + scroll_item_offset); bool b_focused = GetFocus() == wnd_playlist || IsChild(wnd_playlist, GetFocus()); bool b_playing = b_playback && playing_index == (n + scroll_item_offset); //draw each column of each item int theme_state = NULL; if (sel) theme_state = (b_playing ? LISS_HOTSELECTED : (b_focused ? LISS_SELECTED : LISS_SELECTEDNOTFOCUS)); else if (b_playing) theme_state = LISS_HOT; bool b_themed = m_theme && p_helper.get_themed() && IsThemePartDefined(m_theme, LVP_LISTITEM, theme_state); if (b_themed && theme_state) { if (IsThemeBackgroundPartiallyTransparent(m_theme, LVP_LISTITEM, theme_state)) DrawThemeParentBackground(get_wnd(), hdc_mem, &item); DrawThemeBackground(m_theme, hdc_mem, LVP_LISTITEM, theme_state, &item, NULL); } //int total = playlist_api->activeplaylist_get_item_count(); int c, offset = 0, i = 0; for (c = 0; c < t; c++) { if (p_mask[c]) { draw.left = item.left + offset; draw.top = item.top; offset += widths[i]; draw.right = item.left + offset; draw.bottom = item.bottom; { // profiler_debug(draw_item_get_string); g_cache.active_get_display_name(n + scroll_item_offset, i, temp); } colourinfo colours(0x000000, 0x000000, 0xFF, 0xFF, 0, 0xFF); g_cache.active_get_colour(n + scroll_item_offset, i, colours); if (b_themed) { //COLORREF cr_back= get_default_colour(colours::COLOUR_BACK); //colourfore = get_default_colour(colours::COLOUR_TEXT); //GetThemeColor(m_theme, LVP_LISTITEM, sel ? (GetFocus() == wnd_playlist ? LIS_SELECTED : LIS_SELECTEDNOTFOCUS) : LIS_NORMAL, TMT_WINDOWTEXT, &colourfore); colourfore = GetThemeSysColor(m_theme, sel ? COLOR_BTNTEXT : COLOR_WINDOWTEXT); //GetThemeColor(m_theme, LVP_LISTITEM, sel ? (GetFocus() == wnd_playlist ? LIS_SELECTED : LIS_SELECTEDNOTFOCUS) : LIS_NORMAL, TMT_TEXTCOLOR, &colourfore); if (!theme_state) { //GetThemeColor(m_theme, LVP_LISTITEM, LIS_NORMAL, TMT_FILLCOLOR, &colourfore); br = CreateSolidBrush(colours.background_colour); FillRect(hdc_mem, &draw, br); } } else { if (sel) { /* TEST */ if (GetFocus() == wnd_playlist) { colourfore = colours.selected_text_colour; br = CreateSolidBrush(colours.selected_background_colour); } else { colourfore = colours.selected_text_colour_non_focus; br = CreateSolidBrush(colours.selected_background_colour_non_focus); } } else { colourfore = colours.text_colour; br = CreateSolidBrush(colours.background_colour); } //draw cell background //if (!b_themed) FillRect(hdc_mem, &draw, br); } if (br) { DeleteObject(br); br = 0; } //render text //if (b_themed) // DrawThemeText(m_theme, hdc_mem, LVP_LISTITEM, sel ? (GetFocus() == wnd_playlist ? LIS_SELECTED : LIS_SELECTEDNOTFOCUS) : LIS_NORMAL, L"test", 4, 0, 0, &draw); //else ui_helpers::text_out_colours_tab(hdc_mem, temp, temp.length(), 2, 1, &draw, sel, colourfore, TRUE, true, (cfg_ellipsis != 0), (ui_helpers::alignment)columns[c]->align); if (colours.use_frame_left) { HPEN pen = CreatePen(PS_SOLID, 1, colours.frame_left); HPEN pen_old = (HPEN)SelectObject(hdc_mem, pen); MoveToEx(hdc_mem, draw.left, draw.top, 0); LineTo(hdc_mem, draw.left, draw.bottom); SelectObject(hdc_mem, pen_old); DeleteObject(pen); } if (colours.use_frame_top) { HPEN pen = CreatePen(PS_SOLID, 1, colours.frame_top); HPEN pen_old = (HPEN)SelectObject(hdc_mem, pen); MoveToEx(hdc_mem, draw.left, draw.top, 0); LineTo(hdc_mem, draw.right, draw.top); SelectObject(hdc_mem, pen_old); DeleteObject(pen); } if (colours.use_frame_right) { HPEN pen = CreatePen(PS_SOLID, 1, colours.frame_right); HPEN pen_old = (HPEN)SelectObject(hdc_mem, pen); MoveToEx(hdc_mem, draw.right - 1, draw.top, 0); LineTo(hdc_mem, draw.right - 1, draw.bottom); SelectObject(hdc_mem, pen_old); DeleteObject(pen); } if (colours.use_frame_bottom) { HPEN pen = CreatePen(PS_SOLID, 1, colours.frame_bottom); HPEN pen_old = (HPEN)SelectObject(hdc_mem, pen); MoveToEx(hdc_mem, draw.right - 1, draw.bottom - 1, 0); LineTo(hdc_mem, draw.left - 1, draw.bottom - 1); SelectObject(hdc_mem, pen_old); DeleteObject(pen); } i++; } } //draw focus frame if ((n + scroll_item_offset) == focus) { if (m_always_show_focus || (!(SendMessage(get_wnd(), WM_QUERYUISTATE, NULL, NULL) & UISF_HIDEFOCUS) && b_focused)) { RECT rc_focus = item; if (m_theme && p_helper.get_themed() && IsThemePartDefined(m_theme, LVP_LISTITEM, LISS_SELECTED)) InflateRect(&rc_focus, -1, -1); if (!p_helper.get_bool(cui::colours::bool_use_custom_active_item_frame)) { DrawFocusRect(hdc_mem, &rc_focus); } else { br = CreateSolidBrush(p_helper.get_colour(cui::colours::colour_active_item_frame)); FrameRect(hdc_mem, &rc_focus, br); DeleteObject(br); } } } item.top += item_height; item.bottom += item_height; } BitBlt(dc, item_area.left, item_area.top, item_area.right - item_area.left, item_area.bottom - item_area.top, hdc_mem, 0, 0, SRCCOPY); if (font_old) SelectObject(hdc_mem, font_old); SelectObject(hdc_mem, hbm_old); DeleteObject(hbm_mem); DeleteDC(hdc_mem); return true; }
void TDC::move_to(int x, int y) //---------------------------- { MoveToEx(m_hdc,x,y,NULL); }
// 窗口消息处理函数 LRESULT APIENTRY MainWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; switch (message) { case WM_PAINT: hdc = BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); break; case WM_COMMAND: // 菜单命令 switch (wParam) { case IDM_VANISH: // 消除客户区(在设置了修剪全其输出范围也会被限制) hdc = GetDC(hwnd); GetClientRect(hwnd, &rc); FillRect(hdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH)); DeleteDC( hdc); break; // 根据用户的菜单输入,设置修剪路径的组合模式 case IDM_AND: iMode = RGN_AND; break; case IDM_COPY: iMode = RGN_COPY; break; case IDM_DIFF: iMode = RGN_DIFF; break; case IDM_OR: iMode = RGN_OR; break; case IDM_XOR: iMode = RGN_XOR; break; case IDM_CLIP: { // 获取窗口客户区的DC hdc = GetDC(hwnd); // 创建并为DC选择字体 // 消息在菜单中点击此项前需先选择字体 hfont = CreateFontIndirect(cf.lpLogFont); hfontOld = (HFONT)SelectObject(hdc, hfont); // 五个点,用于创建五角星区域 POINT point[5]= {{0,200},{600,200},{100,600},{300,0},{500,600}}; // 创建多边形区域,五角星 hrgn = CreatePolygonRgn(point, 5, WINDING); // 将区域选择为修剪区域 SelectClipRgn(hdc, hrgn); // 输出的文字 LPSTR szOut = "Lorem ipsum dolor sit amet, consectetur \n" "adipisicing elit, sed do eiusmod tempor \n" "incididunt ut labore et dolore magna \n" "aliqua. Ut enim ad minim veniam, quis \n" "nostrud exercitation ullamco laboris nisi \n" "ut aliquip ex ea commodo consequat. Duis \n" "aute irure dolor in reprehenderit in \n" "voluptate velit esse cillum dolore eu \n" "fugiat nulla pariatur. Excepteur sint \n" "occaecat cupidatat non proident, sunt \n" "in culpa qui officia deserunt mollit \n" "anim id est laborum.\n"; // 窗口客户区,用于输出文字 RECT rect; GetClientRect(hwnd,&rect); // 设置文字背景为透明 SetBkMode(hdc, TRANSPARENT); // 开始创建路径 BeginPath(hdc); // 路径的形状为输出的文字 DrawText(hdc, szOut, lstrlen(szOut),&rect , DT_CENTER); EndPath(hdc);// 路径已经为DC的当前路径 // 为DC选择修剪路径,使用用户通过菜单输入的模式 // 注意在进行此操作前需通过菜单选择组合模式 SelectClipPath(hdc, iMode); // 输出放射状直线,以左上角为原点 // 计算线的终点 for (i = 0; i < 90; i++) { aflSin[i] = sin( (((double)i) / 180.0) * 3.14159); } for (i = 0; i < 90; i++) { aflCos[i] = cos( (((double)i) / 180.0) * 3.14159); } flRadius = 1000;// 线的长度(窗口大小为600*650) // 画线,第一度画一条线 for (i = 0; i < 90; i++) { MoveToEx(hdc, nXStart, nYStart, (LPPOINT) NULL); LineTo(hdc, nXStart + ((int) (flRadius * aflCos[i])), nYStart + ((int) (flRadius * aflSin[i]))); } // 选择回字体,释放 SelectObject(hdc, hfontOld); DeleteObject(hfont); DeleteDC( hdc); // 刷新窗口 UpdateWindow(hwnd); break; } case IDM_FONT: // 用户选择字体 cf.lStructSize = sizeof (CHOOSEFONT); cf.hwndOwner = hwnd; cf.lpLogFont = &lf; cf.Flags = CF_SCREENFONTS | CF_EFFECTS; cf.rgbColors = RGB(0, 255, 255); cf.nFontType = SCREEN_FONTTYPE; ChooseFont(&cf); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
/** * \author Paul Henderson (PH, PTJK76) * \date August 2006 - Initial Creation, PH */ BOOL CALLBACK CSignature::SigProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam) { P_COORDXY pPoint; CSignature *pObj; HDC hdc; PAINTSTRUCT ps; static bool bOffScreen; switch(message) { case WM_LBUTTONDOWN: //grab a pointer to the object members pObj = (CSignature *)GetWindowLong(hWnd, GWL_USERDATA); if(LOWORD(lParam) && HIWORD(lParam) ){ pObj->m_pPrevPos = pObj->AddCoord(LOWORD(lParam),HIWORD(lParam),true);// the 'true' depicts a start line pObj->m_pCurrentVector = pObj->m_pCurrentPos; } pObj->m_bSigning = TRUE; break; case WM_LBUTTONUP: pObj = (CSignature *)GetWindowLong(hWnd, GWL_USERDATA); // Allows signature capture to save the vectors and send them using 'VectorNavigate' pObj->SendVectors(); pObj->m_bSigning = FALSE; break; case WM_MOUSEOUT: pObj = (CSignature *)GetWindowLong(hWnd, GWL_USERDATA); // Only send vectors if we are still signing otherwise we send the // last recorded vectors whenever the user clicks outside the Window. if (pObj->m_bSigning) { pObj->m_bSigning = FALSE; pObj->SendVectors(); } break; case WM_MOUSEMOVE: pObj = (CSignature *)GetWindowLong(hWnd, GWL_USERDATA); if(pObj->m_bSigning == FALSE){ //if we went offscreen pObj->m_pPrevPos = pObj->AddCoord(LOWORD(lParam),HIWORD(lParam),true);// the 'true' depicts a start line pObj->m_bSigning = TRUE; } //otherwise it is a valid onscreen coordinate pPoint = pObj->AddCoord(LOWORD(lParam),HIWORD(lParam),pObj->m_bNewLine); //check to make sure that we have a line to draw if(pPoint == NULL || pObj->m_pPrevPos == NULL) break; if(pPoint->bNewLine) { pObj->m_pPrevPos = pPoint; break; } //Draw the line hdc = GetDC(hWnd); //select the correct coloured pen SelectObject(hdc,CreatePen(PS_SOLID,pObj->m_iLineWidth,pObj->m_crLineColor)); MoveToEx(hdc,pObj->m_pPrevPos->XPos,pObj->m_pPrevPos->YPos,NULL); LineTo(hdc,LOWORD(lParam),HIWORD(lParam)); DeleteObject(SelectObject(hdc,GetStockObject(BLACK_PEN))); ReleaseDC(hWnd,hdc); pObj->m_pPrevPos = pPoint; break; case WM_PAINT: pObj = (CSignature *)GetWindowLong(hWnd, GWL_USERDATA); hdc = BeginPaint(hWnd,&ps); pObj->RePaintBox(hdc,TRUE);// second param paint background EndPaint(hWnd, &ps); break; case WM_DESTROY: pObj = (CSignature *)GetWindowLong(hWnd, GWL_USERDATA); pObj->DeleteSigMem(); break; default: return DefWindowProc(hWnd,message, wParam, lParam); } return TRUE; }
static void GroundDrawer(int id, HDC hDC) { double leftN[2], rightN[2], groundN[2], len, leftEx[2], rightEx[2], lenLeft, lenRight; POINT points[4]; COLORREF color; int drawLeft = 0, drawRight = 0, leftId, rightId; HBRUSH hBrush; HPEN hPen; if (gameState != STARTED) return; if (grounds[id].invisible || viewRect[2] < grounds[id].fromX || viewRect[0] > grounds[id].toX || (grounds[id].fromY > viewRect[3] && grounds[id].toY > viewRect[3])) return; color = DrawerColor(groundColor[grounds[id].traits], backgroundColor, grounds[id].color); hPen = CreatePen(PS_SOLID, 3, color); hBrush = CreateSolidBrush(DrawerColor(color, backgroundColor, 0.4)); SelectObject(hDC, hBrush); groundN[0] = grounds[id].fromY - grounds[id].toY; groundN[1] = grounds[id].toX - grounds[id].fromX; leftId = grounds[id].leftId; if (leftId != -1 && !grounds[leftId].invisible && grounds[leftId].toY == grounds[id].fromY) { AngularBisector(grounds[leftId].fromX - grounds[leftId].toX, grounds[leftId].fromY - grounds[leftId].toY, grounds[id].toX - grounds[id].fromX, grounds[id].toY - grounds[id].fromY, &leftN[0], &leftN[1]); } else if (leftId != -1 && !grounds[leftId].invisible) { if (grounds[leftId].toY > grounds[id].fromY) { AngularBisector(0.0, 1.0, grounds[id].toX - grounds[id].fromX, grounds[id].toY - grounds[id].fromY, &leftN[0], &leftN[1]); AngularBisector(grounds[leftId].fromX - grounds[leftId].toX, grounds[leftId].fromY - grounds[leftId].toY, 0.0, -1.0, &leftEx[0], &leftEx[1]); leftEx[1] *= GROUND_WIDTH / leftEx[0]; leftEx[0] *= GROUND_WIDTH / leftEx[0]; lenLeft = grounds[leftId].toY - grounds[id].fromY; drawLeft = 1; } else AngularBisector(0.0, -1.0, grounds[id].toX - grounds[id].fromX, grounds[id].toY - grounds[id].fromY, &leftN[0], &leftN[1]); } else { AngularBisector(0.0, 1.0, grounds[id].toX - grounds[id].fromX, grounds[id].toY - grounds[id].fromY, &leftN[0], &leftN[1]); leftEx[0] = GROUND_WIDTH; leftEx[1] = 0.0; lenLeft = viewRect[3] - grounds[id].fromY; drawLeft = 1; } len = (groundN[0] * leftN[0] + groundN[1] * leftN[1]) / sqrt(groundN[0] * groundN[0] + groundN[1] * groundN[1]); leftN[0] *= GROUND_WIDTH / len; leftN[1] *= GROUND_WIDTH / len; if (drawLeft) { WorldSetViewport(grounds[id].fromX, grounds[id].fromY); points[0].x = WorldX(0); points[0].y = WorldY(0); points[1].x = WorldX(leftN[0]); points[1].y = WorldY(leftN[1]); points[2].x = WorldX(leftEx[0]); points[2].y = WorldY(lenLeft + leftEx[1]); points[3].x = WorldX(0); points[3].y = WorldY(lenLeft); SelectObject(hDC, hPenNoOutline); Polygon(hDC, points, 4); SelectObject(hDC, hPen); MoveToEx(hDC, points[0].x, points[0].y, NULL); LineTo(hDC, points[3].x, points[3].y); } rightId = grounds[id].rightId; if (rightId != -1 && !grounds[rightId].invisible && grounds[rightId].fromY == grounds[id].toY) { AngularBisector(grounds[id].fromX - grounds[id].toX, grounds[id].fromY - grounds[id].toY, grounds[rightId].toX - grounds[rightId].fromX, grounds[rightId].toY - grounds[rightId].fromY, &rightN[0], &rightN[1]); } else if (rightId != -1 && !grounds[rightId].invisible) { if (grounds[rightId].fromY > grounds[id].toY) { AngularBisector(grounds[id].fromX - grounds[id].toX, grounds[id].fromY - grounds[id].toY, 0.0, 1.0, &rightN[0], &rightN[1]); AngularBisector(0.0, -1.0, grounds[rightId].toX - grounds[rightId].fromX, grounds[rightId].toY - grounds[rightId].fromY, &rightEx[0], &rightEx[1]); rightEx[1] *= -GROUND_WIDTH / rightEx[0]; rightEx[0] *= -GROUND_WIDTH / rightEx[0]; lenRight = grounds[rightId].fromY - grounds[id].toY; drawRight = 1; } else AngularBisector(grounds[id].fromX - grounds[id].toX, grounds[id].fromY - grounds[id].toY, 0.0, -1.0, &rightN[0], &rightN[1]); } else { AngularBisector(grounds[id].fromX - grounds[id].toX, grounds[id].fromY - grounds[id].toY, 0.0, 1.0, &rightN[0], &rightN[1]); rightEx[0] = -GROUND_WIDTH; rightEx[1] = 0.0; lenRight = viewRect[3] - grounds[id].toY; drawRight = 1; } len = (groundN[0] * rightN[0] + groundN[1] * rightN[1]) / sqrt(groundN[0] * groundN[0] + groundN[1] * groundN[1]); rightN[0] *= GROUND_WIDTH / len; rightN[1] *= GROUND_WIDTH / len; if (drawRight) { WorldSetViewport(grounds[id].toX, grounds[id].toY); points[0].x = WorldX(0); points[0].y = WorldY(0); points[1].x = WorldX(rightN[0]); points[1].y = WorldY(rightN[1]); points[2].x = WorldX(rightEx[0]); points[2].y = WorldY(lenRight + rightEx[1]); points[3].x = WorldX(0); points[3].y = WorldY(lenRight); SelectObject(hDC, hPenNoOutline); Polygon(hDC, points, 4); SelectObject(hDC, hPen); MoveToEx(hDC, points[0].x, points[0].y, NULL); LineTo(hDC, points[3].x, points[3].y); } WorldSetViewport(0.0, 0.0); points[0].x = WorldX(grounds[id].fromX); points[0].y = WorldY(grounds[id].fromY); points[1].x = WorldX(grounds[id].toX); points[1].y = WorldY(grounds[id].toY); points[2].x = WorldX(grounds[id].toX + rightN[0]); points[2].y = WorldY(grounds[id].toY + rightN[1]); points[3].x = WorldX(grounds[id].fromX + leftN[0]); points[3].y = WorldY(grounds[id].fromY + leftN[1]); SelectObject(hDC, hPenNoOutline); Polygon(hDC, points, 4); SelectObject(hDC, hPen); MoveToEx(hDC, points[0].x, points[0].y, NULL); LineTo(hDC, points[1].x, points[1].y); DeleteObject(hBrush); DeleteObject(hPen); }
void PaintMainWnd (HWND hWnd) { PAINTSTRUCT ps; RECT rect; HPEN hPen, hOld; ThreadData *ptd; TCHAR szName[4]; // short name! int myThread; HDC hDC; // always need a dc for drawing int i; // my favorite loop counter // // get the array index of this window // ptd = (ThreadData *)GetWindowLong (hWnd, GWL_USERDATA); myThread = ptd->index; // //Draw a rectangle for each desktop // hDC = BeginPaint (hWnd, &ps); if (GetClientRect (hWnd, &rect)) { int right, left; // // leave space for edit control and button // rect.bottom -= CONTROLHEIGHT; hPen = CreatePen (PS_SOLID | PS_INSIDEFRAME, 2, RGB(255,16,16)); hOld = SelectObject (hDC, hPen); // // draw each desktop rectangle // for (i=0;i<=gMaxIndex;i++) { right = gWidth * i + gWidth; left = right - gWidth; // // If no snapshot is available, be boring // if (!gHDCArray[i]) { Rectangle (hDC, left, rect.top, right, gHeight); wsprintf (szName, TEXT("%d"), i+1); TextOut (hDC, left+(gWidth/2), gHeight/2, szName, lstrlen (szName)); } else { // // BitBlt the snapshot into the rectangle // StretchBlt (hDC, left, rect.top, gWidth, gHeight, gHDCArray[i], 0, 0, gWidth*2, gHeight*2, SRCCOPY); // // draw lines around the rectangle // MoveToEx (hDC, left, rect.top, NULL); LineTo (hDC, left, gHeight); MoveToEx (hDC, right, rect.top, NULL); LineTo (hDC, right, gHeight); // // underline the active one // if (myThread == i) { MoveToEx (hDC, left, gHeight, NULL); LineTo (hDC, right, gHeight); } } } // // cleanup // SelectObject (hDC, hOld); DeleteObject (hPen); } EndPaint (hWnd, &ps); }
LRESULT CALLBACK HexEditorProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT r; // RECT r2; PAINTSTRUCT ps; SCROLLINFO si; // int dx1, dy1, dx2, dy2; // static int watchIndex=0; switch(uMsg) { case WM_CREATE: { HexDC = GetDC(hDlg); SelectObject(HexDC, HexFont); SetTextAlign(HexDC, TA_UPDATECP | TA_TOP | TA_LEFT); if (Full_Screen) { while (ShowCursor(false) >= 0); while (ShowCursor(true) < 0); } GetWindowRect(HWnd, &r); Hex.DialogPosX = r.right; Hex.DialogPosY = r.top; SetWindowPos( hDlg, NULL, Hex.DialogPosX, Hex.DialogPosY, Hex.DialogSizeX, Hex.DialogSizeY, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_SHOWWINDOW ); ZeroMemory(&si, sizeof(SCROLLINFO)); si.cbSize = sizeof(si); si.fMask = SIF_RANGE | SIF_PAGE; si.nMin = 0; si.nMax = _68K_RAM_SIZE / 16; si.nPage = 16; SetScrollInfo(hDlg, SB_VERT, &si, TRUE); return 0; } break; /* case WM_COMMAND: { switch(wParam) { case IDC_SAVE: { char fname[2048]; strcpy(fname,"dump.bin"); if(Change_File_S(fname,".","Save Full Dump As...","All Files\0*.*\0\0","*.*",hDlg)) { FILE *out=fopen(fname,"wb+"); int i; for (i=0;i<sizeof(Ram_68k);++i) { fname[i&2047]=Ram_68k[i^1]; if ((i&2047)==2047) fwrite(fname,1,sizeof(fname),out); } fwrite(fname,1,i&2047,out); fclose(out); } } break; case IDC_BUTTON1: { char fname[2048]; GetDlgItemText(hDlg,IDC_EDIT1,fname,2047); int CurPos; if ((strnicmp(fname,"ff",2)==0) && sscanf(fname+2,"%x",&CurPos)) { SetScrollPos(GetDlgItem(hDlg,IDC_SCROLLBAR1),SB_CTL,(CurPos>>4),TRUE); Update_RAM_Dump(); } } break; } } break; */ case WM_VSCROLL: { ZeroMemory(&si, sizeof(SCROLLINFO)); si.fMask = SIF_ALL; si.cbSize = sizeof(SCROLLINFO); GetScrollInfo(hDlg,SB_VERT,&si); switch(LOWORD(wParam)) { case SB_ENDSCROLL: case SB_TOP: case SB_BOTTOM: break; case SB_LINEUP: si.nPos--; break; case SB_LINEDOWN: si.nPos++; break; case SB_PAGEUP: si.nPos -= si.nPage; break; case SB_PAGEDOWN: si.nPos += si.nPage; break; case SB_THUMBPOSITION: case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; } if (si.nPos < si.nMin) si.nPos = si.nMin; if ((si.nPos + (int) si.nPage) > si.nMax) si.nPos = si.nMax - si.nPage; Hex.OffsetVisibleFirst = si.nPos * 16; SetScrollInfo(hDlg, SB_VERT, &si, TRUE); UpdateHexEditor(); return 0; } break; case WM_MOUSEWHEEL: { int WheelDelta = (short) HIWORD(wParam); ZeroMemory(&si, sizeof(SCROLLINFO)); si.fMask = SIF_ALL; si.cbSize = sizeof(SCROLLINFO); GetScrollInfo(hDlg, SB_VERT, &si); if (WheelDelta < 0) si.nPos += si.nPage; if (WheelDelta > 0) si.nPos -= si.nPage; if (si.nPos < si.nMin) si.nPos = si.nMin; if ((si.nPos + (int) si.nPage) > si.nMax) si.nPos = si.nMax - si.nPage; Hex.OffsetVisibleFirst = si.nPos*16; SetScrollInfo(hDlg,SB_VERT,&si,TRUE); UpdateHexEditor(); return 0; } break; case WM_PAINT: { BeginPaint(hDlg, &ps); static char buf[10]; int row = 0, line = 0; // TOP HEADER, static. for (row = 0; row < 16; row++) { MoveToEx(HexDC, row * Hex.CellWidth + Hex.GapHeaderH, 0, NULL); SetBkColor(HexDC, Hex.ColorBG); SetTextColor(HexDC, Hex.ColorFont); sprintf(buf, "%2X", row); TextOut(HexDC, 0, 0, buf, strlen(buf)); } // LEFT HEADER, semi-dynamic. for (line = 0; line < 16; line++) { MoveToEx(HexDC, 0, line * Hex.CellHeight + Hex.GapHeaderV, NULL); SetBkColor(HexDC, Hex.ColorBG); SetTextColor(HexDC, Hex.ColorFont); sprintf(buf, "%06X:", Hex.OffsetVisibleFirst + line*16 + Hex.MemoryRegion); TextOut(HexDC, 0, 0, buf, strlen(buf)); } // RAM, dynamic. for (line = 0; line < 16; line++) { for (row = 0; row < 16; row++) { MoveToEx(HexDC, row * Hex.CellWidth + Hex.GapHeaderH, line * Hex.CellHeight + Hex.GapHeaderV, NULL); sprintf(buf, "%02X", (int) Ram_68k[Hex.OffsetVisibleFirst + line*16 + row]); TextOut(HexDC, 0, 0, buf, strlen(buf)); } } EndPaint(hDlg, &ps); return 0; } break; case WM_CLOSE: if (Full_Screen) { while (ShowCursor(true) < 0); while (ShowCursor(false) >= 0); } KillHexEditor(); return 0; } return DefWindowProc(hDlg, uMsg, wParam, lParam); }
void CmEscapeCurrentTool( void ) // abort tool operation when press escape key { switch ( CurrentTool ) { case ZOOM_TOOL: // return to view position at start of drag if ( LToolActive ) if ( BlendView ) BlendView->Pan( appDC, 0, 0 ); else FrontView->Pan( appDC, 0, 0 ); if ( RToolActive ) if ( BlendView ) BlendView->Zoom( appDC, 1.0, 0, 0 ); else FrontView->Zoom( appDC, 1.0, 0, 0 ); EndDrag(); // release DC and cursor captured by BeginDrag() LToolActive = false; RToolActive = false; break; case DOMAIN_TOOL: // just undo shift, no R2_NOT lines on screen if ( LToolActive && DomainView ) DomainView->Pan( appDC, 0, 0 ); LToolActive = false; EndDrag(); // release DC and cursor break; case PENCIL_TOOL: if ( LToolActive ) { EndDrag(); // release DC and cursor LToolActive = false; if ( ToolContour ) delete ToolContour; ToolContour = NULL; InvalidateRect( appWnd, NULL, FALSE ); // cleanup ROP2_NOT drawing } if ( RToolActive ) { EndDrag(); RToolActive = false; } break; case GRID_TOOL: case POINT_TOOL: if ( RToolActive ) { EndDrag(); RToolActive = false; } break; case ELLIPSE_TOOL: if ( LToolActive ) // erase temporary ellipse drag drawing { if ( !ScrollOccurred ) Ellipse( appDC, LToolRect.left, LToolRect.top, LToolRect.right, LToolRect.bottom ); // erase EndDrag(); // release DC and cursor LToolActive = false; } break; case LINE_TOOL: if ( LToolActive ) // erase temporary drag line drawing if active { if ( !ScrollOccurred ) { MoveToEx( appDC, LToolRect.left, LToolRect.top, NULL ); LineTo( appDC, LToolRect.right, LToolRect.bottom ); } EndDrag(); // release DC and cursor LToolActive = false; } break; case ZLINE_TOOL: case MULTILINE_TOOL: case CULTILINE_TOOL: if ( LToolActive ) // erase temporary drawing if active { EndDrag(); // release DC and cursor if ( EditContour ) delete EditContour; EditContour = NULL; // stop editing contour FrontView->needsDrawing = true; // erase EditContour if ( BackView ) BackView->needsDrawing = true; // erase back trace which may exist InvalidateRect( appWnd, NULL, FALSE ); // cleanup drawing LToolActive = false; } break; case ARROW_TOOL: case MAGNIFY_TOOL: case RECTANGLE_TOOL: // both tools need drag rectangle erase if ( LToolActive ) { if ( !ScrollOccurred ) Rectangle( appDC, LToolRect.left, LToolRect.top, LToolRect.right, LToolRect.bottom ); EndDrag(); // release DC and cursor LToolActive = false; } break; case WILDFIRE_TOOL: if ( RToolActive ) // cleanup fire break contour { if ( ToolContour ) delete ToolContour; ToolContour = NULL; } EndDrag(); // release DC and cursor RToolActive = false; LToolActive = false; InvalidateRect( appWnd, NULL, FALSE ); // cleanup any ROP2_NOT drawing break; case SCALPEL_TOOL: if ( LToolActive ) // if using tool left button, abort drag+draw { EndDrag(); // release DC and cursor LToolActive = false; if ( ToolContour ) delete ToolContour; ToolContour = NULL; InvalidateRect( appWnd, NULL, FALSE ); // cleanup ROP2_NOT drawing } if ( RToolActive ) { EndDrag(); RToolActive = false; // if right button, just inactivate } break; default: // other tools have nothing to cleanup! break; } KillTimer( appWnd, SCROLL_TIMER ); // in case section is scrolling, stop it Scrolling = false; }
// ============================================================================ LRESULT AngleControl::Paint() { PAINTSTRUCT ps; HDC hDC = BeginPaint(m_hWnd, &ps); SetBkMode(hDC, TRANSPARENT); float rad = m_diameter * 0.5f; POINT start; start.x= rad + cos(DegToRad(m_startDegrees))*rad + 0.5f; start.y= sin(DegToRad(m_startDegrees))*rad + 0.5f; if (m_dirCCW) start.y = rad - start.y; else start.y += rad; POINT end; end.x = rad + cos(DegToRad(m_degrees+m_startDegrees))*rad + 0.5f; end.y = sin(DegToRad(m_degrees+m_startDegrees))*rad + 0.5f; if (m_dirCCW) end.y = rad - end.y; else end.y += rad; if(IsWindowEnabled(m_hWnd)) { SelectObject(hDC, GetStockObject(BLACK_PEN)); SelectBrush(hDC, m_hBrush); } else { SelectObject(hDC, GetStockObject(WHITE_PEN)); SelectBrush(hDC, GetStockObject(LTGRAY_BRUSH)); } if(m_degrees != 0.f) { BOOL drawCCW = TRUE; if (m_degrees <= 0.f) drawCCW = FALSE; if (!m_dirCCW) drawCCW = !drawCCW; // if(m_degrees > 0.f) if(drawCCW) Pie(hDC, 0, 0, m_diameter, m_diameter, start.x, start.y, end.x, end.y); else Pie(hDC, 0, 0, m_diameter, m_diameter, end.x, end.y, start.x, start.y); } // else { // MoveToEx(hDC, rad, rad, NULL); // LineTo(hDC, start.x, start.y); // } DeleteObject(SelectObject(hDC, GetStockObject(WHITE_PEN))); Arc(hDC, 0, 0, m_diameter, m_diameter, 0, m_diameter, m_diameter, 0); MoveToEx(hDC, rad, rad, NULL); LineTo(hDC, start.x, start.y); MoveToEx(hDC, rad, rad, NULL); LineTo(hDC, end.x, end.y); DeleteObject(SelectObject(hDC, GetStockObject(BLACK_PEN))); Arc(hDC, 0, 0, m_diameter, m_diameter, m_diameter, 0, 0, m_diameter); EndPaint(m_hWnd, &ps); return 0; }
LRESULT TaskBarControlProc( HWND hWnd, int iMsg, WPARAM wParam, LPARAM lParam ) { POINT point; PWindowsTree pWin; RECT rc; HDC hDC; unsigned long iRetMsg; PAINTSTRUCT ps; int iWidth,iHeight; HPEN hPen; HBRUSH hBrush; COLORREF crColor; PWNDCLASSEX pWndClass; LRESULT res; char* pString; int iLen; PTaskBarItem pTaskBarItem; PTaskBar pTaskBar; pWin=(PWindowsTree)hWnd; switch(iMsg) { case LMSG_CREATE: _lGUI_pTaskBarWindow = (PWindowsTree)hWnd; InitFixTaskBarData(hWnd); // SetTimer(hWnd,ID_TIMER,6000); 修改了 break; case LMSG_TIMER: { PTaskBar pTaskBar; PTaskBarItem pItem; pTaskBar = (PTaskBar)(pWin->dwAddData); pItem = pTaskBar->pItemHead; while(1){ if(pItem->id == TASKBAR_OBJID_CLOCK) break; pItem = pItem->pNext; } if(!pItem) return false; InvalidateRect(hWnd,&(pItem->rect),true); break; } case LMSG_COMMAND: break; case LMSG_PENDOWN: { int x, y; CaptureMouse(hWnd,BYCLIENT); x = (int)wParam; y = (int)lParam; ProcessTaskbarPenDown(hWnd, x, y); break; } case LMSG_PENMOVE: break; case LMSG_PENUP: DisCaptureMouse(); break; case LMSG_ERASEBKGND: pWndClass=GetRegClass(pWin->lpszClassName); if(!pWndClass) return (LRESULT)NULL; hBrush=pWndClass->hbrBackground; crColor=((BRUSH*)hBrush)->crBrushColor; ((BRUSH*)hBrush)->crBrushColor=RGB_SYSTEMHIBRIGHT; res=DefWindowProc(hWnd, iMsg, wParam, lParam); ((BRUSH*)hBrush)->crBrushColor=crColor; return res; case LMSG_PAINT: { int iHeight,iWidth; HPEN hPenWhite; PBITMAP pBitmap; PTaskBarItem pItem; ps.bPaintDirect=false; hDC=BeginPaint(hWnd, &ps); if(!hDC){ return true; } GetClientRect(hWnd,&rc); SetRect(&rc,0,0,rc.right-rc.left,rc.bottom-rc.top); iWidth =rc.right - rc.left + 1; iHeight =rc.bottom - rc.top + 1; hPenWhite =CreatePen(PS_SOLID,1,RGB_SYSTEMWHITE); SelectObject(hDC,hPenWhite); MoveToEx(hDC,rc.left,rc.top,&point); LineTo(hDC,rc.right,rc.top); DeleteObject(hPenWhite); //output those bitmaps pBitmap = malloc(sizeof(BITMAP)); if(!pBitmap) return; memset(pBitmap,0,sizeof(BITMAP)); pTaskBar = (PTaskBar)(pWin->dwAddData); pItem = pTaskBar->pItemHead; iWidth = pWin->rect.right - pWin->rect.left + 1; iHeight = pWin->rect.bottom - pWin->rect.top + 1; while(pItem){ if(pItem->bShow){ pBitmap->bmHeight = pItem->rect.bottom - pItem->rect.top + 1; pBitmap->bmWidth = pItem->rect.right - pItem->rect.left + 1; pBitmap->bmBits = GetBmpBufAddress(pItem->id,pItem->pData,pItem->iCurValue); OutputBmpObj(hDC,pItem->rect.left,pItem->rect.top, iWidth,iHeight,(HBITMAP)pBitmap); } pItem = pItem->pNext; } OutputTime(hWnd,hDC); free(pBitmap); EndPaint(hWnd, &ps); break; } case LMSG_DESTROY: ClearTaskBarData(hWnd); KillTimer(hWnd,ID_TIMER); break; default: return DefWindowProc(hWnd, iMsg, wParam, lParam); } return true; }
void DisplayADSRInfos(HWND hW) { HWND hWS=GetDlgItem(hW,IDC_ADSR); HDC hdc;RECT r;HBRUSH hBO;char szB[16]; int ch=iSelChannel,dx,dy,dm,dn,ia,id,is,ir; //----------------------------------------------------// get display size GetClientRect(hWS,&r); hdc=GetDC(hWS); //----------------------------------------------------// clean the area hBO = (HBRUSH) SelectObject(hdc,hBStream[0]); PatBlt(hdc,0,0,r.right,r.bottom,PATCOPY); r.left++;r.right-=2;r.top++;r.bottom-=2; // shrink the display rect for better optics //----------------------------------------------------// ia=min(s_chan[ch].ADSR.AttackTime,10000); // get adsr, but limit it for drawing id=min(s_chan[ch].ADSR.DecayTime,10000); is=min(s_chan[ch].ADSR.SustainTime,10000); ir=min(s_chan[ch].ADSR.ReleaseTime,10000); dx=ia+id+is+ir; // get the dx in (limited) adsr units // set the real values to the info statics SetDlgItemInt(hW,IDC_SADSR1,s_chan[ch].ADSRX.AttackRate,FALSE); SetDlgItemInt(hW,IDC_SADSR2,(s_chan[ch].ADSRX.DecayRate),FALSE); SetDlgItemInt(hW,IDC_SADSR3,s_chan[ch].ADSRX.SustainRate,FALSE); SetDlgItemInt(hW,IDC_SADSR4,(s_chan[ch].ADSRX.ReleaseRate),FALSE); SetDlgItemInt(hW,IDC_SADSR5,s_chan[ch].ADSRX.SustainLevel,TRUE); SetDlgItemInt(hW,IDC_SADSR6,s_chan[ch].ADSRX.SustainIncrease,TRUE); SetDlgItemInt(hW,IDC_SADSR7,s_chan[ch].ADSRX.State,FALSE); wsprintf(szB,"%08lx",s_chan[ch].ADSRX.EnvelopeVol); SetDlgItemText(hW,IDC_SADSR8,szB); if(dx) // something to draw? { HPEN hPO = (HPEN) SelectObject(hdc,hPAdsr[1]); // sel A pen dn=r.left; MoveToEx(hdc,dn,r.bottom,NULL); // move to bottom left corner dn+=(ia*r.right)/dx; // calc A x line pos LineTo(hdc,dn,r.top); // line to AxPos,top SelectObject(hdc,hPAdsr[2]); // sel D pen dn+=(id*r.right)/dx; // calc D x line pos dy=r.top+((1024-s_chan[ch].ADSR.SustainLevel)* // calc the D y pos r.bottom)/0x8000; // (our S level is ranged from 0 to 1024) LineTo(hdc,dn,dy); // line to DxPos,SLevel SelectObject(hdc,hPAdsr[3]); // sel S pen if(s_chan[ch].ADSR.SustainTime>10000) dm=1; // we have to fake the S values... S will else // inc/decrease until channel stop... if(s_chan[ch].ADSR.SustainTime==0) dm=0; // we dunno here when this will happen, else dm=21-(((s_chan[ch].ADSR.SustainTime/500))); // so we do some more ore less angled line, dy=dy-(s_chan[ch].ADSR.SustainModeDec*dm); // roughly depending on the S Time if(dy>r.bottom) dy=r.bottom; if(dy<r.top) dy=r.top; dn+=(is*r.right)/dx; LineTo(hdc,dn,dy); // line to SxPos, fake end volume level SelectObject(hdc,hPAdsr[4]); // sel R pen dn+=(ir*r.right)/dx; // calc R x line pos LineTo(hdc,dn,r.bottom); // line to RxPos, bottom right y SelectObject(hdc,hPO); // repair pen } SelectObject(hdc,hBO); // repair brush ReleaseDC(hWS,hdc); // release context }
static LRESULT CALLBACK MyButtonBarWindowProcedure (HWND pmButtonBarWindow, UINT pmMessage, WPARAM pmWParam, LPARAM pmLParam) { BOOL myIsTextWindow; HDC myDeviceContext; PAINTSTRUCT myPaintStruct; RECT myWindowRect; switch (pmMessage) { case WM_CREATE: myIsTextWindow = (BOOL) (((LPCREATESTRUCT) pmLParam) -> lpCreateParams); return MyCreateButtonBar (pmButtonBarWindow, myIsTextWindow); case WM_DESTROY: MyDispose (pmButtonBarWindow); break; case WM_SIZE: MyResizeButtonBar (pmButtonBarWindow); return 0; case WM_PAINT: myDeviceContext = BeginPaint (pmButtonBarWindow, &myPaintStruct); GetClientRect (pmButtonBarWindow, &myWindowRect); MoveToEx (myDeviceContext, 0, myWindowRect.bottom - 1, NULL); LineTo (myDeviceContext, myWindowRect.right, myWindowRect.bottom - 1); EndPaint (pmButtonBarWindow, &myPaintStruct); return 0; case WM_COMMAND: // Pass the command to the parent SetFocus (GetParent (pmButtonBarWindow)); if ((pmWParam == MIO_COMMAND_TERMINATE) && MIO_finished) { return SendMessage (GetParent (pmButtonBarWindow), WM_COMMAND, MIO_COMMAND_CLOSE, pmLParam); } else { return SendMessage (GetParent (pmButtonBarWindow), WM_COMMAND, pmWParam, pmLParam); } case WM_SYSCOLORCHANGE: // // Set the new background colours // // Delete the old background brush if (stBackgroundBrush != NULL) { DeleteObject (stBackgroundBrush); } // Create the new background brush stBackgroundBrush = CreateSolidBrush (GetSysColor (COLOR_BTNFACE)); // Set the window to be redrawn InvalidateRect (pmButtonBarWindow, NULL, TRUE); return 0; } // switch return DefWindowProc (pmButtonBarWindow, pmMessage, pmWParam, pmLParam); } // MyButtonBarWindowProcedure
void moveTo(int x, int y) { ACL_ASSERT_BEGIN_PAINT; MoveToEx(g_hmemdc, x, y,NULL); }