void CScrollerView::dragval(CDrawContext *dstcon, CPoint &where) { CPoint ref = where; float old = mParam->GetVal(); bool allow = false; // need to drag a bit before edit int d; while(1) { long button = dstcon->getMouseButtons(); if (!(button & kLButton)) { break; } dstcon->getMouseLocation(where); d = mVert ? ref.y-where.y : where.x-ref.x; if(allow==false) { if(d<-2 || d>2) { allow = true; ref = where; } } else { mParam->SetVal(old+d, NFLG_ALL); } if(mFrame) mFrame->doIdleStuff(); } }
void CScrollerView::mouse(CDrawContext *dstcon, CPoint &where) { long button = dstcon->getMouseButtons(); if (!(button & kLButton) || !mParam) { return; } // see whether to set the default value if(button == (kControl|kLButton)) { mParam->SetVal(mParam->mDef, NFLG_ALL); return; } if(mDisplayMouse) { // this event is sent by the attached display mDisplayMouse = false; bool vert=mVert; mVert = true; dragval(dstcon,where); mVert = vert; } else { // this event is from our own area, so get the hitmap and see whats to do long dsplw = mHitmap->getWidth(); long dsplh = mHitmap->getHeight(); CPoint cp = CPoint(0,0); CRect cr = CRect(0,0,dsplw,dsplh); COffscreenContext *hitmap = new COffscreenContext(mFrame,dsplw,dsplh); mHitmap->draw(hitmap, cr, cp); //mHitmap->drawAlphaBlend(dstcon, size, cp); where.offset(-size.left, -size.top); CColor cl = hitmap->getPoint(where); delete hitmap; if(cl==kGreenCColor) { mParam->StepVal(1, NFLG_ALL); } else if(cl==kRedCColor) { mParam->StepVal(-1, NFLG_ALL); } else if(cl==kWhiteCColor) { dragval(dstcon,where); } } }
long CScrollerView::notify(CView *sender, const char *message) { switch((int)message) { case VNTF_MOUSE: // next ::mouse() is an alien mDisplayMouse = true; break; default: int in; sscanf(message,"%i",&in); mParam->SetVal((float)in,NFLG_ALL); } return 0; }