void DrawHilite(HDC hdc, Rect& rect, Shader* pShader ) { int w,h,npts,xcen,ybot,ytop,ylast,i,iy; HPEN linePen = (HPEN)GetStockObject(WHITE_PEN); HPEN fgPen = CreatePen(PS_SOLID,0,GetCustSysColor(COLOR_BTNFACE)); HPEN bgPen = CreatePen(PS_SOLID,0,GetCustSysColor(COLOR_BTNSHADOW)); w = rect.w(); h = rect.h()-3; npts = (w-2)/2; xcen = rect.left+npts; ybot = rect.top+h; ytop = rect.top+2; ylast = -1; for (i=0; i<npts; i++) { float v = pShader->EvalHiliteCurve( (float)i/((float)npts*2.0f) ); if (v>2.0f) v = 2.0f; // keep iy from wrapping iy = ybot-(int)(v*((float)h-2.0f)); if (iy<ytop) iy = ytop; SelectPen(hdc, fgPen); VertLine(hdc,xcen+i,ybot,iy); VertLine(hdc,xcen-i,ybot,iy); if (iy-1>ytop) { // Fill in above curve SelectPen(hdc,bgPen); VertLine(hdc,xcen+i, ytop, iy-1); VertLine(hdc,xcen-i, ytop, iy-1); } if (ylast>=0) { SelectPen(hdc,linePen); VertLine(hdc,xcen+i-1,iy-1,ylast); VertLine(hdc,xcen-i+1,iy-1,ylast); } ylast = iy; } SelectObject( hdc, linePen ); DeleteObject(fgPen); DeleteObject(bgPen); WhiteRect3D(hdc, rect, 1); }
// iso projection of 2 orthogonal highlight curves void DrawHilite2(HDC hdc, Rect& rect, Shader* pShader, int layer ) { int w,h,npts,xcen,ybot,ytop,ylast,i,iy, off, vals[200]; float ybr, ybl; HPEN linePen = (HPEN)GetStockObject(WHITE_PEN); HPEN fgPen = CreatePen(PS_SOLID,0,GetCustSysColor(COLOR_BTNFACE)); HPEN fg2Pen = CreatePen(PS_SOLID,0,GetCustSysColor(COLOR_BTNHILIGHT)); HPEN bgPen = CreatePen(PS_SOLID,0,GetCustSysColor(COLOR_BTNSHADOW)); w = rect.w(); assert( w/2 < 200 ); // 200 vals saved for visibility h = rect.h()-3; npts = (w-2)/2; off = h / 6; float slope = float(h-off-off)/w; ybot = rect.top+h; ytop = rect.top+2; // first the X curve ybr = ybl = float(rect.top+h - 2.5* off); xcen = rect.left+npts; ylast = -1; for (i=0; i<npts; i++) { float v = pShader->EvalHiliteCurve2( (float)i/((float)npts*2.0f), 0.0f, layer ); if (v>2.0f) v = 2.0f; // keep iy from wrapping iy = (int)(v* 0.6f * ((float)h-2.0f)); int r = int( ybr + 0.5f ); if ( r > ybot ) r = ybot; int l = int( ybl + 0.5f ); if ( l > ybot ) l = ybot; int ry = r - iy; if (ry<ytop) ry = ytop; if (ry>ybot) ry = ybot; vals[i] = ry; // save for visibility int ly = l - iy; if (ly<ytop) ly = ytop; if (ly>ybot) ly = ybot; SelectPen(hdc, fgPen); VertLine(hdc,xcen+i, r, ry); // start at center & spread out on both sides VertLine(hdc,xcen-i, l, ly); SelectPen(hdc,bgPen); // Fill in below baseline VertLine(hdc,xcen+i, ybot, r+1); VertLine(hdc,xcen-i, ybot, l+1); VertLine(hdc,xcen+i, ytop, ry-1); VertLine(hdc,xcen-i, ytop, ly-1); // fill in above curve // if (ylast>=0) { // SelectPen(hdc,linePen); // VertLine(hdc, xcen+i-1, iy-1, ylast); // white dot marks curve // VertLine(hdc, xcen-i+1, iy-1, ylast); // } ylast = iy; ybr += slope; ybl += -slope; } // now do the Y curve ybr = ybl = float(rect.top+h - 2.5* off); xcen = rect.left+npts - 1; ylast = -1; for (i=0; i < npts; i++) { float v = pShader->EvalHiliteCurve2( 0.0f, (float)i/((float)npts*2.0f), layer ); if (v>2.0f) v = 2.0f; // keep iy from wrapping iy = (int)(v* 0.6f * ((float)h-2.0f)); int r = int( ybr + 0.5f ); if ( r > ybot ) r = ybot; int l = int( ybl + 0.5f ); if ( l > ybot ) l = ybot; int ry = r - iy; if (ry<ytop) ry = ytop; if (ry>ybot) ry = ybot; int ly = l - iy; if (ly<ytop) ly = ytop; if (ly>ybot) ly = ybot; SelectPen(hdc, fg2Pen); VertLine(hdc,xcen-i, l, ly); // left side always visible..in front if ( r <= vals[i] ) VertLine(hdc,xcen+i, r, ry); // start at center & spread out on both sides else if ( ry <= vals[i] ) VertLine(hdc,xcen+i, vals[i]-1, ry); // start at center & spread out on both sides // if (ylast>=0) { // SelectPen(hdc,linePen); // VertLine(hdc, xcen+i-1, iy-1, ylast); // white dot marks curve // VertLine(hdc, xcen-i+1, iy-1, ylast); // } ylast = iy; ybr += -slope; ybl += slope; } SelectObject( hdc, linePen ); DeleteObject(fgPen); DeleteObject(fg2Pen); DeleteObject(bgPen); WhiteRect3D(hdc, rect, 1); }
LRESULT CALLBACK ish3_ProgressBar::WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { // Get back at our stored class pointer ish3_ProgressBar *UGC = DLGetWindowLongPtr<ish3_ProgressBar*>(hWnd); if(UGC == NULL && message != WM_CREATE) return DefWindowProc(hWnd, message, wParam, lParam); switch ( message ) { case WM_CREATE: { LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam; UGC = (ish3_ProgressBar*)lpcs->lpCreateParams; DLSetWindowLongPtr(hWnd, UGC); break; } case WM_MOUSEMOVE: { if(wParam && MK_LBUTTON) { init_thread_locals(); push_alloc_frame(); one_value_local(arg); // work out a positional click value and fire a 'clicked' event int xPos = LOWORD(lParam); int yPos = HIWORD(lParam); Rect rect; GetClientRect(hWnd,&rect); float fDelta = 0.0f; if(UGC->type==TYPE_HORIZ) { int rWide = (rect.right-1)-(rect.left+2); float Delta = 100.0f/rWide; fDelta = Delta*xPos; } if(UGC->type==TYPE_VERT) { int rHigh = (rect.bottom)-(rect.top); float Delta = 100.0f/rHigh; fDelta = Delta*(rHigh-yPos); } vl.arg = Integer::intern((int)fDelta); UGC->run_event_handler(UGC->parent_rollout, n_clicked, &vl.arg, 1); pop_value_locals(); pop_alloc_frame(); } if(UGC->enabled) SetCursor(LoadCursor(NULL, IDC_ARROW)); } break; case WM_LBUTTONDOWN: { init_thread_locals(); push_alloc_frame(); one_value_local(arg); // ditto - just wanted to handle first time clicks int xPos = LOWORD(lParam); int yPos = HIWORD(lParam); Rect rect; GetClientRect(hWnd,&rect); float fDelta = 0.0f; if(UGC->type==TYPE_HORIZ) { int rWide = (rect.right-1)-(rect.left+2); float Delta = 100.0f/rWide; fDelta = Delta*xPos; } if(UGC->type==TYPE_VERT) { int rHigh = (rect.bottom)-(rect.top); float Delta = 100.0f/rHigh; fDelta = Delta*(rHigh-yPos); } vl.arg = Integer::intern((int)fDelta); UGC->run_event_handler(UGC->parent_rollout, n_clicked, &vl.arg, 1); pop_value_locals(); pop_alloc_frame(); } break; case WM_RBUTTONUP: UGC->call_event_handler(UGC->parent_rollout, n_rightClick, NULL, 0); break; case WM_PAINT: { // begin paint cycle PAINTSTRUCT ps; HDC hdc; hdc = BeginPaint( hWnd, &ps ); Rect rect; GetClientRect(hWnd,&rect); // Setup pens, brushes and colours SetBkColor( hdc, GetCustSysColor( COLOR_BTNFACE ) ); SetBkMode( hdc, TRANSPARENT ); HPEN hLight = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNHIGHLIGHT ) ); HPEN hBlack = (HPEN)GetStockObject(BLACK_PEN); HPEN hDark = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNSHADOW ) ); // setup the progress bar colour, taking enabled flag into account HBRUSH hProgress; if(UGC->enabled) hProgress = CreateSolidBrush( UGC->colorPro ); else hProgress = CreatePatternBrush( LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_DISABLED)) ); HPEN hPP; if(UGC->enabled) hPP = CreatePen( PS_SOLID, 0, UGC->colorPro ); else hPP = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNFACE ) ); // the 'blanker' definition HBRUSH hProgressTerm = CreateSolidBrush( GetCustSysColor( COLOR_BTNFACE ) ); HPEN hPT = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNFACE ) ); // Do some 3D control drawing (frame) SelectObject(hdc, hDark); MoveToEx(hdc, rect.right-1, 0, NULL); LineTo (hdc, 0, 0); LineTo (hdc, 0, rect.bottom-1); SelectObject(hdc, hBlack); MoveToEx(hdc, rect.right-2, 1, NULL); LineTo (hdc, 1, 1); LineTo (hdc, 1, rect.bottom-2); SelectObject(hdc, hLight); MoveToEx(hdc, 0, rect.bottom-1, NULL); LineTo (hdc, rect.right-1, rect.bottom-1); LineTo (hdc, rect.right-1, 0 ); // HORIZONTAL DRAW if(UGC->type==TYPE_HORIZ) { // prepare progress bar float delta = (float)((rect.right-rect.left)-1)/100.0f; int amt = UGC->value; int draw = (int)(amt*delta); // handle extremities if(amt==100) draw = ((rect.right-rect.left)-1); if(amt==0) draw = rect.left+1; if(draw<=2) draw=2; // blit out unused to background if(amt!=100) { HGDIOBJ hOldPen = SelectObject(hdc, hPT); HGDIOBJ hOldBrush = SelectObject(hdc, hProgressTerm); Rectangle(hdc,draw,2,rect.right-1,rect.bottom-2); SelectObject(hdc, hOldPen); SelectObject(hdc, hOldBrush); } // draw progress bar if(amt>0) { HGDIOBJ hOldPen = SelectObject(hdc, hPP); HGDIOBJ hOldBrush = SelectObject(hdc, hProgress); Rectangle(hdc,2,2,draw,rect.bottom-2); SelectObject(hdc, hOldPen); SelectObject(hdc, hOldBrush); } } // VERTICAL DRAW if(UGC->type==TYPE_VERT) { // prepare progress bar float delta = (float)((rect.bottom-rect.top)-4)/100.0f; int amt = UGC->value; int draw = (int)(amt*delta); // handle extremities if(amt==100) draw = ((rect.bottom-rect.top)-4); if(amt==0) draw = 0;//rect.bottom-2; // blit out unused to background if(amt!=100) { HGDIOBJ hOldPen = SelectObject(hdc, hPT); HGDIOBJ hOldBrush = SelectObject(hdc, hProgressTerm); Rectangle(hdc,2,rect.top+2,rect.right-2,(rect.bottom-2)-draw); SelectObject(hdc, hOldPen); SelectObject(hdc, hOldBrush); } // draw progress bar if(amt>0) { HGDIOBJ hOldPen = SelectObject(hdc, hPP); HGDIOBJ hOldBrush = SelectObject(hdc, hProgress); Rectangle(hdc,2,rect.bottom-2,rect.right-2,(rect.bottom-2)-draw); SelectObject(hdc, hOldPen); SelectObject(hdc, hOldBrush); } } DeleteObject(hLight); DeleteObject(hDark); DeleteObject(hBlack); DeleteObject(hPP); DeleteObject(hPT); DeleteObject(hProgress); DeleteObject(hProgressTerm); // end paint cycle EndPaint( hWnd, &ps ); return 0; } } return TRUE; }