void wxStatusBarBeOS::DrawStatusBar() { int i=0; int leftPos=0; wxArrayInt widthsAbs; wxString text; m_view->Clear(); BRect bounds(m_view->bounds()); BView * drawview = m_view->GetBack(); if(drawview->LockLooper()) { rgb_color clr; drawview->PushState(); clr = drawview->ViewColor(); clr.red-=50; clr.green-=50; clr.blue-=50; drawview->SetHighColor(clr); drawview->StrokeLine(BPoint(bounds.left, bounds.top), BPoint(bounds.right, bounds.top)); clr.red+=100; clr.green+=100; clr.blue+=100; drawview->SetHighColor(clr); drawview->StrokeLine(BPoint(bounds.left, bounds.top+1), BPoint(bounds.right, bounds.top+1)); drawview->PopState(); if(m_nFields>0) widthsAbs = CalculateAbsWidths(bounds.IntegerWidth() - 2*(m_nFields - 1)); drawview->SetDrawingMode(B_OP_OVER); for(i=0;i<m_nFields;i++) { text = GetStatusBufferText(i); drawview->DrawString(text, BPoint(leftPos, bounds.bottom-2)); leftPos+=widthsAbs[i]+2; } drawview->UnlockLooper(); } m_view->flush(); }
void ActivityView::_DrawHistory(bool drawBackground) { _UpdateOffscreenBitmap(); BView* view = this; if (fOffscreen != NULL) { fOffscreen->Lock(); view = _OffscreenView(); } BRect frame = _HistoryFrame(); BRect outerFrame = frame.InsetByCopy(-2, -2); // draw the outer frame uint32 flags = 0; if (!drawBackground) flags |= BControlLook::B_BLEND_FRAME; be_control_look->DrawTextControlBorder(this, outerFrame, outerFrame, fLegendBackgroundColor, flags); // convert to offscreen view if necessary if (view != this) frame.OffsetTo(B_ORIGIN); view->SetLowColor(fHistoryBackgroundColor); view->FillRect(frame, B_SOLID_LOW); uint32 step = 2; uint32 resolution = fDrawResolution; if (fDrawResolution > 1) { step = 1; resolution--; } // We would get a negative number of steps which isn't a good idea. if (frame.IntegerWidth() <= 10) return; uint32 width = frame.IntegerWidth() - 10; uint32 steps = width / step; bigtime_t timeStep = RefreshInterval() * resolution; bigtime_t now = system_time(); // Draw scale // TODO: add second markers? view->SetPenSize(1); rgb_color scaleColor = view->LowColor(); uint32 average = (scaleColor.red + scaleColor.green + scaleColor.blue) / 3; if (average < 96) scaleColor = tint_color(scaleColor, B_LIGHTEN_2_TINT); else scaleColor = tint_color(scaleColor, B_DARKEN_2_TINT); view->SetHighColor(scaleColor); view->StrokeLine(BPoint(frame.left, frame.top + frame.Height() / 2), BPoint(frame.right, frame.top + frame.Height() / 2)); // Draw values view->SetPenSize(1.5); BAutolock _(fSourcesLock); for (uint32 i = fSources.CountItems(); i-- > 0;) { ViewHistory* viewValues = fViewValues.ItemAt(i); DataSource* source = fSources.ItemAt(i); DataHistory* values = fValues.ItemAt(i); viewValues->Update(values, steps, fDrawResolution, now, timeStep, RefreshInterval()); if (viewValues->Start() >= (int32)steps - 1) continue; uint32 x = viewValues->Start() * step; bool first = true; view->SetHighColor(source->Color()); view->SetLineMode(B_BUTT_CAP, B_ROUND_JOIN); view->MovePenTo(B_ORIGIN); try { view->BeginLineArray(steps - viewValues->Start() - 1); BPoint prev; for (uint32 j = viewValues->Start(); j < steps; x += step, j++) { float y = _PositionForValue(source, values, viewValues->ValueAt(j)); if (first) { first = false; } else view->AddLine(prev, BPoint(x, y), source->Color()); prev.Set(x, y); } } catch (std::bad_alloc) { // Not enough memory to allocate the line array. // TODO we could try to draw using the slower but less memory // consuming solution using StrokeLine. } view->EndLineArray(); } // TODO: add marks when an app started or quit view->Sync(); if (fOffscreen != NULL) { fOffscreen->Unlock(); DrawBitmap(fOffscreen, outerFrame.LeftTop()); } }
void BTitleView::Draw(BRect /*updateRect*/, bool useOffscreen, bool updateOnly, const BColumnTitle *pressedColumn, void (*trackRectBlitter)(BView *, BRect), BRect passThru) { BRect bounds(Bounds()); BView *view; if (useOffscreen) { ASSERT(sOffscreen); BRect frame(bounds); frame.right += frame.left; // this is kind of messy way of avoiding being clipped by the ammount the // title is scrolled to the left // ToDo: fix this view = sOffscreen->BeginUsing(frame); view->SetOrigin(-bounds.left, 0); view->SetLowColor(LowColor()); view->SetHighColor(HighColor()); BFont font(be_plain_font); font.SetSize(9); view->SetFont(&font); } else view = this; if (be_control_look != NULL) { rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); view->SetHighColor(tint_color(base, B_DARKEN_2_TINT)); view->StrokeLine(bounds.LeftBottom(), bounds.RightBottom()); bounds.bottom--; be_control_look->DrawButtonBackground(view, bounds, bounds, base, 0, BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER); } else { // fill background with light gray background if (!updateOnly) view->FillRect(bounds, B_SOLID_LOW); view->BeginLineArray(4); view->AddLine(bounds.LeftTop(), bounds.RightTop(), sShadowColor); view->AddLine(bounds.LeftBottom(), bounds.RightBottom(), sShadowColor); // draw lighter gray and white inset lines bounds.InsetBy(0, 1); view->AddLine(bounds.LeftBottom(), bounds.RightBottom(), sLightShadowColor); view->AddLine(bounds.LeftTop(), bounds.RightTop(), sShineColor); view->EndLineArray(); } int32 count = fTitleList.CountItems(); float minx = bounds.right; float maxx = bounds.left; for (int32 index = 0; index < count; index++) { BColumnTitle *title = fTitleList.ItemAt(index); title->Draw(view, title == pressedColumn); BRect titleBounds(title->Bounds()); if (titleBounds.left < minx) minx = titleBounds.left; if (titleBounds.right > maxx) maxx = titleBounds.right; } if (be_control_look != NULL) { bounds = Bounds(); minx--; view->SetHighColor(sLightShadowColor); view->StrokeLine(BPoint(minx, bounds.top), BPoint(minx, bounds.bottom - 1)); } else { // first and last shades before and after first column maxx++; minx--; view->BeginLineArray(2); view->AddLine(BPoint(minx, bounds.top), BPoint(minx, bounds.bottom), sShadowColor); view->AddLine(BPoint(maxx, bounds.top), BPoint(maxx, bounds.bottom), sShineColor); view->EndLineArray(); } #if !(APP_SERVER_CLEARS_BACKGROUND) FillRect(BRect(bounds.left, bounds.top + 1, minx - 1, bounds.bottom - 1), B_SOLID_LOW); FillRect(BRect(maxx + 1, bounds.top + 1, bounds.right, bounds.bottom - 1), B_SOLID_LOW); #endif if (useOffscreen) { if (trackRectBlitter) (trackRectBlitter)(view, passThru); view->Sync(); DrawBitmap(sOffscreen->Bitmap()); sOffscreen->DoneUsing(); } else if (trackRectBlitter) (trackRectBlitter)(view, passThru); }
void BTitleView::Draw(BRect /*updateRect*/, bool useOffscreen, bool updateOnly, const BColumnTitle* pressedColumn, void (*trackRectBlitter)(BView*, BRect), BRect passThru) { BRect bounds(Bounds()); BView* view; if (useOffscreen) { ASSERT(sOffscreen); BRect frame(bounds); frame.right += frame.left; // ToDo: this is kind of messy way of avoiding being clipped // by the amount the title is scrolled to the left view = sOffscreen->BeginUsing(frame); view->SetOrigin(-bounds.left, 0); view->SetLowColor(LowColor()); view->SetHighColor(HighColor()); BFont font; GetFont(&font); view->SetFont(&font); } else view = this; view->SetHighUIColor(B_PANEL_BACKGROUND_COLOR, B_DARKEN_2_TINT); view->StrokeLine(bounds.LeftBottom(), bounds.RightBottom()); bounds.bottom--; rgb_color baseColor = ui_color(B_PANEL_BACKGROUND_COLOR); be_control_look->DrawButtonBackground(view, bounds, bounds, baseColor, 0, BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER); int32 count = fTitleList.CountItems(); float minx = bounds.right; float maxx = bounds.left; for (int32 index = 0; index < count; index++) { BColumnTitle* title = fTitleList.ItemAt(index); title->Draw(view, title == pressedColumn); BRect titleBounds(title->Bounds()); if (titleBounds.left < minx) minx = titleBounds.left; if (titleBounds.right > maxx) maxx = titleBounds.right; } bounds = Bounds(); minx--; view->SetHighUIColor(B_PANEL_BACKGROUND_COLOR, B_DARKEN_1_TINT); view->StrokeLine(BPoint(minx, bounds.top), BPoint(minx, bounds.bottom - 1)); #if !(APP_SERVER_CLEARS_BACKGROUND) FillRect(BRect(bounds.left, bounds.top + 1, minx - 1, bounds.bottom - 1), B_SOLID_LOW); FillRect(BRect(maxx + 1, bounds.top + 1, bounds.right, bounds.bottom - 1), B_SOLID_LOW); #endif if (useOffscreen) { if (trackRectBlitter) (trackRectBlitter)(view, passThru); view->Sync(); DrawBitmap(sOffscreen->Bitmap()); sOffscreen->DoneUsing(); } else if (trackRectBlitter) (trackRectBlitter)(view, passThru); }
void RemoteView::_DrawThread() { RemoteMessage reply(NULL, fSendBuffer); RemoteMessage message(fReceiveBuffer, NULL); // cursor BPoint cursorHotSpot(0, 0); while (!fStopThread) { uint16 code; status_t status = message.NextMessage(code); if (status != B_OK) { TRACE_ERROR("failed to read message from receiver\n"); break; } TRACE("code %u with %ld bytes data\n", code, message.DataLeft()); BAutolock locker(this->Looper()); if (!locker.IsLocked()) break; // handle stuff that doesn't go to a specicifc engine switch (code) { case RP_INIT_CONNECTION: { uint16 port; status_t result = message.Read(port); if (result != B_OK) { TRACE_ERROR("failed to read remote port\n"); continue; } BNetEndpoint *endpoint = fReceiver->Endpoint(); if (endpoint == NULL) { TRACE_ERROR("receiver not connected anymore\n"); continue; } in_addr remoteHost; char hostName[MAXHOSTNAMELEN + 1]; BNetAddress address(endpoint->RemoteAddr()); address.GetAddr(remoteHost); address.GetAddr(hostName, NULL); address.SetTo(remoteHost, port); TRACE("connecting to host \"%s\" port %u\n", hostName, port); result = fSendEndpoint->Connect(address); if (result != B_OK) { TRACE_ERROR("failed to connect to host \"%s\" port %u\n", hostName, port); continue; } BRect bounds = fOffscreenBitmap->Bounds(); reply.Start(RP_UPDATE_DISPLAY_MODE); reply.Add(bounds.IntegerWidth() + 1); reply.Add(bounds.IntegerHeight() + 1); if (reply.Flush() == B_OK) fIsConnected = true; continue; } case RP_CLOSE_CONNECTION: { be_app->PostMessage(B_QUIT_REQUESTED); continue; } case RP_CREATE_STATE: case RP_DELETE_STATE: { uint32 token; message.Read(token); if (code == RP_CREATE_STATE) _CreateState(token); else _DeleteState(token); continue; } case RP_SET_CURSOR: { BBitmap *bitmap; BPoint oldHotSpot = cursorHotSpot; message.Read(cursorHotSpot); if (message.ReadBitmap(&bitmap) != B_OK) continue; delete fCursorBitmap; fCursorBitmap = bitmap; Invalidate(fCursorFrame); BRect bounds = fCursorBitmap->Bounds(); fCursorFrame.right = fCursorFrame.left + bounds.IntegerWidth() + 1; fCursorFrame.bottom = fCursorFrame.bottom + bounds.IntegerHeight() + 1; fCursorFrame.OffsetBy(oldHotSpot - cursorHotSpot); Invalidate(fCursorFrame); continue; } case RP_SET_CURSOR_VISIBLE: { bool wasVisible = fCursorVisible; message.Read(fCursorVisible); if (wasVisible != fCursorVisible) Invalidate(fCursorFrame); continue; } case RP_MOVE_CURSOR_TO: { BPoint position; message.Read(position); if (fCursorVisible) Invalidate(fCursorFrame); fCursorFrame.OffsetTo(position - cursorHotSpot); Invalidate(fCursorFrame); continue; } case RP_INVALIDATE_RECT: { BRect rect; if (message.Read(rect) != B_OK) continue; Invalidate(rect); continue; } case RP_INVALIDATE_REGION: { BRegion region; if (message.ReadRegion(region) != B_OK) continue; Invalidate(®ion); continue; } case RP_FILL_REGION_COLOR_NO_CLIPPING: { BRegion region; rgb_color color; message.ReadRegion(region); if (message.Read(color) != B_OK) continue; fOffscreen->LockLooper(); fOffscreen->SetHighColor(color); fOffscreen->FillRegion(®ion); fOffscreen->UnlockLooper(); Invalidate(®ion); continue; } case RP_COPY_RECT_NO_CLIPPING: { int32 xOffset, yOffset; BRect rect; message.Read(xOffset); message.Read(yOffset); if (message.Read(rect) != B_OK) continue; BRect dest = rect.OffsetByCopy(xOffset, yOffset); fOffscreen->LockLooper(); fOffscreen->CopyBits(rect, dest); fOffscreen->UnlockLooper(); continue; } } uint32 token; message.Read(token); engine_state *state = _FindState(token); if (state == NULL) { TRACE_ERROR("didn't find state for token %lu\n", token); continue; } BView *offscreen = state->view; ::pattern &pattern = state->pattern; BRegion &clippingRegion = state->clipping_region; float &penSize = state->pen_size; bool &syncDrawing = state->sync_drawing; BRegion invalidRegion; BAutolock offscreenLocker(offscreen->Looper()); if (!offscreenLocker.IsLocked()) break; switch (code) { case RP_ENABLE_SYNC_DRAWING: syncDrawing = true; continue; case RP_DISABLE_SYNC_DRAWING: syncDrawing = false; continue; case RP_SET_OFFSETS: { int32 xOffset, yOffset; message.Read(xOffset); if (message.Read(yOffset) != B_OK) continue; offscreen->MovePenTo(xOffset, yOffset); break; } case RP_SET_HIGH_COLOR: case RP_SET_LOW_COLOR: { rgb_color color; if (message.Read(color) != B_OK) continue; if (code == RP_SET_HIGH_COLOR) offscreen->SetHighColor(color); else offscreen->SetLowColor(color); break; } case RP_SET_PEN_SIZE: { float newPenSize; if (message.Read(newPenSize) != B_OK) continue; offscreen->SetPenSize(newPenSize); penSize = newPenSize / 2; break; } case RP_SET_STROKE_MODE: { cap_mode capMode; join_mode joinMode; float miterLimit; message.Read(capMode); message.Read(joinMode); if (message.Read(miterLimit) != B_OK) continue; offscreen->SetLineMode(capMode, joinMode, miterLimit); break; } case RP_SET_BLENDING_MODE: { source_alpha sourceAlpha; alpha_function alphaFunction; message.Read(sourceAlpha); if (message.Read(alphaFunction) != B_OK) continue; offscreen->SetBlendingMode(sourceAlpha, alphaFunction); break; } case RP_SET_PATTERN: { if (message.Read(pattern) != B_OK) continue; break; } case RP_SET_DRAWING_MODE: { drawing_mode drawingMode; if (message.Read(drawingMode) != B_OK) continue; offscreen->SetDrawingMode(drawingMode); break; } case RP_SET_FONT: { BFont font; if (message.ReadFontState(font) != B_OK) continue; offscreen->SetFont(&font); break; } case RP_CONSTRAIN_CLIPPING_REGION: { if (message.ReadRegion(clippingRegion) != B_OK) continue; offscreen->ConstrainClippingRegion(&clippingRegion); break; } case RP_INVERT_RECT: { BRect rect; if (message.Read(rect) != B_OK) continue; offscreen->InvertRect(rect); invalidRegion.Include(rect); break; } case RP_DRAW_BITMAP: { BBitmap *bitmap; BRect bitmapRect, viewRect; uint32 options; message.Read(bitmapRect); message.Read(viewRect); message.Read(options); if (message.ReadBitmap(&bitmap) != B_OK || bitmap == NULL) continue; offscreen->DrawBitmap(bitmap, bitmapRect, viewRect, options); invalidRegion.Include(viewRect); delete bitmap; break; } case RP_DRAW_BITMAP_RECTS: { color_space colorSpace; int32 rectCount; uint32 flags, options; message.Read(options); message.Read(colorSpace); message.Read(flags); message.Read(rectCount); for (int32 i = 0; i < rectCount; i++) { BBitmap *bitmap; BRect viewRect; message.Read(viewRect); if (message.ReadBitmap(&bitmap, true, colorSpace, flags) != B_OK || bitmap == NULL) { continue; } offscreen->DrawBitmap(bitmap, bitmap->Bounds(), viewRect, options); invalidRegion.Include(viewRect); delete bitmap; } break; } case RP_STROKE_ARC: case RP_FILL_ARC: case RP_FILL_ARC_GRADIENT: { BRect rect; float angle, span; message.Read(rect); message.Read(angle); if (message.Read(span) != B_OK) continue; if (code == RP_STROKE_ARC) { offscreen->StrokeArc(rect, angle, span, pattern); rect.InsetBy(-penSize, -penSize); } else if (code == RP_FILL_ARC) offscreen->FillArc(rect, angle, span, pattern); else { BGradient *gradient; if (message.ReadGradient(&gradient) != B_OK) continue; offscreen->FillArc(rect, angle, span, *gradient); delete gradient; } invalidRegion.Include(rect); break; } case RP_STROKE_BEZIER: case RP_FILL_BEZIER: case RP_FILL_BEZIER_GRADIENT: { BPoint points[4]; if (message.ReadList(points, 4) != B_OK) continue; BRect bounds = _BuildInvalidateRect(points, 4); if (code == RP_STROKE_BEZIER) { offscreen->StrokeBezier(points, pattern); bounds.InsetBy(-penSize, -penSize); } else if (code == RP_FILL_BEZIER) offscreen->FillBezier(points, pattern); else { BGradient *gradient; if (message.ReadGradient(&gradient) != B_OK) continue; offscreen->FillBezier(points, *gradient); delete gradient; } invalidRegion.Include(bounds); break; } case RP_STROKE_ELLIPSE: case RP_FILL_ELLIPSE: case RP_FILL_ELLIPSE_GRADIENT: { BRect rect; if (message.Read(rect) != B_OK) continue; if (code == RP_STROKE_ELLIPSE) { offscreen->StrokeEllipse(rect, pattern); rect.InsetBy(-penSize, -penSize); } else if (code == RP_FILL_ELLIPSE) offscreen->FillEllipse(rect, pattern); else { BGradient *gradient; if (message.ReadGradient(&gradient) != B_OK) continue; offscreen->FillEllipse(rect, *gradient); delete gradient; } invalidRegion.Include(rect); break; } case RP_STROKE_POLYGON: case RP_FILL_POLYGON: case RP_FILL_POLYGON_GRADIENT: { BRect bounds; bool closed; int32 numPoints; message.Read(bounds); message.Read(closed); if (message.Read(numPoints) != B_OK) continue; BPoint points[numPoints]; for (int32 i = 0; i < numPoints; i++) message.Read(points[i]); if (code == RP_STROKE_POLYGON) { offscreen->StrokePolygon(points, numPoints, bounds, closed, pattern); bounds.InsetBy(-penSize, -penSize); } else if (code == RP_FILL_POLYGON) offscreen->FillPolygon(points, numPoints, bounds, pattern); else { BGradient *gradient; if (message.ReadGradient(&gradient) != B_OK) continue; offscreen->FillPolygon(points, numPoints, bounds, *gradient); delete gradient; } invalidRegion.Include(bounds); break; } case RP_STROKE_RECT: case RP_FILL_RECT: case RP_FILL_RECT_GRADIENT: { BRect rect; if (message.Read(rect) != B_OK) continue; if (code == RP_STROKE_RECT) { offscreen->StrokeRect(rect, pattern); rect.InsetBy(-penSize, -penSize); } else if (code == RP_FILL_RECT) offscreen->FillRect(rect, pattern); else { BGradient *gradient; if (message.ReadGradient(&gradient) != B_OK) continue; offscreen->FillRect(rect, *gradient); delete gradient; } invalidRegion.Include(rect); break; } case RP_STROKE_ROUND_RECT: case RP_FILL_ROUND_RECT: case RP_FILL_ROUND_RECT_GRADIENT: { BRect rect; float xRadius, yRadius; message.Read(rect); message.Read(xRadius); if (message.Read(yRadius) != B_OK) continue; if (code == RP_STROKE_ROUND_RECT) { offscreen->StrokeRoundRect(rect, xRadius, yRadius, pattern); rect.InsetBy(-penSize, -penSize); } else if (code == RP_FILL_ROUND_RECT) offscreen->FillRoundRect(rect, xRadius, yRadius, pattern); else { BGradient *gradient; if (message.ReadGradient(&gradient) != B_OK) continue; offscreen->FillRoundRect(rect, xRadius, yRadius, *gradient); delete gradient; } invalidRegion.Include(rect); break; } case RP_STROKE_SHAPE: case RP_FILL_SHAPE: case RP_FILL_SHAPE_GRADIENT: { BRect bounds; int32 opCount, pointCount; message.Read(bounds); if (message.Read(opCount) != B_OK) continue; BMessage archive; for (int32 i = 0; i < opCount; i++) { int32 op; message.Read(op); archive.AddInt32("ops", op); } if (message.Read(pointCount) != B_OK) continue; for (int32 i = 0; i < pointCount; i++) { BPoint point; message.Read(point); archive.AddPoint("pts", point); } BPoint offset; message.Read(offset); float scale; if (message.Read(scale) != B_OK) continue; offscreen->PushState(); offscreen->MovePenTo(offset); offscreen->SetScale(scale); BShape shape(&archive); if (code == RP_STROKE_SHAPE) { offscreen->StrokeShape(&shape, pattern); bounds.InsetBy(-penSize, -penSize); } else if (code == RP_FILL_SHAPE) offscreen->FillShape(&shape, pattern); else { BGradient *gradient; if (message.ReadGradient(&gradient) != B_OK) { offscreen->PopState(); continue; } offscreen->FillShape(&shape, *gradient); delete gradient; } offscreen->PopState(); invalidRegion.Include(bounds); break; } case RP_STROKE_TRIANGLE: case RP_FILL_TRIANGLE: case RP_FILL_TRIANGLE_GRADIENT: { BRect bounds; BPoint points[3]; message.ReadList(points, 3); if (message.Read(bounds) != B_OK) continue; if (code == RP_STROKE_TRIANGLE) { offscreen->StrokeTriangle(points[0], points[1], points[2], bounds, pattern); bounds.InsetBy(-penSize, -penSize); } else if (code == RP_FILL_TRIANGLE) { offscreen->FillTriangle(points[0], points[1], points[2], bounds, pattern); } else { BGradient *gradient; if (message.ReadGradient(&gradient) != B_OK) continue; offscreen->FillTriangle(points[0], points[1], points[2], bounds, *gradient); delete gradient; } invalidRegion.Include(bounds); break; } case RP_STROKE_LINE: { BPoint points[2]; if (message.ReadList(points, 2) != B_OK) continue; offscreen->StrokeLine(points[0], points[1], pattern); BRect bounds = _BuildInvalidateRect(points, 2); invalidRegion.Include(bounds.InsetBySelf(-penSize, -penSize)); break; } case RP_STROKE_LINE_ARRAY: { int32 numLines; if (message.Read(numLines) != B_OK) continue; BRect bounds; offscreen->BeginLineArray(numLines); for (int32 i = 0; i < numLines; i++) { rgb_color color; BPoint start, end; message.ReadArrayLine(start, end, color); offscreen->AddLine(start, end, color); bounds.left = min_c(bounds.left, min_c(start.x, end.x)); bounds.top = min_c(bounds.top, min_c(start.y, end.y)); bounds.right = max_c(bounds.right, max_c(start.x, end.x)); bounds.bottom = max_c(bounds.bottom, max_c(start.y, end.y)); } offscreen->EndLineArray(); invalidRegion.Include(bounds); break; } case RP_FILL_REGION: case RP_FILL_REGION_GRADIENT: { BRegion region; if (message.ReadRegion(region) != B_OK) continue; if (code == RP_FILL_REGION) offscreen->FillRegion(®ion, pattern); else { BGradient *gradient; if (message.ReadGradient(&gradient) != B_OK) continue; offscreen->FillRegion(®ion, *gradient); delete gradient; } invalidRegion.Include(®ion); break; } case RP_STROKE_POINT_COLOR: { BPoint point; rgb_color color; message.Read(point); if (message.Read(color) != B_OK) continue; rgb_color oldColor = offscreen->HighColor(); offscreen->SetHighColor(color); offscreen->StrokeLine(point, point); offscreen->SetHighColor(oldColor); invalidRegion.Include( BRect(point, point).InsetBySelf(-penSize, -penSize)); break; } case RP_STROKE_LINE_1PX_COLOR: { BPoint points[2]; rgb_color color; message.ReadList(points, 2); if (message.Read(color) != B_OK) continue; float oldSize = offscreen->PenSize(); rgb_color oldColor = offscreen->HighColor(); drawing_mode oldMode = offscreen->DrawingMode(); offscreen->SetPenSize(1); offscreen->SetHighColor(color); offscreen->SetDrawingMode(B_OP_OVER); offscreen->StrokeLine(points[0], points[1]); offscreen->SetDrawingMode(oldMode); offscreen->SetHighColor(oldColor); offscreen->SetPenSize(oldSize); invalidRegion.Include(_BuildInvalidateRect(points, 2)); break; } case RP_STROKE_RECT_1PX_COLOR: case RP_FILL_RECT_COLOR: { BRect rect; rgb_color color; message.Read(rect); if (message.Read(color) != B_OK) continue; rgb_color oldColor = offscreen->HighColor(); offscreen->SetHighColor(color); if (code == RP_STROKE_RECT_1PX_COLOR) { float oldSize = PenSize(); offscreen->SetPenSize(1); offscreen->StrokeRect(rect); offscreen->SetPenSize(oldSize); } else offscreen->FillRect(rect); offscreen->SetHighColor(oldColor); invalidRegion.Include(rect); break; } case RP_DRAW_STRING: { BPoint point; size_t length; char *string; bool hasDelta; message.Read(point); message.ReadString(&string, length); if (message.Read(hasDelta) != B_OK) { free(string); continue; } if (hasDelta) { escapement_delta delta[length]; message.ReadList(delta, length); offscreen->DrawString(string, point, delta); } else offscreen->DrawString(string, point); free(string); reply.Start(RP_DRAW_STRING_RESULT); reply.Add(token); reply.Add(offscreen->PenLocation()); reply.Flush(); font_height height; offscreen->GetFontHeight(&height); BRect bounds(point, offscreen->PenLocation()); bounds.top -= height.ascent; bounds.bottom += height.descent; invalidRegion.Include(bounds); break; } case RP_DRAW_STRING_WITH_OFFSETS: { size_t length; char *string; message.ReadString(&string, length); int32 count = UTF8CountChars(string, length); BPoint offsets[count]; if (message.ReadList(offsets, count) != B_OK) { free(string); continue; } offscreen->DrawString(string, offsets, count); free(string); reply.Start(RP_DRAW_STRING_RESULT); reply.Add(token); reply.Add(offscreen->PenLocation()); reply.Flush(); BFont font; offscreen->GetFont(&font); BRect boxes[count]; font.GetBoundingBoxesAsGlyphs(string, count, B_SCREEN_METRIC, boxes); font_height height; offscreen->GetFontHeight(&height); for (int32 i = 0; i < count; i++) { // TODO: validate boxes[i].OffsetBy(offsets[i] + BPoint(0, -height.ascent)); invalidRegion.Include(boxes[i]); } break; } case RP_READ_BITMAP: { BRect bounds; bool drawCursor; message.Read(bounds); if (message.Read(drawCursor) != B_OK) continue; // TODO: support the drawCursor flag BBitmap bitmap(bounds, B_BITMAP_NO_SERVER_LINK, B_RGB32); bitmap.ImportBits(fOffscreenBitmap, bounds.LeftTop(), BPoint(0, 0), bounds.IntegerWidth() + 1, bounds.IntegerHeight() + 1); reply.Start(RP_READ_BITMAP_RESULT); reply.Add(token); reply.AddBitmap(&bitmap); reply.Flush(); break; } default: TRACE_ERROR("unknown protocol code: %u\n", code); break; } if (syncDrawing) { offscreen->Sync(); Invalidate(&invalidRegion); } } }
void MonthWindowView::AttachedToWindow(void) { SetFont(be_plain_font); SetViewColor(VIEW_COLOR); // Calculate size of cell needed for number of day of month font_height h; be_plain_font->GetHeight(&h); h_cell=(int)(h.ascent+h.descent+h.leading+6); w_cell=StringWidth("4")*4; #ifdef __LANG_RUSSIAN BString s(""); s<<tday; s.Append(" "); switch(tmonth) { case 1: { s.Append("января "); break; } case 2: { s.Append("февраля "); break; } case 3: { s.Append("марта "); break; } case 4: { s.Append("апреля "); break; } case 5: { s.Append("мая "); break; } case 6: { s.Append("июня "); break; } case 7: { s.Append("июля "); break; } case 8: { s.Append("августа "); break; } case 9: { s.Append("сентября "); break; } case 10: { s.Append("октября "); break; } case 11: { s.Append("ноября "); break; } case 12: { s.Append("декабря "); break; } } s<<tyear; s.Append(" г."); #else // localized, english and french BString s(""); s<<tday; s.Append(" "); s.Append(monthNames[tmonth-1]); s.Append(" "); s<<tyear; #endif msng=new BMessenger(this); todayStringView=new MouseSenseStringView(new BMessage('TODA'), msng, BRect(10,10,100,100),"todayMStringViewAViX", s.String()); AddChild(todayStringView); todayStringView->ResizeToPreferred(); todayStringView->SetViewColor(VIEW_COLOR); monthStringView=new BStringView(BRect(10,10,100,100),"monthStringViewAViX", monthNames[8]); monthStringView->SetAlignment(B_ALIGN_CENTER); AddChild(monthStringView); monthStringView->ResizeToPreferred(); monthStringView->SetText(monthNames[cmonth-1]); monthStringView->SetViewColor(VIEW_COLOR); s.SetTo(""); if(cyear<10) s.Append("000"); else if(cyear<100) s.Append("00"); else if(cyear<1000) s.Append("0"); s<<cyear; yearStringView=new BStringView(BRect(10,10,100,100),"yearStringViewAViX", "0000"); AddChild(yearStringView); yearStringView->ResizeToPreferred(); yearStringView->SetText(s.String()); yearStringView->SetViewColor(VIEW_COLOR); ResizeTo(w_cell*7+1,h_cell*7+3+16+yearStringView->Bounds().bottom+todayStringView->Bounds().bottom); Window()->ResizeTo(Bounds().right, Bounds().bottom); yearMStringView[0]=new MouseSenseStringView(new BMessage('YEA0'),msng, BRect(10,10,100,100), "yearMStringViewAViX0", "<<"); AddChild(yearMStringView[0]); yearMStringView[0]->ResizeToPreferred(); yearMStringView[0]->SetViewColor(VIEW_COLOR); yearMStringView[1]=new MouseSenseStringView(new BMessage('YEA1'),msng, BRect(10,10,100,100), "yearMStringViewAViX1", ">>"); AddChild(yearMStringView[1]); yearMStringView[1]->ResizeToPreferred(); yearMStringView[1]->SetViewColor(VIEW_COLOR); monthMStringView[0]=new MouseSenseStringView(new BMessage('MON0'),msng, BRect(10,10,100,100), "monthMStringViewAViX0", "<<"); AddChild(monthMStringView[0]); monthMStringView[0]->ResizeToPreferred(); monthMStringView[0]->SetViewColor(VIEW_COLOR); monthMStringView[1]=new MouseSenseStringView(new BMessage('MON1'),msng, BRect(10,10,100,100), "monthMStringViewAViX1", ">>"); AddChild(monthMStringView[1]); monthMStringView[1]->ResizeToPreferred(); monthMStringView[1]->SetViewColor(VIEW_COLOR); todayStringView->MoveTo((Bounds().right-todayStringView->Bounds().right)/2, Bounds().bottom-todayStringView->Bounds().bottom-2); if(tyear<first_year || tyear>last_year) todayStringView->SetHighColor(NOACTIVE_COLOR); yearMStringView[1]->MoveTo(Bounds().right-yearMStringView[1]->Bounds().right,5); yearStringView->MoveTo(yearMStringView[1]->Frame().left-yearStringView->Bounds().right,5); yearMStringView[0]->MoveTo(yearStringView->Frame().left-yearMStringView[0]->Bounds().right,5); monthStringView->MoveTo((yearMStringView[0]->Frame().left-monthStringView->Bounds().right)/2,5); monthMStringView[0]->MoveTo(monthStringView->Frame().left-monthMStringView[0]->Bounds().right,5); monthMStringView[1]->MoveTo(monthStringView->Frame().right,5); which_focused=2; // days of month Bmp=new BBitmap(BRect(Frame()),B_RGB32,true); BmpView=new BView(Bmp->Bounds(),"BV",0,B_WILL_DRAW); Bmp->AddChild(BmpView); Bmp->Lock(); BmpView->SetHighColor(VIEW_COLOR); BmpView->FillRect(BmpView->Frame()); BmpView->SetHighColor(LINE_COLOR); BmpView->StrokeLine(BPoint(3,todayStringView->Frame().top-5), BPoint(Bounds().right-3,todayStringView->Frame().top-5)); BmpView->StrokeLine(BPoint(3,yearStringView->Frame().bottom+2), BPoint(Bounds().right-3,yearStringView->Frame().bottom+2)); BmpView->SetHighColor(0,0,0,0); float y=yearStringView->Frame().bottom+h_cell; float x=0; for(int i=0;i<7;i++) { BmpView->DrawString(weekdayNames[i],BPoint(x+(w_cell-StringWidth(weekdayNames[i]))/2,y)); x+=w_cell; } BmpView->Sync(); Bmp->Unlock(); DrawMonth(); }
void MonthWindowView::KeyDown(const char *bytes, int32 numBytes) { switch(bytes[0]) { case B_TAB: { Bmp->Lock(); switch(which_focused) { case 0: // months { BmpView->SetHighColor(VIEW_COLOR); BmpView->StrokeLine(BPoint(monthMStringView[0]->Frame().left, monthMStringView[0]->Frame().bottom+1), BPoint(monthMStringView[1]->Frame().right, monthMStringView[1]->Frame().bottom+1)); BmpView->SetHighColor(0,0,0); break; } case 1: // years { BmpView->SetHighColor(VIEW_COLOR); BmpView->StrokeLine(BPoint(yearMStringView[0]->Frame().left, yearMStringView[0]->Frame().bottom+1), BPoint(yearMStringView[1]->Frame().right, yearMStringView[1]->Frame().bottom+1)); BmpView->SetHighColor(0,0,0); break; } case 2: // days of month { BmpView->SetHighColor(NOACTIVE_COLOR); BmpView->StrokeRect(cursor); BmpView->SetHighColor(0,0,0); break; } case 3: // today { BmpView->SetHighColor(VIEW_COLOR); BmpView->StrokeLine(BPoint(todayStringView->Frame().left, todayStringView->Frame().bottom+1), BPoint(todayStringView->Frame().right, todayStringView->Frame().bottom+1)); BmpView->SetHighColor(0,0,0); break; } } // changing which_focused if(modifiers() & B_SHIFT_KEY) { if(which_focused==0) which_focused=3; else which_focused--; } else // simply Tab { if(which_focused==3) which_focused=0; else which_focused++; } // drawing with new which_focused switch(which_focused) { case 0: // months { BmpView->SetHighColor(ACTIVE_COLOR); BmpView->StrokeLine(BPoint(monthMStringView[0]->Frame().left, monthMStringView[0]->Frame().bottom+1), BPoint(monthMStringView[1]->Frame().right, monthMStringView[1]->Frame().bottom+1)); BmpView->SetHighColor(0,0,0); break; } case 1: // years { BmpView->SetHighColor(ACTIVE_COLOR); BmpView->StrokeLine(BPoint(yearMStringView[0]->Frame().left, yearMStringView[0]->Frame().bottom+1), BPoint(yearMStringView[1]->Frame().right, yearMStringView[1]->Frame().bottom+1)); BmpView->SetHighColor(0,0,0); break; } case 2: // days of month { BmpView->SetHighColor(ACTIVE_COLOR); BmpView->StrokeRect(cursor); BmpView->SetHighColor(0,0,0); break; } case 3: // today { BmpView->SetHighColor(ACTIVE_COLOR); BmpView->StrokeLine(BPoint(todayStringView->Frame().left, todayStringView->Frame().bottom+1), BPoint(todayStringView->Frame().right, todayStringView->Frame().bottom+1)); BmpView->SetHighColor(0,0,0); break; } } BmpView->Sync(); Bmp->Unlock(); Draw(Bounds()); break; } // B_TAB case B_DOWN_ARROW: { if(which_focused==0) // month { BMessage msg('MON0'); MessageReceived(&msg); } else if(which_focused==1) // year { BMessage msg('YEA0'); MessageReceived(&msg); } else if(which_focused==2) // days of month { int qu_days=monthDays[cmonth-1]; if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29; if((cday+7)<=qu_days) { Bmp->Lock(); BmpView->SetHighColor(VIEW_COLOR); BmpView->StrokeRect(cursor); cursor.OffsetBySelf(0, h_cell); cday+=7; BmpView->SetHighColor(ACTIVE_COLOR); BmpView->StrokeRect(cursor); BmpView->SetHighColor(0,0,0); BmpView->Sync(); Bmp->Unlock(); Draw(Bounds()); } } break; } case B_UP_ARROW: { // Test whether Ctrl+UpArrow is pressed if(modifiers() & B_CONTROL_KEY) Window()->PostMessage(B_QUIT_REQUESTED); else { if(which_focused==0) // month { BMessage msg('MON1'); MessageReceived(&msg); } else if(which_focused==1) // year { BMessage msg('YEA1'); MessageReceived(&msg); } else if(which_focused==2) // days of month { if((cday-7)>=1) { Bmp->Lock(); BmpView->SetHighColor(VIEW_COLOR); BmpView->StrokeRect(cursor); cursor.OffsetBySelf(0, -h_cell); cday-=7; BmpView->SetHighColor(ACTIVE_COLOR); BmpView->StrokeRect(cursor); BmpView->SetHighColor(0,0,0); BmpView->Sync(); Bmp->Unlock(); Draw(Bounds()); } } } break; } case B_LEFT_ARROW: { if(which_focused==0) // month { BMessage msg('MON0'); MessageReceived(&msg); } else if(which_focused==1) // year { BMessage msg('YEA0'); MessageReceived(&msg); } else if(which_focused==2) // days of month { if(cday>1) { Bmp->Lock(); BmpView->SetHighColor(VIEW_COLOR); BmpView->StrokeRect(cursor); if(cwday>0) // by dates no matter of day of week { cursor.OffsetBySelf(-w_cell,0); cwday--; } else // cwday==0 { cursor.OffsetBySelf(w_cell*6,-h_cell); cwday=6; } cday--; BmpView->SetHighColor(ACTIVE_COLOR); BmpView->StrokeRect(cursor); BmpView->SetHighColor(0,0,0); BmpView->Sync(); Bmp->Unlock(); Draw(Bounds()); } else // 1st of month, go month before { if(cyear>first_year || cmonth>1) // one can go { int cm=(cmonth==1) ? 12 : cmonth-1; int qu_days=monthDays[cm-1]; if(cm==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29; // it is correct not to pay attention to year changing // because if we moved to february then year was not changed // but if month is other then february // then it has the same number of days every year. cday=qu_days; BMessage msg('MON0'); MessageReceived(&msg); // here month, cwday and year (if needed) will be changed } } } break; } case B_RIGHT_ARROW: { if(which_focused==0) // month { BMessage msg('MON1'); MessageReceived(&msg); } else if(which_focused==1) // year { BMessage msg('YEA1'); MessageReceived(&msg); } else if(which_focused==2) // days of month { int qu_days=monthDays[cmonth-1]; if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29; if(cday<qu_days) { Bmp->Lock(); BmpView->SetHighColor(VIEW_COLOR); BmpView->StrokeRect(cursor); if(cwday<6) // by dates no matter of day of week { cursor.OffsetBySelf(w_cell,0); cwday++; } else // cwday==6 { cursor.OffsetBySelf(-w_cell*6,h_cell); cwday=0; } cday++; BmpView->SetHighColor(ACTIVE_COLOR); BmpView->StrokeRect(cursor); BmpView->SetHighColor(0,0,0); BmpView->Sync(); Bmp->Unlock(); Draw(Bounds()); } else // last of month, go next month { if(cyear<last_year || cmonth<12) // one can go { cday=1; BMessage msg('MON1'); MessageReceived(&msg); // here month, cwday and year (if needed) will be changed } } } break; } case B_ESCAPE: { Window()->PostMessage(B_QUIT_REQUESTED); break; } case B_ENTER: { if(which_focused==2) { // here it is needed to send dayPressed (==cwday), cyear, cmonth // to window and leave BMessage *msg=new BMessage('MVME'); msg->AddInt32("day",cday); msg->AddInt32("month",cmonth); msg->AddInt32("year",cyear); Window()->PostMessage(msg); } else if(which_focused==3) { BMessage msg('TODA'); MessageReceived(&msg); } break; } case B_SPACE: // the same as B_ENTER { if(which_focused==2) { // here it is needed to send dayPressed (==cwday), cyear, cmonth // to window and leave BMessage *msg=new BMessage('MVME'); msg->AddInt32("day",cday); msg->AddInt32("month",cmonth); msg->AddInt32("year",cyear); Window()->PostMessage(msg); } else if(which_focused==3) { BMessage msg('TODA'); MessageReceived(&msg); } break; } default: BView::KeyDown(bytes, numBytes); } }
void BSlider::_DrawTriangleThumb() { BRect frame = ThumbFrame(); BView *view = OffscreenView(); if (be_control_look != NULL) { rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 flags = be_control_look->Flags(this); be_control_look->DrawSliderTriangle(view, frame, frame, base, flags, fOrientation); return; } rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color lightenmax; rgb_color lighten1; rgb_color darken2; rgb_color darken3; rgb_color darkenmax; if (IsEnabled()) { lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT); lighten1 = no_tint; darken2 = tint_color(no_tint, B_DARKEN_2_TINT); darken3 = tint_color(no_tint, B_DARKEN_3_TINT); darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); } else { lightenmax = tint_color(no_tint, B_LIGHTEN_2_TINT); lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT); darken2 = tint_color(no_tint, (B_NO_TINT + B_DARKEN_1_TINT) / 2); darken3 = tint_color(no_tint, B_DARKEN_1_TINT); darkenmax = tint_color(no_tint, B_DARKEN_3_TINT); } if (Orientation() == B_HORIZONTAL) { view->SetHighColor(lighten1); view->FillTriangle( BPoint(frame.left + 1, frame.bottom - 3), BPoint((frame.left + frame.right) / 2, frame.top + 1), BPoint(frame.right - 1, frame.bottom - 3)); view->SetHighColor(no_tint); view->StrokeLine(BPoint(frame.right - 2, frame.bottom - 3), BPoint(frame.left + 3, frame.bottom - 3)); view->SetHighColor(darkenmax); view->StrokeLine(BPoint(frame.left, frame.bottom - 1), BPoint(frame.right, frame.bottom - 1)); view->StrokeLine(BPoint(frame.right, frame.bottom - 2), BPoint((frame.left + frame.right) / 2, frame.top)); view->SetHighColor(darken2); view->StrokeLine(BPoint(frame.right - 1, frame.bottom - 2), BPoint(frame.left + 1, frame.bottom - 2)); view->SetHighColor(darken3); view->StrokeLine(BPoint(frame.left, frame.bottom - 2), BPoint((frame.left + frame.right) / 2 - 1, frame.top + 1)); view->SetHighColor(lightenmax); view->StrokeLine(BPoint(frame.left + 2, frame.bottom - 3), BPoint((frame.left + frame.right) / 2, frame.top + 1)); // Shadow view->SetHighColor(0, 0, 0, IsEnabled() ? 80 : 40); view->SetDrawingMode(B_OP_ALPHA); view->StrokeLine(BPoint(frame.left + 1, frame.bottom), BPoint(frame.right, frame.bottom)); } else { view->SetHighColor(lighten1); view->FillTriangle( BPoint(frame.left, (frame.top + frame.bottom) / 2), BPoint(frame.right - 1, frame.top + 1), BPoint(frame.right - 1, frame.bottom - 1)); view->SetHighColor(darkenmax); view->StrokeLine(BPoint(frame.right - 1, frame.top), BPoint(frame.right - 1, frame.bottom)); view->StrokeLine(BPoint(frame.right - 1, frame.bottom), BPoint(frame.right - 2, frame.bottom)); view->SetHighColor(darken2); view->StrokeLine(BPoint(frame.right - 2, frame.top + 2), BPoint(frame.right - 2, frame.bottom - 1)); view->StrokeLine( BPoint(frame.left, (frame.top + frame.bottom) / 2), BPoint(frame.right - 2, frame.top)); view->SetHighColor(darken3); view->StrokeLine( BPoint(frame.left + 1, (frame.top + frame.bottom) / 2 + 1), BPoint(frame.right - 3, frame.bottom - 1)); view->SetHighColor(lightenmax); view->StrokeLine( BPoint(frame.left + 1, (frame.top + frame.bottom) / 2), BPoint(frame.right - 2, frame.top + 1)); // Shadow view->SetHighColor(0, 0, 0, IsEnabled() ? 80 : 40); view->SetDrawingMode(B_OP_ALPHA); view->StrokeLine(BPoint(frame.right, frame.top + 1), BPoint(frame.right, frame.bottom)); } view->SetDrawingMode(B_OP_COPY); }
void BSlider::DrawBar() { BRect frame = BarFrame(); BView *view = OffscreenView(); if (be_control_look != NULL) { uint32 flags = be_control_look->Flags(this); rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color rightFillColor = fBarColor; rgb_color leftFillColor = fUseFillColor ? fFillColor : fBarColor; be_control_look->DrawSliderBar(view, frame, frame, base, leftFillColor, rightFillColor, Position(), flags, fOrientation); return; } rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color lightenmax; rgb_color darken1; rgb_color darken2; rgb_color darkenmax; rgb_color barColor; rgb_color fillColor; if (IsEnabled()) { lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT); darken1 = tint_color(no_tint, B_DARKEN_1_TINT); darken2 = tint_color(no_tint, B_DARKEN_2_TINT); darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); barColor = fBarColor; fillColor = fFillColor; } else { lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT); darken1 = no_tint; darken2 = tint_color(no_tint, B_DARKEN_1_TINT); darkenmax = tint_color(no_tint, B_DARKEN_3_TINT); barColor.red = (fBarColor.red + no_tint.red) / 2; barColor.green = (fBarColor.green + no_tint.green) / 2; barColor.blue = (fBarColor.blue + no_tint.blue) / 2; barColor.alpha = 255; fillColor.red = (fFillColor.red + no_tint.red) / 2; fillColor.green = (fFillColor.green + no_tint.green) / 2; fillColor.blue = (fFillColor.blue + no_tint.blue) / 2; fillColor.alpha = 255; } // exclude the block thumb from the bar filling BRect lowerFrame = frame.InsetByCopy(1, 1); lowerFrame.top++; lowerFrame.left++; BRect upperFrame = lowerFrame; BRect thumbFrame; if (Style() == B_BLOCK_THUMB) { thumbFrame = ThumbFrame(); if (fOrientation == B_HORIZONTAL) { lowerFrame.right = thumbFrame.left; upperFrame.left = thumbFrame.right; } else { lowerFrame.top = thumbFrame.bottom; upperFrame.bottom = thumbFrame.top; } } else if (fUseFillColor) { if (fOrientation == B_HORIZONTAL) { lowerFrame.right = floor(lowerFrame.left - 1 + Position() * (lowerFrame.Width() + 1)); upperFrame.left = lowerFrame.right; } else { lowerFrame.top = floor(lowerFrame.bottom + 1 - Position() * (lowerFrame.Height() + 1)); upperFrame.bottom = lowerFrame.top; } } view->SetHighColor(barColor); view->FillRect(upperFrame); if (Style() == B_BLOCK_THUMB || fUseFillColor) { if (fUseFillColor) view->SetHighColor(fillColor); view->FillRect(lowerFrame); } if (Style() == B_BLOCK_THUMB) { // We don't want to stroke the lines over the thumb PushState(); BRegion region; GetClippingRegion(®ion); region.Exclude(thumbFrame); ConstrainClippingRegion(®ion); } view->SetHighColor(darken1); view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.left + 1.0f, frame.top)); view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.left + 1.0f, frame.bottom)); view->StrokeLine(BPoint(frame.right - 1.0f, frame.top), BPoint(frame.right, frame.top)); view->SetHighColor(darken2); view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), BPoint(frame.right - 1.0f, frame.top)); view->StrokeLine(BPoint(frame.left, frame.bottom - 1.0f), BPoint(frame.left, frame.top + 1.0f)); view->SetHighColor(lightenmax); view->StrokeLine(BPoint(frame.left + 1.0f, frame.bottom), BPoint(frame.right, frame.bottom)); view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), BPoint(frame.right, frame.top + 1.0f)); frame.InsetBy(1.0f, 1.0f); view->SetHighColor(darkenmax); view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.left, frame.top)); view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), BPoint(frame.right, frame.top)); if (Style() == B_BLOCK_THUMB) PopState(); }
void BSlider::_DrawBlockThumb() { BRect frame = ThumbFrame(); BView *view = OffscreenView(); if (be_control_look != NULL) { rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 flags = be_control_look->Flags(this); be_control_look->DrawSliderThumb(view, frame, frame, base, flags, fOrientation); return; } rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color lighten2; rgb_color lighten1; rgb_color darken2; rgb_color darken3; rgb_color darkenmax; if (IsEnabled()) { lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT); lighten1 = no_tint; darken2 = tint_color(no_tint, B_DARKEN_2_TINT); darken3 = tint_color(no_tint, B_DARKEN_3_TINT); darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); } else { lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT); lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT); darken2 = tint_color(no_tint, (B_NO_TINT + B_DARKEN_1_TINT) / 2.0); darken3 = tint_color(no_tint, B_DARKEN_1_TINT); darkenmax = tint_color(no_tint, B_DARKEN_3_TINT); } // blank background for shadow // ToDo: this also draws over the hash marks (though it's not *that* noticeable) view->SetHighColor(no_tint); view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.left, frame.top)); BRect barFrame = BarFrame(); if (barFrame.right >= frame.right) { // leave out barFrame from shadow background clearing view->StrokeLine(BPoint(frame.right, frame.top), BPoint(frame.right, barFrame.top - 1.0f)); view->StrokeLine(BPoint(frame.right, barFrame.bottom + 1.0f), BPoint(frame.right, frame.bottom)); } else { view->StrokeLine(BPoint(frame.right, frame.top), BPoint(frame.right, frame.bottom)); } view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.right - 1.0f, frame.bottom)); view->StrokeLine(BPoint(frame.left, frame.bottom - 1.0f), BPoint(frame.left, frame.bottom - 1.0f)); view->StrokeLine(BPoint(frame.right - 1.0f, frame.top), BPoint(frame.right - 1.0f, frame.top)); // Outline (top, left) view->SetHighColor(darken3); view->StrokeLine(BPoint(frame.left, frame.bottom - 2.0f), BPoint(frame.left, frame.top + 1.0f)); view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), BPoint(frame.right - 2.0f, frame.top)); // Shadow view->SetHighColor(0, 0, 0, IsEnabled() ? 100 : 50); view->SetDrawingMode(B_OP_ALPHA); view->StrokeLine(BPoint(frame.right, frame.top + 2.0f), BPoint(frame.right, frame.bottom - 1.0f)); view->StrokeLine(BPoint(frame.left + 2.0f, frame.bottom), BPoint(frame.right - 1.0f, frame.bottom)); view->SetDrawingMode(B_OP_COPY); view->SetHighColor(darken3); view->StrokeLine(BPoint(frame.right - 1.0f, frame.bottom - 1.0f), BPoint(frame.right - 1.0f, frame.bottom - 1.0f)); // First bevel frame.InsetBy(1.0f, 1.0f); view->SetHighColor(darkenmax); view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.right - 1.0f, frame.bottom)); view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), BPoint(frame.right, frame.top)); view->SetHighColor(lighten2); view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.left, frame.bottom - 1.0f)); view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), BPoint(frame.right - 1.0f, frame.top)); frame.InsetBy(1.0f, 1.0f); view->FillRect(BRect(frame.left, frame.top, frame.right - 1.0f, frame.bottom - 1.0f)); // Second bevel and center dots view->SetHighColor(darken2); view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.right, frame.bottom)); view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), BPoint(frame.right, frame.top)); if (Orientation() == B_HORIZONTAL) { view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 2.0f), BPoint(frame.left + 6.0f, frame.top + 2.0f)); view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 4.0f), BPoint(frame.left + 6.0f, frame.top + 4.0f)); view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f), BPoint(frame.left + 6.0f, frame.top + 6.0f)); } else { view->StrokeLine(BPoint(frame.left + 2.0f, frame.top + 6.0f), BPoint(frame.left + 2.0f, frame.top + 6.0f)); view->StrokeLine(BPoint(frame.left + 4.0f, frame.top + 6.0f), BPoint(frame.left + 4.0f, frame.top + 6.0f)); view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f), BPoint(frame.left + 6.0f, frame.top + 6.0f)); } frame.InsetBy(1.0f, 1.0f); // Third bevel view->SetHighColor(lighten1); view->StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.right, frame.bottom)); view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), BPoint(frame.right, frame.top)); }
void CalcoloKtView::Calculate() { BString txt1text; BString txt2text; BString kt_text; long double Kt; long double x; // r/d long double D_d; // D/d long double a; long double b; long double c; long double a1; long double b1; long double c1; txt1text << txt1->Text(); txt2text << txt2->Text(); x = atof(txt1text.String()); D_d = atof(txt2text.String()); if (!((x > 0) && (x <= 0.3))) { BAlert *myAlert = new BAlert(ALERT_RD_TITLE, ALERT_RD_MESSAGE, ALERT_OK, NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT); myAlert->Go(); return; } if (!((D_d >= 1.01) && (D_d <= 3))) { BAlert *myAlert = new BAlert(ALERT_DD_TITLE, ALERT_DD_MESSAGE, ALERT_OK, NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT); myAlert->Go(); return; } if (D_d <= 1.05) { a1 = 0.590823256; b1 = 0.000625284; a = a1 + b1 / log(D_d); } else { a1 = 0.806683239; b1 = -0.010667756; c1 = 0.342511804; a = a1 + b1 * (D_d / log(D_d)) + c1 * (log(D_d) / D_d); } a1 = -0.287595623; b1 = -0.021137436; c1 = 0.001099864; b = a1 + b1 * D_d + c1 / log(D_d); if (D_d <= 1.05) { a1 = -1.585648431; b1 = 0.003195393; c = a1 + b1 * (D_d / log(D_d)); } else { a1 = 37.11501602; b1 = 14.59448006; c1 = -51.84367334; c = D_d / (a1 + b1 * D_d + c1 * sqrt(D_d)); } Kt = a * pow(x, b) * pow((1-x), c); kt_text << "Kt : "; kt_text << (float)Kt; lbl1->SetText(kt_text.String()); /* kt_text.SetTo(""); kt_text << "D_d : "; kt_text << (float)D_d; kt_text << "a : "; kt_text << (float)a; kt_text << "; b : "; kt_text << (float)b; kt_text << "; c : "; kt_text << (float)c; txt2->SetText(kt_text.String()); */ BView *drawView; drawView = (BView *)FindView("drawView"); drawView->SetHighColor(0, 200, 50); /* .:: Asse x (30, 200) - (310, 200) ::. .:: Asse y (30, 0) - ( 30, 200)::. */ BPoint p1, p2; p1.x = (310 - 30) * x / 0.28 + 30; p1.y = 200 - 200 * Kt / 4; p2.x = (310 - 30) * x / 0.28 + 30; p2.y = 200; drawView->StrokeLine(p1, p2, B_SOLID_HIGH); p1.x = (310 - 30) * x / 0.28 + 30; p1.y = 200 - 200 * Kt / 4; p2.x = 30; p2.y = 200 - 200 * Kt / 4; drawView->StrokeLine(p1, p2, B_SOLID_HIGH); drawView->SetHighColor(0, 0, 0); float xres; xres = 0.28 / (310 - 30 + 1); x = 1 * xres; p1.x = 1 + 30; p1.y = 200 - 200 * ( a * pow(x, b) * pow((1-x), c)) / 4; drawView->MovePenTo(p1); for (int i = 2; i <= 280; i++) { x = i * xres; p1.x = i + 30; p1.y = 200 - 200 * ( a * pow(x, b) * pow((1-x), c)) / 4; drawView->StrokeLine(p1, B_SOLID_HIGH); } }
void CalcoloKtView::Draw(BRect) { BView *iconView; iconView = (BView *)FindView("iconView"); iconView->SetHighColor(0, 0, 0); BPoint p1, p2; // Dimensioni della BView iconView 130 x 60 pixels float x_origin; float y_origin; float l_tot; float h_tot; // .:: Dimensioni principali dell'icona ::. x_origin = 25; y_origin = 5; l_tot = 90; h_tot = 52; // .:: Sezione Sx ::. p1.x = x_origin; p1.y = y_origin; p2.x = x_origin + l_tot * 5 / 9; p2.y = y_origin; iconView->StrokeLine(p1, p2, B_SOLID_HIGH); p1.x = x_origin; p1.y = y_origin + h_tot; p2.x = x_origin + l_tot * 5 / 9; p2.y = y_origin + h_tot; iconView->StrokeLine(p1, p2, B_SOLID_HIGH); p1.x = x_origin + l_tot * 5 / 9; p1.y = y_origin; p2.x = x_origin + l_tot * 5 / 9; p2.y = y_origin + h_tot; iconView->StrokeLine(p1, p2, B_SOLID_HIGH); // .:: Quota Sx ::. p1.x = x_origin + (l_tot * 5 / 9)/2; p1.y = y_origin; p2.x = x_origin + (l_tot * 5 / 9)/2; p2.y = y_origin + h_tot; iconView->StrokeLine(p1, p2, B_SOLID_HIGH); // .:: Freccie quota Sx ::. float largfreccie; BPoint p3; largfreccie = h_tot * 3 / 52; p1.x = x_origin + (l_tot * 5 / 9)/2; p1.y = y_origin; p2.x = p1.x - largfreccie / 2; p2.y = p1.y + largfreccie * 2; p3.x = p1.x + largfreccie / 2; p3.y = p1.y + largfreccie * 2; iconView->FillTriangle(p1, p2, p3, B_SOLID_HIGH); p1.x = x_origin + (l_tot * 5 / 9)/2; p1.y = y_origin + h_tot; p2.x = p1.x - largfreccie / 2; p2.y = p1.y - largfreccie * 2; p3.x = p1.x + largfreccie / 2; p3.y = p1.y - largfreccie * 2; iconView->FillTriangle(p1, p2, p3, B_SOLID_HIGH); // .:: Testo quota Sx ::. BPoint dimtext; BFont font(be_plain_font); float fontsize; fontsize = h_tot * 7 / 52; font.SetSize(fontsize); iconView->SetFont(&font); dimtext.x = x_origin + (l_tot * 5 / 9)/2 + l_tot * 5 / 90; dimtext.y = y_origin + h_tot / 2 + fontsize / 2; iconView->MovePenTo(dimtext); iconView->DrawString("D"); // .:: Sezione Dx ::. float arcradius; arcradius = l_tot * 7 / 90; p1.x = x_origin + l_tot * 5 / 9 + arcradius; p1.y = y_origin + h_tot / 4; p2.x = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 14 / 45; p2.y = y_origin + h_tot / 4; iconView->StrokeLine(p1, p2, B_SOLID_HIGH); p1.x = x_origin + l_tot * 5 / 9 + arcradius; p1.y = y_origin + h_tot *3 / 4; p2.x = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 14 / 45; p2.y = y_origin + h_tot *3 / 4; iconView->StrokeLine(p1, p2, B_SOLID_HIGH); // .:: Quota Dx ::. p1.x = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 7 / 45; p1.y = y_origin + h_tot / 4; p2.x = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 7 / 45; p2.y = y_origin + h_tot *3 / 4; iconView->StrokeLine(p1, p2, B_SOLID_HIGH); // .:: Freccie quota Sx ::. largfreccie = h_tot * 3 / 52; p1.x = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 7 / 45; p1.y = y_origin + h_tot / 4; p2.x = p1.x - largfreccie / 2; p2.y = p1.y + largfreccie * 2; p3.x = p1.x + largfreccie / 2; p3.y = p1.y + largfreccie * 2; iconView->FillTriangle(p1, p2, p3, B_SOLID_HIGH); p1.x = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 7 / 45; p1.y = y_origin + h_tot *3 / 4; p2.x = p1.x - largfreccie / 2; p2.y = p1.y - largfreccie * 2; p3.x = p1.x + largfreccie / 2; p3.y = p1.y - largfreccie * 2; iconView->FillTriangle(p1, p2, p3, B_SOLID_HIGH); // .:: Testo quota Dx ::. dimtext.x = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 7 / 45 + l_tot * 5 / 90; dimtext.y = y_origin + h_tot / 2 + fontsize / 2; iconView->MovePenTo(dimtext); iconView->DrawString("d"); // .:: Simbolo di continuazione a Sx ::. float xbezorig; float ybezorig; float xunit; float yunit; BPoint controlpoints[4]; xbezorig = x_origin; ybezorig = y_origin; xunit = l_tot * 2 / 45; yunit = h_tot / 20; controlpoints[0].x = xbezorig; controlpoints[0].y = ybezorig; controlpoints[1].x = xbezorig + 0.8 * xunit; controlpoints[1].y = ybezorig + 1 * yunit; controlpoints[2].x = xbezorig + 1.2 * xunit; controlpoints[2].y = ybezorig + 2 * yunit; controlpoints[3].x = xbezorig + 1.5 * xunit; controlpoints[3].y = ybezorig + 3 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig + 1.5 * xunit; controlpoints[0].y = ybezorig + 3 * yunit; controlpoints[1].x = xbezorig + 1.7 * xunit; controlpoints[1].y = ybezorig + 4 * yunit; controlpoints[2].x = xbezorig + 1.5 * xunit; controlpoints[2].y = ybezorig + 5 * yunit; controlpoints[3].x = xbezorig + 1.1 * xunit; controlpoints[3].y = ybezorig + 6 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig + 1.1 * xunit; controlpoints[0].y = ybezorig + 6 * yunit; controlpoints[1].x = xbezorig + 1 * xunit; controlpoints[1].y = ybezorig + 7 * yunit; controlpoints[2].x = xbezorig + 0.8 * xunit; controlpoints[2].y = ybezorig + 8 * yunit; controlpoints[3].x = xbezorig + 0.3 * xunit; controlpoints[3].y = ybezorig + 9 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig + 1 * xunit; controlpoints[0].y = ybezorig + 7 * yunit; controlpoints[1].x = xbezorig + 0.8 * xunit; controlpoints[1].y = ybezorig + 8 * yunit; controlpoints[2].x = xbezorig + 0.3 * xunit; controlpoints[2].y = ybezorig + 9 * yunit; controlpoints[3].x = xbezorig; controlpoints[3].y = ybezorig + 10 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig; controlpoints[0].y = ybezorig + 10 * yunit; controlpoints[1].x = xbezorig - 0.8 * xunit; controlpoints[1].y = ybezorig + 11 * yunit; controlpoints[2].x = xbezorig - 1.2 * xunit; controlpoints[2].y = ybezorig + 12 * yunit; controlpoints[3].x = xbezorig - 1.5 * xunit; controlpoints[3].y = ybezorig + 13 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig - 1.5 * xunit; controlpoints[0].y = ybezorig + 13 * yunit; controlpoints[1].x = xbezorig - 1.7 * xunit; controlpoints[1].y = ybezorig + 14 * yunit; controlpoints[2].x = xbezorig - 1.5 * xunit; controlpoints[2].y = ybezorig + 15 * yunit; controlpoints[3].x = xbezorig - 1.1 * xunit; controlpoints[3].y = ybezorig + 16 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig - 1.1 * xunit; controlpoints[0].y = ybezorig + 16 * yunit; controlpoints[1].x = xbezorig - 1 * xunit; controlpoints[1].y = ybezorig + 17 * yunit; controlpoints[2].x = xbezorig - 0.8 * xunit; controlpoints[2].y = ybezorig + 18 * yunit; controlpoints[3].x = xbezorig - 0.3 * xunit; controlpoints[3].y = ybezorig + 19 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig - 1 * xunit; controlpoints[0].y = ybezorig + 17 * yunit; controlpoints[1].x = xbezorig - 0.8 * xunit; controlpoints[1].y = ybezorig + 18 * yunit; controlpoints[2].x = xbezorig - 0.3 * xunit; controlpoints[2].y = ybezorig + 19 * yunit; controlpoints[3].x = xbezorig; controlpoints[3].y = ybezorig + 20 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig; controlpoints[0].y = ybezorig; controlpoints[1].x = xbezorig - 0.8 * xunit; controlpoints[1].y = ybezorig + 1 * yunit; controlpoints[2].x = xbezorig - 1.2 * xunit; controlpoints[2].y = ybezorig + 2 * yunit; controlpoints[3].x = xbezorig - 1.5 * xunit; controlpoints[3].y = ybezorig + 3 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig - 1.5 * xunit; controlpoints[0].y = ybezorig + 3 * yunit; controlpoints[1].x = xbezorig - 1.7 * xunit; controlpoints[1].y = ybezorig + 4 * yunit; controlpoints[2].x = xbezorig - 1.5 * xunit; controlpoints[2].y = ybezorig + 5 * yunit; controlpoints[3].x = xbezorig - 1.1 * xunit; controlpoints[3].y = ybezorig + 6 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig - 1.1 * xunit; controlpoints[0].y = ybezorig + 6 * yunit; controlpoints[1].x = xbezorig - 1 * xunit; controlpoints[1].y = ybezorig + 7 * yunit; controlpoints[2].x = xbezorig - 0.8 * xunit; controlpoints[2].y = ybezorig + 8 * yunit; controlpoints[3].x = xbezorig - 0.3 * xunit; controlpoints[3].y = ybezorig + 9 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig - 1 * xunit; controlpoints[0].y = ybezorig + 7 * yunit; controlpoints[1].x = xbezorig - 0.8 * xunit; controlpoints[1].y = ybezorig + 8 * yunit; controlpoints[2].x = xbezorig - 0.3 * xunit; controlpoints[2].y = ybezorig + 9 * yunit; controlpoints[3].x = xbezorig; controlpoints[3].y = ybezorig + 10 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); // .:: Simbolo di continuazione a Dx ::. xbezorig = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 14 / 45; ybezorig = y_origin + h_tot / 4; xunit = l_tot * 2 / 90; yunit = h_tot / 40; controlpoints[0].x = xbezorig; controlpoints[0].y = ybezorig; controlpoints[1].x = xbezorig + 0.8 * xunit; controlpoints[1].y = ybezorig + 1 * yunit; controlpoints[2].x = xbezorig + 1.2 * xunit; controlpoints[2].y = ybezorig + 2 * yunit; controlpoints[3].x = xbezorig + 1.5 * xunit; controlpoints[3].y = ybezorig + 3 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig + 1.5 * xunit; controlpoints[0].y = ybezorig + 3 * yunit; controlpoints[1].x = xbezorig + 1.7 * xunit; controlpoints[1].y = ybezorig + 4 * yunit; controlpoints[2].x = xbezorig + 1.5 * xunit; controlpoints[2].y = ybezorig + 5 * yunit; controlpoints[3].x = xbezorig + 1.1 * xunit; controlpoints[3].y = ybezorig + 6 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig + 1.1 * xunit; controlpoints[0].y = ybezorig + 6 * yunit; controlpoints[1].x = xbezorig + 1 * xunit; controlpoints[1].y = ybezorig + 7 * yunit; controlpoints[2].x = xbezorig + 0.8 * xunit; controlpoints[2].y = ybezorig + 8 * yunit; controlpoints[3].x = xbezorig + 0.3 * xunit; controlpoints[3].y = ybezorig + 9 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig + 1 * xunit; controlpoints[0].y = ybezorig + 7 * yunit; controlpoints[1].x = xbezorig + 0.8 * xunit; controlpoints[1].y = ybezorig + 8 * yunit; controlpoints[2].x = xbezorig + 0.3 * xunit; controlpoints[2].y = ybezorig + 9 * yunit; controlpoints[3].x = xbezorig; controlpoints[3].y = ybezorig + 10 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig; controlpoints[0].y = ybezorig + 10 * yunit; controlpoints[1].x = xbezorig - 0.8 * xunit; controlpoints[1].y = ybezorig + 11 * yunit; controlpoints[2].x = xbezorig - 1.2 * xunit; controlpoints[2].y = ybezorig + 12 * yunit; controlpoints[3].x = xbezorig - 1.5 * xunit; controlpoints[3].y = ybezorig + 13 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig - 1.5 * xunit; controlpoints[0].y = ybezorig + 13 * yunit; controlpoints[1].x = xbezorig - 1.7 * xunit; controlpoints[1].y = ybezorig + 14 * yunit; controlpoints[2].x = xbezorig - 1.5 * xunit; controlpoints[2].y = ybezorig + 15 * yunit; controlpoints[3].x = xbezorig - 1.1 * xunit; controlpoints[3].y = ybezorig + 16 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig - 1.1 * xunit; controlpoints[0].y = ybezorig + 16 * yunit; controlpoints[1].x = xbezorig - 1 * xunit; controlpoints[1].y = ybezorig + 17 * yunit; controlpoints[2].x = xbezorig - 0.8 * xunit; controlpoints[2].y = ybezorig + 18 * yunit; controlpoints[3].x = xbezorig - 0.3 * xunit; controlpoints[3].y = ybezorig + 19 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig - 1 * xunit; controlpoints[0].y = ybezorig + 17 * yunit; controlpoints[1].x = xbezorig - 0.8 * xunit; controlpoints[1].y = ybezorig + 18 * yunit; controlpoints[2].x = xbezorig - 0.3 * xunit; controlpoints[2].y = ybezorig + 19 * yunit; controlpoints[3].x = xbezorig; controlpoints[3].y = ybezorig + 20 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig; controlpoints[0].y = ybezorig + 10 * yunit; controlpoints[1].x = xbezorig + 0.8 * xunit; controlpoints[1].y = ybezorig + 11 * yunit; controlpoints[2].x = xbezorig + 1.2 * xunit; controlpoints[2].y = ybezorig + 12 * yunit; controlpoints[3].x = xbezorig + 1.5 * xunit; controlpoints[3].y = ybezorig + 13 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig + 1.5 * xunit; controlpoints[0].y = ybezorig + 13 * yunit; controlpoints[1].x = xbezorig + 1.7 * xunit; controlpoints[1].y = ybezorig + 14 * yunit; controlpoints[2].x = xbezorig + 1.5 * xunit; controlpoints[2].y = ybezorig + 15 * yunit; controlpoints[3].x = xbezorig + 1.1 * xunit; controlpoints[3].y = ybezorig + 16 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig + 1.1 * xunit; controlpoints[0].y = ybezorig + 16 * yunit; controlpoints[1].x = xbezorig + 1 * xunit; controlpoints[1].y = ybezorig + 17 * yunit; controlpoints[2].x = xbezorig + 0.8 * xunit; controlpoints[2].y = ybezorig + 18 * yunit; controlpoints[3].x = xbezorig + 0.3 * xunit; controlpoints[3].y = ybezorig + 19 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); controlpoints[0].x = xbezorig + 1 * xunit; controlpoints[0].y = ybezorig + 17 * yunit; controlpoints[1].x = xbezorig + 0.8 * xunit; controlpoints[1].y = ybezorig + 18 * yunit; controlpoints[2].x = xbezorig + 0.3 * xunit; controlpoints[2].y = ybezorig + 19 * yunit; controlpoints[3].x = xbezorig; controlpoints[3].y = ybezorig + 20 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); // .:: Archi di raccordo ::. xunit = arcradius / 3; yunit = arcradius / 3; xbezorig = x_origin + l_tot * 5 / 9; ybezorig = y_origin + h_tot / 4 - arcradius; controlpoints[0].x = xbezorig; controlpoints[0].y = ybezorig; controlpoints[1].x = xbezorig + 0.5 * xunit; controlpoints[1].y = ybezorig + 1 * yunit; controlpoints[2].x = xbezorig + 1 * xunit; controlpoints[2].y = ybezorig + 2 * yunit; controlpoints[3].x = xbezorig + 3 * xunit; controlpoints[3].y = ybezorig + 3 * yunit; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); xbezorig = x_origin + l_tot * 5 / 9; ybezorig = y_origin + h_tot *3 / 4; controlpoints[0].x = xbezorig; controlpoints[0].y = ybezorig + 3 * yunit; controlpoints[1].x = xbezorig + 0.5 * xunit; controlpoints[1].y = ybezorig + 2 * yunit; controlpoints[2].x = xbezorig + 1 * xunit; controlpoints[2].y = ybezorig + 1 * yunit; controlpoints[3].x = xbezorig + 3 * xunit; controlpoints[3].y = ybezorig; iconView->StrokeBezier(controlpoints, B_SOLID_HIGH); // .:: Quota raggio raccordo ::. xbezorig = x_origin + l_tot * 5 / 9; ybezorig = y_origin + h_tot / 4 - arcradius; float pigreco; pigreco = atan(1) * 4; p1.x = xbezorig + 1.2 * xunit; p1.y = ybezorig + 1.8 * yunit; p2.x = p1.x + 2 * arcradius * cos(pigreco / 4); p2.y = p1.y - 2 * arcradius * sin(pigreco / 4); iconView->StrokeLine(p1, p2, B_SOLID_HIGH); // .:: Freccia quota raggio di raccordo ::. p2.x = p1.x + (-1 * largfreccie / 2 * cos(pigreco / 4) + largfreccie * 2 * sin(pigreco / 4)); p2.y = p1.y + (-1 * largfreccie / 2 * sin(pigreco / 4) - largfreccie * 2 * cos(pigreco / 4)); p3.x = p1.x + (largfreccie / 2 * cos(pigreco / 4) + largfreccie * 2 * sin(pigreco / 4)); p3.y = p1.y + (largfreccie / 2 * sin(pigreco / 4) - largfreccie * 2 * cos(pigreco / 4)); iconView->FillTriangle(p1, p2, p3, B_SOLID_HIGH); // .:: Testo quota raggio di raccordo ::. p2.x = p1.x + 2 * arcradius * cos(pigreco / 4); p2.y = p1.y - arcradius / 2 * sin(pigreco / 4); iconView->MovePenTo(p2); iconView->DrawString("r"); // .:: Quota forza Sx ::. p1.x = x_origin - 3 * xunit; p1.y = y_origin + h_tot / 2; p2.x = x_origin - 8 * xunit; p2.y = y_origin + h_tot / 2; iconView->StrokeLine(p1, p2, B_SOLID_HIGH); p1.x = x_origin - 8 * xunit; p1.y = y_origin + h_tot / 2; p2.x = p1.x + largfreccie * 2; p2.y = p1.y - largfreccie / 2; p3.x = p1.x + largfreccie * 2; p3.y = p1.y + largfreccie / 2; iconView->FillTriangle(p1, p2, p3, B_SOLID_HIGH); p1.x = x_origin - 11 / 2 * xunit; p1.y = y_origin + h_tot / 2 - yunit; iconView->MovePenTo(p1); iconView->DrawString("P"); // .:: Quota forza Dx ::. p1.x = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 14 / 45 + 3 * xunit; p1.y = y_origin + h_tot / 2; p2.x = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 14 / 45 + 8 * xunit; p2.y = y_origin + h_tot / 2; iconView->StrokeLine(p1, p2, B_SOLID_HIGH); p1.x = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 14 / 45 + 8 * xunit; p1.y = y_origin + h_tot / 2; p2.x = p1.x - largfreccie * 2; p2.y = p1.y - largfreccie / 2; p3.x = p1.x - largfreccie * 2; p3.y = p1.y + largfreccie / 2; iconView->FillTriangle(p1, p2, p3, B_SOLID_HIGH); p1.x = x_origin + l_tot * 5 / 9 + arcradius + l_tot * 14 / 45 + 11 / 2 * xunit; p1.y = y_origin + h_tot / 2 - yunit; iconView->MovePenTo(p1); iconView->DrawString("P"); // .:: Grafico ::. // Dimensioni della BView drawView 310 x 210 pixels BView *drawView; drawView = (BView *)FindView("drawView"); drawView->SetHighColor(0, 0, 0); p1.x = 30; p1.y = 0; p2.x = 30; p2.y = 200; drawView->StrokeLine(p1, p2, B_SOLID_HIGH); p2.x = p1.x - largfreccie / 2; p2.y = p1.y + largfreccie * 2; p3.x = p1.x + largfreccie / 2; p3.y = p1.y + largfreccie * 2; drawView->FillTriangle(p1, p2, p3, B_SOLID_HIGH); p1.x = 30; p1.y = 200; p2.x = 310; p2.y = 200; drawView->StrokeLine(p1, p2, B_SOLID_HIGH); p1.x = 310; p1.y = 200; p2.x = p1.x - largfreccie * 2; p2.y = p1.y - largfreccie / 2; p3.x = p1.x - largfreccie * 2; p3.y = p1.y + largfreccie / 2; drawView->FillTriangle(p1, p2, p3, B_SOLID_HIGH); for (int i = 280; i > 0; i = i - 50) { p1.x = i; p1.y = 198; p2.x = i; p2.y = 202; drawView->StrokeLine(p1, p2, B_SOLID_HIGH); p1.y = 210; float flxLabel; BString strxLabel; flxLabel = (i - 10) / 50 * 0.05; strxLabel << (float)flxLabel; drawView->MovePenTo(p1); drawView->DrawString(strxLabel.String()); } for (int i = 200; i > 0; i = i - 25) { p1.x = 28; p1.y = i; p2.x = 32; p2.y = i; drawView->StrokeLine(p1, p2, B_SOLID_HIGH); p1.x = 0; float flyLabel; BString stryLabel; flyLabel = (200 - i) / 25 * 0.5; stryLabel << (float)flyLabel; drawView->MovePenTo(p1); drawView->DrawString(stryLabel.String()); } p1.x = 10; p1.y = 10; drawView->MovePenTo(p1); drawView->DrawString("Kt"); p1.x = 157; p1.y = 210; drawView->MovePenTo(p1); drawView->DrawString("r/d"); }
void TouchpadView::DrawSliders() { BView* view; if (fOffScreenView != NULL) view = fOffScreenView; else view = this; if (!LockLooper()) return; if (fOffScreenBitmap->Lock()) { view->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); view->FillRect(Bounds()); view->SetHighColor(100, 100, 100); view->FillRoundRect(fPadRect, 4, 4); int32 dragSize = 3; // half drag size // scroll areas view->SetHighColor(145, 100, 100); BRect rightRect(fPadRect.left + fXScrollRange, fPadRect.top, fPadRect.right, fPadRect.bottom); view->FillRoundRect(rightRect, 4, 4); BRect bottomRect(fPadRect.left, fPadRect.top + fYScrollRange, fPadRect.right, fPadRect.bottom); view->FillRoundRect(bottomRect, 4, 4); // Stroke Rect view->SetHighColor(100, 100, 100); view->SetPenSize(2); view->StrokeRoundRect(fPadRect, 4, 4); // x scroll range line view->SetHighColor(200, 0, 0); view->StrokeLine(BPoint(fPadRect.left + fXScrollRange, fPadRect.top), BPoint(fPadRect.left + fXScrollRange, fPadRect.bottom)); fXScrollDragZone = BRect(fPadRect.left + fXScrollRange - dragSize, fPadRect.top - dragSize, fPadRect.left + fXScrollRange + dragSize, fPadRect.bottom + dragSize); fXScrollDragZone1 = BRect(fPadRect.left + fXScrollRange - dragSize, fPadRect.top - dragSize, fPadRect.left + fXScrollRange + dragSize, fPadRect.top + dragSize); view->FillRect(fXScrollDragZone1); fXScrollDragZone2 = BRect(fPadRect.left + fXScrollRange - dragSize, fPadRect.bottom - dragSize, fPadRect.left + fXScrollRange + dragSize, fPadRect.bottom + dragSize); view->FillRect(fXScrollDragZone2); // y scroll range line view->StrokeLine(BPoint(fPadRect.left, fPadRect.top + fYScrollRange), BPoint(fPadRect.right, fPadRect.top + fYScrollRange)); fYScrollDragZone = BRect(fPadRect.left - dragSize, fPadRect.top + fYScrollRange - dragSize, fPadRect.right + dragSize, fPadRect.top + fYScrollRange + dragSize); fYScrollDragZone1 = BRect(fPadRect.left - dragSize, fPadRect.top + fYScrollRange - dragSize, fPadRect.left + dragSize, fPadRect.top + fYScrollRange + dragSize); view->FillRect(fYScrollDragZone1); fYScrollDragZone2 = BRect(fPadRect.right - dragSize, fPadRect.top + fYScrollRange - dragSize, fPadRect.right + dragSize, fPadRect.top + fYScrollRange + dragSize); view->FillRect(fYScrollDragZone2); fOffScreenView->Sync(); fOffScreenBitmap->Unlock(); DrawBitmap(fOffScreenBitmap, B_ORIGIN); } UnlockLooper(); }
void ActivityView::_DrawHistory(bool drawBackground) { _UpdateOffscreenBitmap(); BView* view = this; if (fOffscreen != NULL) { fOffscreen->Lock(); view = _OffscreenView(); } BRect frame = _HistoryFrame(); BRect outerFrame = frame.InsetByCopy(-2, -2); // draw the outer frame uint32 flags = 0; if (!drawBackground) flags |= BControlLook::B_BLEND_FRAME; be_control_look->DrawTextControlBorder(this, outerFrame, outerFrame, fLegendBackgroundColor, flags); // convert to offscreen view if necessary if (view != this) frame.OffsetTo(B_ORIGIN); view->SetLowColor(fHistoryBackgroundColor); view->FillRect(frame, B_SOLID_LOW); uint32 step = 2; uint32 resolution = fDrawResolution; if (fDrawResolution > 1) { step = 1; resolution--; } uint32 width = frame.IntegerWidth() - 10; uint32 steps = width / step; bigtime_t timeStep = RefreshInterval() * resolution; bigtime_t now = system_time(); // Draw scale // TODO: add second markers? view->SetPenSize(1); rgb_color scaleColor = view->LowColor(); uint32 average = (scaleColor.red + scaleColor.green + scaleColor.blue) / 3; if (average < 96) scaleColor = tint_color(scaleColor, B_LIGHTEN_2_TINT); else scaleColor = tint_color(scaleColor, B_DARKEN_2_TINT); view->SetHighColor(scaleColor); view->StrokeLine(BPoint(frame.left, frame.top + frame.Height() / 2), BPoint(frame.right, frame.top + frame.Height() / 2)); // Draw values view->SetPenSize(1.5); BAutolock _(fSourcesLock); for (uint32 i = fSources.CountItems(); i-- > 0;) { ViewHistory* viewValues = fViewValues.ItemAt(i); DataSource* source = fSources.ItemAt(i); DataHistory* values = fValues.ItemAt(i); viewValues->Update(values, steps, fDrawResolution, now, timeStep, RefreshInterval()); uint32 x = viewValues->Start() * step; BShape shape; bool first = true; for (uint32 i = viewValues->Start(); i < steps; x += step, i++) { float y = _PositionForValue(source, values, viewValues->ValueAt(i)); if (first) { shape.MoveTo(BPoint(x, y)); first = false; } else shape.LineTo(BPoint(x, y)); } view->SetHighColor(source->Color()); view->SetLineMode(B_BUTT_CAP, B_ROUND_JOIN); view->MovePenTo(B_ORIGIN); view->StrokeShape(&shape); } // TODO: add marks when an app started or quit view->Sync(); if (fOffscreen != NULL) { fOffscreen->Unlock(); DrawBitmap(fOffscreen, outerFrame.LeftTop()); } }