void __fastcall TFormMain::FormVirtualKeyboardShown(TObject *Sender, bool KeyboardVisible, const TRect &Bounds) { FKBBounds = TRectF(Bounds); FKBBounds = TRectF(ScreenToClient(FKBBounds.TopLeft()),ScreenToClient(FKBBounds.BottomRight())); UpdateKBBounds(); }
void __fastcall TFormMain::FormVirtualKeyboardHidden(TObject *Sender, bool KeyboardVisible, const TRect &Bounds) { FKBBounds = TRectF(0, 0, 0, 0); FNeedOffset = false; RestorePosition(); }
//--------------------------------------------------------------------------- void ClearCanvas(TCanvas *Canvas, TColor color) { Canvas->Stroke->Color = color; Canvas->Fill->Color = color; Canvas->FillRect( TRectF(0, 0, Canvas->Width, Canvas->Height), 0, 0, AllCorners, 0xFF); }
DGLE_RESULT DGLE_API CRender::GetScissor(bool &bEnabled, TRectF &stArea) { TRasterizerStateDesc desc; _pCoreRenderer->GetRasterizerState(desc); bEnabled = desc.bScissorEnabled; uint x, y, w, h; _pCoreRenderer->GetScissorRectangle(x, y, w, h); stArea = TRectF((float)x, (float)y, (float)w, (float)h); return S_OK; }
//--------------------------------------------------------------------------- void __fastcall TLifeForm::PaintBox1Paint(TObject *Sender, TCanvas *Canvas) { PaintBox1->Canvas->BeginScene(); PaintBox1->Canvas->Stroke->Color = TAlphaColorRec::Gray; if(FLifeBoard.Length > 0) { for(int i = 0; i < FViewSize.X; i++) { for(int j = 0; j < FViewSize.Y; j++) { if(FLifeBoard[Min(FViewOffset.X + i, FLifeBoard.High)][Min(FViewOffset.Y + j, FLifeBoard[0].High)] != 0) { PaintBox1->Canvas->Fill->Color = TAlphaColorRec::Black; PaintBox1->Canvas->FillRect(TRectF(i * 10, j * 10, i * 10 + 11, j * 10 + 11), 0, 0, TCorners(), 100); } else { PaintBox1->Canvas->Fill->Color = this->Canvas->Fill->Color; PaintBox1->Canvas->DrawRect(TRectF(i * 10, j * 10, i * 10 + 11, j * 10 + 11), 0, 0, TCorners(), 100); } } } } int Scale = 1000000; while(Scale > 10) { if((FMaxGensPerSecond * 10) < Scale) { Scale = Scale / 10; } else { break; } int Gens = MulDiv(FGensPerSecond, PaintBox1->Height, Scale); int Max = MulDiv(FMaxGensPerSecond, PaintBox1->Height, Scale); PaintBox1->Canvas->Fill->Color = TAlphaColorRec::Green; PaintBox1->Canvas->FillRect(TRectF(PaintBox1->Width - 4, PaintBox1->Height - Gens, PaintBox1->Width, PaintBox1->Height), 0,0, TCorners(), 100); PaintBox1->Canvas->Stroke->Color = TAlphaColorRec::Red; PaintBox1->Canvas->DrawLine(TPointF(PaintBox1->Width - 4, PaintBox1->Height - Max), TPointF(PaintBox1->Width, PaintBox1->Height - Max), 100); } PaintBox1->Canvas->EndScene(); }
//--------------------------------------------------------------------------- void __fastcall TLifeForm::PaintBox1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, float X, float Y) { if((!FLifeEngine->Running) && (Button == TMouseButton::mbLeft)) { int Row = Y / 10; int Column = X / 10; if((Row >= 0) && (Row <= FViewSize.Y) && (Column >= 0) && (Column <= FViewSize.X)) { FLifeBoard[FViewOffset.X + Column][FViewOffset.Y + Row] = FLifeBoard[FViewOffset.X + Column][FViewOffset.Y + Row] ^ 1; PaintBox1->InvalidateRect(TRectF(Column + 10, Row * 10, Column * 10 + 11, Row * 10 + 11)); } Label1->Text = String().sprintf(L"%d, %d", FViewSize.X + Column, FViewSize.Y + Row); } }
// --------------------------------------------------------------------------- __fastcall TMultiViewAlertPresentation::TMultiViewAlertPresentation (TCustomMultiView* AMultiView) : TMultiViewPresentation(AMultiView) { TMessageManager::DefaultManager->SubscribeToMessage (__classid(TFormReleasedMessage), &DoFormReleased); /* Detail overlay layer for catching mouse events */ FDetailOverlay = new TShadowedOverlayLayout(NULL); FDetailOverlay->Stored = false; FDetailOverlay->Mode = TCustomOverlayLayout::TOverlayMode::AllLocalArea; FDetailOverlay->EnabledShadow = MultiView->ShadowOptions->Enabled; FDetailOverlay->Color = MultiView->ShadowOptions->Color; FDetailOverlay->Opacity = 0; FDetailOverlay->Align = TAlignLayout::Contents; FDetailOverlay->Lock(); FDetailOverlay->Visible = false; FDetailOverlay->OnMouseDown = &DoMouseDown; FFrame = new TPanel(NULL); FFrame->Padding->Rect = TRectF(1, 1, 1, 1); }
void __fastcall TMainForm::DrawTextOnLayer(const int Index, const String Text) { int LayerIndex = MainDataModule->ImageList1->Destination->Items[Index]->Layers->Count - 1; if(LayerIndex >= 0) { TLayer * Layer = MainDataModule->ImageList1->Destination->Items[Index]->Layers->Items[LayerIndex]; String SourceName = Layer->Name; TSize Size; TCustomBitmapItem * Item; // Create a new source image if earlier its was not if(!MainDataModule->ImageList1->BitmapItemByName(SourceName, Item, Size)) { Size.cx = Layer->SourceRect->Rect.Width(); Size.cy = Layer->SourceRect->Rect.Height(); TCustomSourceItem * NewSource = MainDataModule->ImageList1->Source->Add(); NewSource->Name = SourceName; Item = NewSource->MultiResBitmap->ItemByScale(1, false, true); if(Item == NULL) { Item = NewSource->MultiResBitmap->Add(); } Item->Bitmap->SetSize(Size.cx, Size.cy); } // Output some text if(Item != NULL) { Item->Bitmap->Clear(TAlphaColor(0x0)); TCanvas * canvas = Item->Bitmap->Canvas; if(canvas->BeginScene()) { __try { canvas->Font->Size = 15; canvas->Fill->Color = TAlphaColor(TAlphaColorRec::Red); canvas->Fill->Kind = TBrushKind::Solid; canvas->FillText(TRectF(1, 0, Size.cx - 1, Size.cy / 2), Text, false, 1, TFillTextFlags(), TTextAlign::Center, TTextAlign::Center); } __finally { canvas->EndScene(); } }
DGLE_RESULT DGLE_API CBitmapFont::Draw2D(float fX, float fY, const char *pcTxt, const TColor4 &stColor, float fAngle, bool bVerticesColors) { uint length = strlen(pcTxt); if (length == 0) return S_FALSE; bool b_need_update; _pRender2D->NeedToUpdateBatchData(b_need_update); if (!b_need_update) { _pRender2D->Draw(_pTex, TDrawDataDesc(), CRDM_TRIANGLES, length * 6, TRectF(), (E_EFFECT2D_FLAGS)(EF_BLEND | (bVerticesColors ? EF_DEFAULT : EF_COLOR_MIX))); return S_OK; } uint width, height; GetTextDimensions(pcTxt, width, height); float quad[] = {fX, fY, fX + (float)width, fY, fX + (float)width, fY + (float)height, fX, fY + (float)height}; TMatrix4 transform; if (fAngle != 0.f) { TMatrix4 rot = MatrixIdentity(); const float s = sinf(-fAngle * (float)M_PI/180.f), c = cosf(-fAngle * (float)M_PI/180.f); rot._2D[0][0] = c; rot._2D[0][1] = -s; rot._2D[1][0] = s; rot._2D[1][1] = c; transform = MatrixTranslate(TVector3(-(fX + width / 2.f), -(fY + height / 2.f), 0.f)) * rot * MatrixTranslate(TVector3(fX + width / 2.f, fY + height / 2.f, 0.f)); float x = quad[0], y = quad[1]; quad[0] = transform._2D[0][0] * x + transform._2D[1][0] * y + transform._2D[3][0]; quad[1] = transform._2D[0][1] * x + transform._2D[1][1] * y + transform._2D[3][1]; x = quad[2]; y = quad[3]; quad[2] = transform._2D[0][0] * x + transform._2D[1][0] * y + transform._2D[3][0]; quad[3] = transform._2D[0][1] * x + transform._2D[1][1] * y + transform._2D[3][1]; x = quad[4]; y = quad[5]; quad[4] = transform._2D[0][0] * x + transform._2D[1][0] * y + transform._2D[3][0]; quad[5] = transform._2D[0][1] * x + transform._2D[1][1] * y + transform._2D[3][1]; x = quad[6]; y = quad[7]; quad[6] = transform._2D[0][0] * x + transform._2D[1][0] * y + transform._2D[3][0]; quad[7] = transform._2D[0][1] * x + transform._2D[1][1] * y + transform._2D[3][1]; } if (!_pRender2D->BBoxInScreen(quad, fAngle != 0.f)) return S_OK; float xoffset = 0.f; uint t_w, t_h; _pTex->GetDimensions(t_w, t_h); TColor4 prev_color, verts_colors[4]; _pRender2D->GetColorMix(prev_color); _pRender2D->SetColorMix(stColor); if (bVerticesColors) _pRender2D->GetVerticesColors(verts_colors[0], verts_colors[1], verts_colors[2], verts_colors[3]); uint size = length * 12 * 2; if (bVerticesColors) size = length * 24 * 2; if (_uiBufferSize < size) { _uiBufferSize = size; delete[] _pBuffer; _pBuffer = new float[_uiBufferSize]; } for (uint i = 0; i < length; ++i) { const uchar ch = static_cast<const uchar>(pcTxt[i]) - 32; const int &curb_x = _astChars[ch].x, &curb_y = _astChars[ch].y, &curb_w = _astChars[ch].w, &curb_h = _astChars[ch].h; const uint idx = i * 24; _pBuffer[idx] = fX + xoffset; _pBuffer[idx + 1] = fY; _pBuffer[idx + 2] = (float)curb_x / (float)t_w; _pBuffer[idx + 3] = (float)curb_y / (float)t_h; _pBuffer[idx + 4] = fX + xoffset + (float)curb_w * _fScale; _pBuffer[idx + 5] = fY; _pBuffer[idx + 6] = (float)(curb_x + curb_w) / (float)t_w; _pBuffer[idx + 7] = (float)curb_y / (float)t_h; _pBuffer[idx + 8] = fX + xoffset + (float)curb_w * _fScale; _pBuffer[idx + 9] = fY + (float)curb_h * _fScale; _pBuffer[idx + 10] = (float)(curb_x + curb_w) / (float)t_w; _pBuffer[idx + 11] = (float)(curb_y + curb_h) / (float)t_h; _pBuffer[idx + 12] = _pBuffer[idx]; _pBuffer[idx + 13] = _pBuffer[idx + 1]; _pBuffer[idx + 14] = _pBuffer[idx + 2]; _pBuffer[idx + 15] = _pBuffer[idx + 3]; _pBuffer[idx + 16] = _pBuffer[idx + 8]; _pBuffer[idx + 17] = _pBuffer[idx + 9]; _pBuffer[idx + 18] = _pBuffer[idx + 10]; _pBuffer[idx + 19] = _pBuffer[idx + 11]; _pBuffer[idx + 20] = fX + xoffset; _pBuffer[idx + 21] = fY + (float)curb_h * _fScale; _pBuffer[idx + 22] = (float)curb_x / (float)t_w; _pBuffer[idx + 23] = (float)(curb_y + curb_h) / (float)t_h; if (fAngle != 0.f) { float x = _pBuffer[idx], y = _pBuffer[idx + 1]; _pBuffer[idx] = transform._2D[0][0] * x + transform._2D[1][0] * y + transform._2D[3][0]; _pBuffer[idx + 1] = transform._2D[0][1] * x + transform._2D[1][1] * y + transform._2D[3][1]; x = _pBuffer[idx + 4]; y = _pBuffer[idx + 5]; _pBuffer[idx + 4] = transform._2D[0][0] * x + transform._2D[1][0] * y + transform._2D[3][0]; _pBuffer[idx + 5] = transform._2D[0][1] * x + transform._2D[1][1] * y + transform._2D[3][1]; x = _pBuffer[idx + 8]; y = _pBuffer[idx + 9]; _pBuffer[idx + 8] = transform._2D[0][0] * x + transform._2D[1][0] * y + transform._2D[3][0]; _pBuffer[idx + 9] = transform._2D[0][1] * x + transform._2D[1][1] * y + transform._2D[3][1]; x = _pBuffer[idx + 20]; y = _pBuffer[idx + 21]; _pBuffer[idx + 20] = transform._2D[0][0] * x + transform._2D[1][0] * y + transform._2D[3][0]; _pBuffer[idx + 21] = transform._2D[0][1] * x + transform._2D[1][1] * y + transform._2D[3][1]; _pBuffer[idx + 12] = _pBuffer[idx]; _pBuffer[idx + 13] = _pBuffer[idx + 1]; _pBuffer[idx + 16] = _pBuffer[idx + 8]; _pBuffer[idx + 17] = _pBuffer[idx + 9]; } if (bVerticesColors) { const uint idx = length * 24 + i * 24; memcpy(&_pBuffer[idx], verts_colors[0], 12 * sizeof(float)); memcpy(&_pBuffer[idx + 12], verts_colors[0], 4 * sizeof(float)); memcpy(&_pBuffer[idx + 16], verts_colors[2], 8 * sizeof(float)); } xoffset += (float)curb_w * _fScale; } TDrawDataDesc desc; desc.pData = (uint8 *)_pBuffer; desc.uiVertexStride = 4 * sizeof(float); desc.bVertices2D = true; desc.uiTextureVertexOffset = 2 * sizeof(float); desc.uiTextureVertexStride = desc.uiVertexStride; if (bVerticesColors) desc.uiColorOffset = length * 24 * sizeof(float); _pRender2D->Draw(_pTex, desc, CRDM_TRIANGLES, length*6, TRectF(), (E_EFFECT2D_FLAGS)(EF_BLEND | (bVerticesColors ? EF_DEFAULT : EF_COLOR_MIX))); _pRender2D->SetColorMix(prev_color); return S_OK; }
DGLE_RESULT DGLE_API Game::Render() { //pRender2D->Begin2D(); // render game objects for (auto it = ++cItemList().cbegin(); it != cItemList().cend(); ++it) if (it->GetType() == GameObject::GOT_SCORE) it->Draw(); for (auto it = ++cItemList().cbegin(); it != cItemList().cend(); ++it) if (it->GetType() == GameObject::GOT_BLACK_SCORE) it->Draw(); for (auto it = ++cItemList().cbegin(); it != cItemList().cend(); ++it) { switch (it->GetType()) { case GameObject::GOT_BIG_SCORE: case GameObject::GOT_HELP_SCORE: it->Draw(); } } cItemList().cbegin()->Draw(); for (auto const &ghost : cGhostList()) ghost.Draw(); // render wall for (BYTE i = 0; i < _cell_n; ++i) for (BYTE j = 0; j < _cell_m; ++j) if (!cell[i][j]) pRender2D->DrawRectangle(TRectF(i * _wall_width, j * _wall_width + _h_offset, _wall_width, _wall_width), WallColor, PF_FILL); // render HUD char chLevel[6 + 16], chLives[7 + 16], chStatus[10], chScore[8 + 16]; sprintf_s(chLevel, "Level %u", CurrentLevel); sprintf_s(chLives, "Lives: %u", Lives); if (CurrentLevel == 1) sprintf_s(chStatus, "New Game!"); else sprintf_s(chStatus, "Hurry up!"); sprintf_s(chScore, "Score = %u", CurrentScore); uint Level_w, Level_h, Lives_w, Lives_h, Status_w, Status_h, Score_w, Score_h; pFont->GetTextDimensions(chLevel, Level_w, Level_h); pFont->GetTextDimensions(chLives, Lives_w, Lives_h); pFont->GetTextDimensions(chStatus, Status_w, Status_h); pFont->GetTextDimensions(chScore, Score_w, Score_h); pFont->Draw2DSimple((SCREEN_WIDTH - Level_w) / 8, Level_h * 3 / 4, chLevel, ColorDarkGreen()); pFont->Draw2DSimple((SCREEN_WIDTH - Lives_w) * 3 / 8, Lives_h * 3 / 4, chLives, ColorRed()); if (CurrentLevel == 1 && Lives == 3 || IsBlackFlagSet()) pFont->Draw2DSimple((SCREEN_WIDTH - Status_w) * 5 / 8, Status_h * 3 / 4, chStatus, ColorRed()); pFont->Draw2DSimple((SCREEN_WIDTH - Score_w) * 7 / 8, Score_h * 3 / 4, chScore, ColorBlue()); //pRender2D->End2D(); return S_OK; }
HRESULT CALLBACK CTexture::Draw2D(int iX, int iY, uint uiWidth, uint uiHeight, float fAngle, uint uiFrameIndex) { if (_uiFrameWidth + _uiFrameHeight + uiFrameIndex == 0) { _pRender2D->DrawTexture((ITexture*)this, TPoint2((float)iX, (float)iY), TPoint2((float)uiWidth, (float)uiHeight), TRectF(0.f, 0.f, (float)_uiWidth, (float)_uiHeight), fAngle, EF_BLEND); return S_OK; } else return _pRender2D->DrawSpriteA((ITexture*)this, TPoint2((float)iX, (float)iY), TPoint2((float)uiWidth, (float)uiHeight), uiFrameIndex, fAngle, EF_BLEND); }