[Igarden-commit] CommonSource/YAAFExtensions RGSlideControl.h, 1.3, 1.4 RGSlideControl.cpp, 1.4, 1.
Status: Beta
Brought to you by:
jlbedell
|
From: Jeffrey B. <jlb...@us...> - 2006-10-18 01:18:09
|
Update of /cvsroot/igarden/CommonSource/YAAFExtensions In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv12309 Modified Files: RGSlideControl.h RGSlideControl.cpp Log Message: Move non-Mac scroll calls to RGSlideContro Index: RGSlideControl.cpp =================================================================== RCS file: /cvsroot/igarden/CommonSource/YAAFExtensions/RGSlideControl.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RGSlideControl.cpp 8 Oct 2006 00:08:08 -0000 1.4 --- RGSlideControl.cpp 18 Oct 2006 01:18:07 -0000 1.5 *************** *** 752,754 **** --- 752,1178 ---- } + /************************************************************************/ + /* */ + /* Windows Event Implementation */ + /* */ + /************************************************************************/ + + #if OPT_WINOS + + BEGINDISPATCH(XGScrollBar,XGView) + DISPATCHTABLE(KXGWInternal,XGScrollBar::DoWInternal) + ENDDISPATCH + + /* XGScrollBar::DoWInternal + * + * This is where messages that are received from my + * control is sent + */ + + long XGSlideControl::DoWInternal(long,void *ptr) + { + XGSWInternalRecord *r; + + r = (XGSWInternalRecord *)ptr; + + /* + * How to handle this + */ + + if ((r->msg == WM_HSCROLL) || (r->msg == WM_VSCROLL)) { + /* + * I've been clicked on. Scroll. This does this cheap. + */ + + switch (LOWORD(r->wp)) { + case SB_LEFT: + SetValue(fMinValue); + break; + case SB_RIGHT: + SetValue(fMaxValue); + break; + case SB_LINELEFT: + SetValue(GetValue() - GetStepSize()); + break; + case SB_LINERIGHT: + SetValue(GetValue() + GetStepSize()); + break; + case SB_PAGELEFT: + SetValue(GetValue() - GetPageSize()); + break; + case SB_PAGERIGHT: + SetValue(GetValue() + GetPageSize()); + break; + case SB_THUMBPOSITION: + case SB_THUMBTRACK: + SetValue(HIWORD(r->wp) * fScale); + break; + } + return 0; + } + return -1; + } + + #endif + + /************************************************************************/ + /* */ + /* X scollbar support */ + /* */ + /************************************************************************/ + + #if OPT_XWIN + + /*$ ScaleToPixel + * + * Given a minimum and maximum pixel value and a long integer + * value and maximum, this returns the pixel value that represents + * the specified position along the scale + */ + + static short ScaleToPixel(short minpix, short maxpix, long val, long max) + { + long scale; + + /* + * Scale down to guarentee the (maxpix - minpix)*val + * operation doesn't overflow. The disadvantage is that + * for scrollbars that are 10,000 pixels tall, this can + * be less than smooth. But then, a 10,000 pixel screen + * at 100 pixels/inch would be 8 feet call--and who is + * going to have an 8 foot monitor? + */ + + scale = (16383 + max) / 16384; + if (scale <= 0) return minpix; // ??? + val /= scale; + max /= scale; + return (short)(minpix + + (((maxpix - minpix) * val) / max)); + } + + /*$ XGScrollBar::ThumbWidth + * + * Get the width of the thumb + */ + + short XGSlideControl::ThumbWidth() + { + Rect r; + short widthx,widthy; + short width; + long value; + Rect thumb; + + r = GetContentRect(); + widthx = r.right - r.left; + widthy = r.bottom - r.top; + + if (widthx > widthy) { + widthx -= widthy*2; + width = ScaleToPixel(0,widthx,fPage,fPage + fMaxValue - fMinValue); + } else { + widthy -= widthx*2; + width = ScaleToPixel(0,widthy,fPage,fPage + fMaxValue - fMinValue); + } + + if (width < 8) width = 8; + return width; + } + + /*$ XGScrollBar::CalcScrollRect + * + * Calculate the scrollbar rectangle borders + */ + + Rect XGSlideControl::CalcScrollRect(short index) + { + Rect r = GetContentRect(); + short width,tmp; + short ttop,tbottom; + short thumb = ThumbWidth(); + + width = r.right - r.left; + tmp = r.bottom - r.top; + if (tmp < width) { + width = tmp; + + /* + * Bar is on it's side + */ + + switch (index) { + case 0: // left arrow + r.right = r.left + width; + break; + + case 1: // Left margin + r.right = ScaleToPixel(r.left + width, + r.right - width - thumb, + fValue - fMinValue, + fMaxValue - fMinValue); + r.left += width; + break; + + case 2: // thumb + tmp = r.left; + r.left = ScaleToPixel(r.left + width, + r.right - width - thumb, + fValue - fMinValue, + fMaxValue - fMinValue); + r.right = r.left + thumb; + break; + + case 3: // right margin + r.left = thumb + + ScaleToPixel(r.left + width, + r.right - width - thumb, + fValue - fMinValue, + fMaxValue - fMinValue); + r.right -= width; + break; + + case 4: // right arrow + r.left = r.right - width; + break; + } + } else { + /* + * Bar is upright + */ + + switch (index) { + case 0: // top arrow + r.bottom = r.top + width; + break; + + case 1: // Left margin + r.bottom = ScaleToPixel(r.top + width, + r.bottom - width - thumb, + fValue - fMinValue, + fMaxValue - fMinValue); + r.top += width; + break; + + case 2: // thumb + tmp = r.top; + r.top = ScaleToPixel(r.top + width, + r.bottom - width - thumb, + fValue - fMinValue, + fMaxValue - fMinValue); + r.bottom = r.top + thumb; + break; + + case 3: // bottom margin + r.top = thumb + + ScaleToPixel(r.top + width, + r.bottom - width - thumb, + fValue - fMinValue, + fMaxValue - fMinValue); + r.bottom -= width; + break; + + case 4: // bottom arrow + r.top = r.bottom - width; + break; + } + } + + return r; + } + + /*$ XGScrollBar::DrawScrollBar + * + * Draw the scrollbar itself. This also hilites the specified + * part. + */ + + void XGSlideControl::DrawScrollBar(short part) + { + Rect r; + XGDraw draw(this); + int x,y; + bool width; + + r = GetContentRect(); + width = (r.right - r.left > r.bottom - r.top); + + /* + * If this thing is empty, this draws an empty rectangle. + */ + + if (fMaxValue <= fMinValue) { + draw.Draw3DRect(r,KXGEFrame); + InsetRect(&r,1,1); + draw.Draw3DRect(r,KXGEBackground); + return; + } + + /* + * Draw the top arrow + */ + + r = CalcScrollRect(0); + draw.Draw3DRect(r,KXGEBackground); + if (part == 0) { + draw.Draw3DRect(r,KXGEInButton); + yaaf::OffsetRect(&r,1,1); + } else { + draw.Draw3DRect(r,KXGEButton); + } + + if (width) { + draw.MoveTo((r.left*2+r.right)/3,(r.top+r.bottom)/2); + draw.LineTo((r.left+2*r.right)/3,(r.top*2+r.bottom)/3); + draw.LineTo((r.left+2*r.right)/3,(r.top+2*r.bottom)/3); + draw.LineTo((r.left*2+r.right)/3,(r.top+r.bottom)/2); + } else { + draw.MoveTo((r.left+r.right)/2,(r.top*2+r.bottom)/3); + draw.LineTo((r.left*2+r.right)/3,(r.top+2*r.bottom)/3); + draw.LineTo((r.left+2*r.right)/3,(r.top+2*r.bottom)/3); + draw.LineTo((r.left+r.right)/2,(r.top*2+r.bottom)/3); + } + + /* + * Draw the bottom arrow + */ + + r = CalcScrollRect(4); + draw.Draw3DRect(r,KXGEBackground); + if (part == 4) { + draw.Draw3DRect(r,KXGEInButton); + yaaf::OffsetRect(&r,1,1); + } else { + draw.Draw3DRect(r,KXGEButton); + } + + if (width) { + draw.MoveTo((r.left+2*r.right)/3,(r.top+r.bottom)/2); + draw.LineTo((r.left*2+r.right)/3,(r.top*2+r.bottom)/3); + draw.LineTo((r.left*2+r.right)/3,(r.top+2*r.bottom)/3); + draw.LineTo((r.left+2*r.right)/3,(r.top+r.bottom)/2); + } else { + draw.MoveTo((r.left+r.right)/2,(r.top+2*r.bottom)/3); + draw.LineTo((r.left*2+r.right)/3,(r.top*2+r.bottom)/3); + draw.LineTo((r.left+2*r.right)/3,(r.top*2+r.bottom)/3); + draw.LineTo((r.left+r.right)/2,(r.top+2*r.bottom)/3); + } + + /* + * Draw the top border + */ + + r = CalcScrollRect(1); + if (width) InsetRect(&r,-1,0); + else InsetRect(&r,0,-1); + draw.Draw3DRect(r,KXGEFrame); + InsetRect(&r,1,1); + draw.Draw3DRect(r,KXGEBackground); + if (part == 1) { + draw.Draw3DRect(r,KXGEInset); + } + + /* + * Draw the bottom border + */ + + r = CalcScrollRect(3); + if (width) InsetRect(&r,-1,0); + else InsetRect(&r,0,-1); + draw.Draw3DRect(r,KXGEFrame); + InsetRect(&r,1,1); + draw.Draw3DRect(r,KXGEBackground); + if (part == 3) { + draw.Draw3DRect(r,KXGEInset); + } + + /* + * Draw the thumb + */ + + r = CalcScrollRect(2); + draw.Draw3DRect(r,KXGEBackground); + if (part == 2) { + draw.Draw3DRect(r,KXGEInButton); + } else { + draw.Draw3DRect(r,KXGEButton); + } + } + + /*$ XGScrollBar::UpdateTrackValue + * + * Update the trackbar's value based on the position of the mouse. + * + * NOTE: I gotta figure out how to deal with very large values. + * Right now, (fMaxValue - fMinValue) * pixel size cannot exceed + * the largest signed long integer value. + */ + + void XGSlideControl::UpdateTrackValue(Point where) + { + XGSValue v; + Rect r; + short widthx,widthy; + long value; + short thumb; + + r = GetContentRect(); + widthx = r.right - r.left; + widthy = r.bottom - r.top; + thumb = ThumbWidth(); + + /* + * Calculate value if thumb was in middle + */ + + if (widthx > widthy) { + InsetRect(&r,widthy,0); + InsetRect(&r,thumb/2,0); + if (r.right <= r.left) value = fMinValue; + else { + value = fMinValue + + (((fMaxValue - fMinValue) * (where.h - r.left))/(r.right-r.left)); + } + } else { + InsetRect(&r,0,widthx); + InsetRect(&r,0,thumb/2); + if (r.bottom <= r.top) value = fMinValue; + else { + value = fMinValue + + (((fMaxValue - fMinValue) * (where.v - r.top))/(r.bottom-r.top)); + } + } + + /* + * Peg + */ + + if (value > fMaxValue) value = fMaxValue; + if (value < fMinValue) value = fMinValue; + + /* + * Make sure the value is set correctly + */ + + if (value < fMinValue) value = fMinValue; + if (value > fMaxValue) value = fMaxValue; + + /* + * And send the messages indicating the value changed + */ + + if (value != fValue) { + DoDispatch(KXGSliderStart,GetViewID(),NULL); + v.slider = this; + v.oldVal = fValue; + v.newVal = value; + fValue = value; + DrawScrollBar(2); // draw the scroll bar in new pos + DoDispatch(KXGSliderValue,GetViewID(),(void *)&v); + } + } + + #endif + + } // namespace yaaf Index: RGSlideControl.h =================================================================== RCS file: /cvsroot/igarden/CommonSource/YAAFExtensions/RGSlideControl.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RGSlideControl.h 29 Jun 2005 01:50:09 -0000 1.3 --- RGSlideControl.h 18 Oct 2006 01:18:07 -0000 1.4 *************** *** 124,127 **** --- 124,145 ---- ControlHandle fControl; #endif + + #if OPT_WINOS + void AdjustScale(); + void LoadControl(); + + long fScale; + HWND fControl; + #endif + + #if OPT_XWIN + void DrawScrollBar(short part = -1); + Rect CalcScrollRect(short); + void UpdateTrackValue(Point); + short ThumbWidth(); + + bool fDown; + short fTrack; // what am I down on? + #endif }; |