void CCandidateView::ScrollToTarget() { Int32 sx = 0; GetScrollX(&sx); if (mTargetScrollX > sx) { sx += SCROLL_PIXELS; if (sx >= mTargetScrollX) { sx = mTargetScrollX; RequestLayout(); } } else { sx -= SCROLL_PIXELS; if (sx <= mTargetScrollX) { sx = mTargetScrollX; RequestLayout(); } } Int32 tmp = 0; GetScrollY(&tmp); ScrollTo(sx, tmp); Invalidate(); }
void MatrixControl::Draw (BRect restrictiveRect) { if (IsFocus() == false) showcursor=false; Window()->Lock(); float orx = GetScrollX(); float ory = GetScrollY(); SetHighColor(0,0,0,255); StrokeRect(BRect(orx,ory,Frame().Width()+orx,Frame().Height()+ory),B_SOLID_HIGH); int i,k; int32 a,b; BString out; escapement_delta delta; delta.space = 0; delta.nonspace = 0; SetDrawingMode( B_OP_OVER ); SetFont( be_bold_font ); if ((CursorOnKoeff == true) && (cursoron == true)) { SetHighColor(255,255,255,255); } if (CursorOnKoeff) DrawString( edit->String() , BPoint(10,20), &delta); else if (!DrawfromPulse) DrawString( extra::fStringOutOf( Koeffizient,GLOBAL_ACCURACY ).String() , BPoint(10,20), &delta); if /* A */ (DrawfromPulse == false) { for /* B */ (i=0;i<matrix_dimension;++i) { if (!DataEnterMode) { SetHighColor(255,40,40,255); FillRect(BRect( (i+1)*square_size-10, 20 ,(i+1)*square_size-5 , square_size * matrix_dimension), B_SOLID_HIGH ); SetHighColor(40,40,255,255); FillRect(BRect( 20, (i+1)*square_size+5, square_size * (matrix_dimension+1) ,(i+1)*square_size+10 ), B_SOLID_HIGH ); SetHighColor(0,0,0,255); StrokeRect(BRect( (i+1)*square_size-10, 20 ,(i+1)*square_size -5 , square_size * matrix_dimension), B_SOLID_HIGH ); StrokeRect(BRect( 20, (i+1)*square_size+5, square_size * (matrix_dimension+1) ,(i+1)*square_size +10 ), B_SOLID_HIGH ); } for /* C */(k=0;k<matrix_dimension;++k) { out.SetTo(extra::fStringOutOf(float_matrix[i*matrix_dimension +k],GLOBAL_ACCURACY).String()); SetHighColor(255,50,127,255); if /* D */ ((showcursor == true) && (posx == k) && (posy == i) && (cursoron == true) && (CursorOnKoeff == false)) SetHighColor(255,255,255,255); // D a = (k+1)*square_size; b = (i+1)*square_size; DrawString(out.String(),BPoint(a,b), &delta); } // C } // B } // A else // A { //out.SetTo(extra::fStringOutOf(float_matrix[posy*matrix_dimension +posx],3).String()); if (CursorOnKoeff == false) { bool optimizer; optimizer = ((showcursor == true) && (cursoron == true)); SetHighColor(200,200,200,255); FillRect(BRect((posx+1)*square_size-10, posy*square_size+10, (posx+2)*square_size-10, (posy+1)*square_size+10)); SetHighColor(255,50,127,255); DrawString(edit->String(),BPoint((posx+1)*square_size,(posy+1)*square_size), &delta); if /* B */(optimizer == true) { SetHighColor(255,255,255,255); DrawString("|", &delta); }// B } } // A Window()->Sync(); Window()->Unlock(); }
void MatrixControl::MouseDown( BPoint x ) { if (IsFocus() == false) MakeFocus(true); x.y += GetScrollY(); x.x += GetScrollX(); if (!DataEnterMode) { int32 i; BRect *rect; BMessage *nachricht; for (i=0; i<matrix_dimension; ++i) { rect = new BRect( (i+1)*square_size-10, 20 ,(i+1)*square_size -5 , square_size * matrix_dimension); if (rect->Contains(x)==true) { nachricht = new BMessage(CONST_dragcolumn); nachricht->AddInt32("column",i); nachricht->AddPointer("matrix_control",this); DragMessage(nachricht,BRect( (i+1)*square_size-10, 20 ,(i+1)*square_size -5 , square_size * matrix_dimension),NULL); delete nachricht; //Drag around a data row return; } delete rect; rect = new BRect( 20, (i+1)*square_size+5, square_size * (matrix_dimension+1) ,(i+1)*square_size +10 ); if (rect->Contains(x)==true) { nachricht = new BMessage(CONST_dragrow); nachricht->AddInt32("row",i); nachricht->AddPointer("matrix_control",this); DragMessage(nachricht,BRect( 20, (i+1)*square_size+5, square_size * (matrix_dimension+1) ,(i+1)*square_size +10 ),NULL); delete nachricht; return; } delete rect; } } if (DataEnterMode) { int half; half = square_size / 2; posx = int ((x.x / square_size) - 1); posy = int (((x.y + half) / square_size) - 1); showcursor = true; if ((posx < 0) || (posx >= matrix_dimension)) {MakeFocus(false);posx = 0;} if ((posy < 0) || (posy >= matrix_dimension)) {MakeFocus(false);posy = 0;} if (x.y < 40) { CursorOnKoeff = true; edit->SetTo(extra::fStringOutOf(Koeffizient,GLOBAL_ACCURACY).String()); } else { CursorOnKoeff = false; edit->SetTo(extra::fStringOutOf(float_matrix[posy*matrix_dimension +posx],GLOBAL_ACCURACY).String()); } } // If (DataEnterMode) if (IsFocus() == true) { DrawfromPulse = false; Invalidate(); } }
void CCandidateView::OnDraw( /* [in] */ ICanvas* canvas) { if (canvas != NULL) { View::OnDraw(canvas); } mTotalWidth = 0; if (mSuggestions == NULL) return; if (mBgPadding == NULL) { CRect::New(0, 0, 0, 0, (IRect**)&mBgPadding); AutoPtr<IDrawable> bg; GetBackground((IDrawable**)&bg); if (bg != NULL) { Boolean isPadding = FALSE; bg->GetPadding(mBgPadding, &isPadding); } } Int32 x = 0; Int32 count = mSuggestions->GetLength() ; Int32 height = 0; GetHeight(&height); Int32 touchX = mTouchX; Int32 scrollX = 0; GetScrollX(&scrollX); Boolean scrolled = mScrolled; Boolean typedWordValid = mTypedWordValid; Float textSize = 0, ascent = 0; mPaint->GetTextSize((Float*)&textSize); mPaint->Ascent((Float*)&ascent); Int32 y = (Int32) (((height - textSize) / 2) - ascent); Int32 top = 0; mBgPadding->GetTop(&top); for (Int32 i = 0; i < count; i++) { ICharSequence* text = (*mSuggestions)[i]; String suggestion; if (text != NULL) { text->ToString(&suggestion); } Float textWidth = 0; mPaint->MeasureText(suggestion, &textWidth); Int32 wordWidth = (Int32) textWidth + X_GAP * 2; (*mWordX)[i] = x; (*mWordWidth)[i] = wordWidth; mPaint->SetColor(mColorNormal); if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) { if (canvas != NULL) { canvas->Translate(x, 0); mSelectionHighlight->SetBounds(0, top, wordWidth, height); mSelectionHighlight->Draw(canvas); canvas->Translate(-x, 0); } mSelectedIndex = i; } if (canvas != NULL) { if ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid)) { mPaint->SetFakeBoldText(TRUE); mPaint->SetColor(mColorRecommended); } else if (i != 0) { mPaint->SetColor(mColorOther); } canvas->DrawText(suggestion, x + X_GAP, y, mPaint); mPaint->SetColor(mColorOther); canvas->DrawLine(x + wordWidth + 0.5f, top, x + wordWidth + 0.5f, height + 1, mPaint); mPaint->SetFakeBoldText(FALSE); } x += wordWidth; } mTotalWidth = x; Int32 tmp = 0; GetScrollX(&tmp); if (mTargetScrollX != tmp) { ScrollToTarget(); } }