void UIGauge::DrawBG(ILI9341_t3 *tft) { UIElement::DrawBG(tft); int r = GetPaddedHeight(); if (showNums) { r -= 15; } int x0 = GetPaddedX() + GetPaddedWidth()/2; int y0 = GetPaddedY() + GetPaddedHeight(); tft->drawCircleHelper(x0, y0, r, 0x1, color); tft->drawCircleHelper(x0, y0, r-1, 0x1, color); tft->drawCircleHelper(x0, y0, r, 0x2, color); tft->drawCircleHelper(x0, y0, r-1, 0x2, color); if (showNums) { tft->setTextColor(color); tft->setTextSize(1); tft->setCursor(GetPaddedX(), y0 - 10); tft->println(lower); tft->setCursor(x0 + r + 2, y0 - 10); tft->println(upper); tft->setCursor(x0, y0 - r - 10); tft->println(lower + (upper - lower) / 2); } }
void Directx::TTexture::Read(SoyPixelsImpl& DestPixels,TContext& ContextDx,TPool<TTexture>* pTexturePool) { // not readable, so copy to a temp texture first and then read // gr: use try/catch on the lock to cover more cases? if ( GetMode() != TTextureMode::ReadOnly && pTexturePool ) { auto& TexturePool = *pTexturePool; auto Meta = TTextureMeta(this->GetMeta(), TTextureMode::ReadOnly); auto Alloc = [this,&ContextDx]() { return std::make_shared<TTexture>(this->GetMeta(), ContextDx, TTextureMode::ReadOnly); }; auto& TempTexture = TexturePool.Alloc(Meta, Alloc); TempTexture.Write(*this, ContextDx); // no pool! TempTexture.Read(DestPixels, ContextDx); TexturePool.Release(TempTexture); return; } auto Lock = LockTextureData( ContextDx, false ); DestPixels.Init( Lock.mMeta ); // copy row by row to handle misalignment SoyPixelsRemote SourcePixels( reinterpret_cast<uint8*>(Lock.mData), Lock.GetPaddedWidth(), Lock.mMeta.GetHeight(), Lock.mSize, Lock.mMeta.GetFormat() ); DestPixels.Copy( SourcePixels, TSoyPixelsCopyParams(true,true,true,false,false) ); }
void Directx::TTexture::Write(const SoyPixelsImpl& SourcePixels,TContext& ContextDx) { auto Lock = LockTextureData( ContextDx, true ); // copy row by row to handle misalignment SoyPixelsRemote DestPixels( reinterpret_cast<uint8*>(Lock.mData), Lock.GetPaddedWidth(), Lock.mMeta.GetHeight(), Lock.mSize, Lock.mMeta.GetFormat() ); DestPixels.Copy( SourcePixels, TSoyPixelsCopyParams(true,true,true,false,false) ); }
void UIStatusBar::DrawFG(ILI9341_t3 *tft) { DrawBG(tft); tft->setTextColor(ILI9341_BLACK); tft->setTextSize(2); tft->setCursor(GetPaddedX(), GetPaddedY()); char buf1[20]; sprintf(buf1, "X=%3d Y=%3d", x, y); tft->println(buf1); tft->setCursor(GetPaddedX() + GetPaddedWidth()*3/4, GetPaddedY()); char buf2[10]; sprintf(buf2, "%4lums", millis() - last_time); last_time = millis(); tft->print(buf2); SetDirty(true); // Always dirty, redraw every frame }
void UIGauge::DrawFG(ILI9341_t3 *tft) { int r = GetPaddedHeight(); if (showNums) { r -= 15; } int x0 = GetPaddedX() + GetPaddedWidth()/2; int y0 = GetPaddedY() + GetPaddedHeight(); float last_val_rad = (float)(lastValue - lower) / (upper - lower) * PI; float val_rad = (float)(value - lower) / (upper - lower) * PI; if (last_val_rad < 0) { last_val_rad = 0; } else if (last_val_rad > PI) { last_val_rad = PI; } if (val_rad < 0) { val_rad = 0; } else if (val_rad > PI) { val_rad = PI; } int last_x1 = x0 - (r-5) * cos(last_val_rad); int last_y1 = y0 - (r-5) * sin(last_val_rad); tft->drawLine(x0, y0, last_x1, last_y1, fill_color); tft->drawLine(x0-1, y0, last_x1-1, last_y1, fill_color); tft->drawLine(x0+1, y0, last_x1+1, last_y1, fill_color); int x1 = x0 - (r-5) * cos(val_rad); int y1 = y0 - (r-5) * sin(val_rad); tft->drawLine(x0, y0, x1, y1, fgColor); tft->drawLine(x0-1, y0, x1-1, y1, fgColor); tft->drawLine(x0+1, y0, x1+1, y1, fgColor); SetDirty(false); }