void CTextureDx9::RenderWithoutTransform(LPD3DXSPRITE _lpDSpriteHandle, D3DXVECTOR2 position, D3DXVECTOR2 Center, D3DXVECTOR2 scale, float angle, D3DCOLOR color, RECT *srcRect, float deep) { D3DXVECTOR2 CamTransDistance; CamTransDistance.x = -Camera::getInstance()->GetMatrixTranslate()._41; CamTransDistance.y = Camera::getInstance()->GetMatrixTranslate()._42; position.y += Camera::getInstance()->getBound().bottom; Center.y += Camera::getInstance()->getBound().bottom; D3DXVECTOR3 currentPosition(position.x + CamTransDistance.x, position.y, deep); //toa do trong the gioi thuc D3DXMATRIX oldMatrix; //ma tran luu lai phep transform cua SpriteBatch _lpDSpriteHandle->GetTransform(&oldMatrix); D3DXVECTOR2 centerScale = D3DXVECTOR2(position.x, position.y);//lay vi tri cua vat the lam tam xoay(vi vi tri cua vat la vi tri chinh giua cua vat) D3DXMATRIX matrixScalingRotate; //ma tran rotate, scale D3DXMatrixTransformation2D(&matrixScalingRotate, ¢erScale, 0.0f, &scale, &Center, D3DXToRadian(angle), 0); D3DXMATRIX finalMatrix = matrixScalingRotate * oldMatrix; _lpDSpriteHandle->SetTransform(&finalMatrix); //ma tran chuyen toa do vi tri cua vat the tu the gioi thuc sang toa do trong directX de ve _lpDSpriteHandle->Draw( this->m_lpTexture, srcRect, &D3DXVECTOR3((float)(srcRect->right - srcRect->left)/2, (float)(srcRect->bottom - srcRect->top)/2, 0), ¤tPosition, color); _lpDSpriteHandle->SetTransform(&oldMatrix); }
// // -------------------------------------------------------- // Renders the edit box and the internal text. // -------------------------------------------------------- void DirectX::GUI::EditBox::render( LPD3DXSPRITE d3dsprite, const POINT* pos ) { // Compute absolute offset int xpos = m_posX + pos->x; int ypos = m_posY + pos->y; // Render edit box background sprite Matrix fieldTransform; float fieldScaleX = (float)m_sizeX / (float)(m_style->selectionBox.right - m_style->selectionBox.left); float fieldScaleY = (float)m_sizeY / (float)(m_style->selectionBox.bottom - m_style->selectionBox.top); D3DXMatrixTransformation2D( &fieldTransform, NULL, 0.0, &Vector2( fieldScaleX, fieldScaleY ), NULL, NULL, &Vector2( (float)xpos, (float)ypos ) ); // Render the properly positioned sprite d3dsprite->SetTransform( &fieldTransform ); d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->selectionBox, NULL, NULL, 0xFFFFFFFF ); // Draw button text if( m_state&FOCUSED ) m_cursorPosition = m_text.insert( m_cursorPosition, '|' ); Matrix iden; RECT textRect = { xpos, ypos, xpos+m_sizeX, ypos+m_sizeY }; D3DXMatrixIdentity( &iden ); d3dsprite->SetTransform( &iden ); m_style->font.getFont( )->DrawTextW( d3dsprite, m_text.c_str( ), -1, &textRect, m_alignment, m_style->color ); if( m_state&FOCUSED ) { std::wstring::iterator next = m_cursorPosition; next++; m_cursorPosition = m_text.erase( m_cursorPosition, next ); } }
int OpticSprite::draw(LPD3DXSPRITE sprite, double time, D3DXCOLOR colour, double offsetX, double offsetY) { if(!this->animate) { sprite->Draw(texture, NULL, NULL, NULL, colour); return 1; } if(animation.lifetime() > time) { animation.updateState(aniState, time); colour = D3DXCOLOR(aniState.red, aniState.green, aniState.blue, colour.a < aniState.alpha? colour.a : aniState.alpha); float rotation = 6.28318531f * aniState.rotation; D3DXMATRIX mat, current; D3DXVECTOR2 scaling(aniState.scale_x, aniState.scale_y); D3DXVECTOR2 position(floor(((pResolution->width * aniState.position_x) - translateCentre.x) + offsetX), floor(((pResolution->height * aniState.position_y) - translateCentre.y) + offsetY)); D3DXMatrixTransformation2D(&mat, &transformCentre, 0.0f, &scaling, &transformCentre, rotation, &position); sprite->GetTransform(¤t); mat *= current; sprite->SetTransform(&mat); HRESULT res; //Spritesheet rect calculations are slightly iffy thanks to the texture scaling (rounding errors) if(this->spritesheet) { int x = (width * currFrame) % surfaceDesc.Width; //Hacky workaround int diff = x - surfaceDesc.Width; if(abs(diff) <= 10) { x = 0; } //End of hacky workaround int y = height * currRow; RECT source; source.top = y; source.left = x; source.right = x + width; source.bottom = y + height; res = sprite->Draw(texture, &source, NULL, NULL, colour); sprite->SetTransform(¤t); if(!advanceFrame(time, x, y)) { return 0; } } else { res = sprite->Draw(texture, NULL, NULL, NULL, colour); sprite->SetTransform(¤t); } if(res != S_OK) { throw OpticSpriteException("Rendering sprite failed!"); } return 1; } return 0; }
void DrawSprite(LPD3DXSPRITE pSpriteBat,LPDIRECT3DTEXTURE9 pSpriteTex, const RECT& to,D3DCOLOR col) { int w,h; GetSpriteSize(pSpriteTex,w,h); float sx=float(to.right-to.left)/w; float sy=float(to.bottom-to.top)/h; D3DXMATRIX scale; D3DXMatrixScaling(&scale,sx,sy,1); pSpriteBat->SetTransform(&scale); pSpriteBat->Draw(pSpriteTex,NULL,NULL, &D3DXVECTOR3(to.left/sx,to.top/sy,0),col); pSpriteBat->SetTransform(&IDENTITY_MAT); // reset the matrix }
void Sprite_Transform_Draw(LPDIRECT3DTEXTURE9 image, int x, int y, int width, int height, int frame, int columns, float rotation, float scaling, D3DCOLOR color) { //create a scale vector D3DXVECTOR2 scale( scaling, scaling ); //create a translate vector D3DXVECTOR2 trans( (float)x, (float)y ); //set center by dividing width and height by two D3DXVECTOR2 center( (float)( width * scaling )/2, (float)( height * scaling )/2); //create 2D transformation matrix D3DXMATRIX mat; D3DXMatrixTransformation2D( &mat, NULL, 0, &scale, ¢er, rotation, &trans ); //tell sprite object to use the transform spriteobj->SetTransform( &mat ); //calculate frame location in source image int fx = (frame % columns) * width; int fy = (frame / columns) * height; RECT srcRect = {fx, fy, fx + width, fy + height}; //draw the sprite frame spriteobj->Draw( image, &srcRect, NULL, NULL, color ); }
void CImage::DrawSprite(LPD3DXSPRITE SpriteInterface, LPDIRECT3DTEXTURE9 TextureInterface, int PosX, int PosY, int Rotation, int Align) { if(SpriteInterface == NULL || TextureInterface == NULL) return; D3DXVECTOR3 Vec; Vec.x = (FLOAT)PosX; Vec.y = (FLOAT)PosY; Vec.z = (FLOAT)0.0f; D3DXMATRIX mat; D3DXVECTOR2 scaling(1.0f, 1.0f); D3DSURFACE_DESC desc; TextureInterface->GetLevelDesc(0, &desc); D3DXVECTOR2 spriteCentre; if(Align == 1) spriteCentre = D3DXVECTOR2((FLOAT)desc.Width / 2, (FLOAT)desc.Height / 2); else spriteCentre = D3DXVECTOR2(0, 0); D3DXVECTOR2 trans = D3DXVECTOR2(0, 0); D3DXMatrixTransformation2D(&mat, NULL, 0.0, &scaling, &spriteCentre, (FLOAT)Rotation, &trans); SpriteInterface->SetTransform(&mat); SpriteInterface->Begin(D3DXSPRITE_ALPHABLEND); SpriteInterface->Draw(TextureInterface, NULL, NULL, &Vec, 0xFFFFFFFF); SpriteInterface->End(); }
BOOL dx9vid_init() { d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface D3DCAPS9 d3dCaps; d3d->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps ); d3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ); ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev ); // Create the screen texture D3DXCreateTexture( d3ddev, 256, 256, D3DX_FILTER_NONE, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &g_screenTex); // Create the screen sprite (ignores 3d perspective) D3DXCreateSprite( d3ddev, &g_screenSprite ); // Scale our matrix to match the screen D3DXMatrixIdentity( &pTransform ); spritePos = D3DXVECTOR2( 0.f, 0.f ); rotCenter = D3DXVECTOR2( 0.f, 0.f); D3DXVECTOR2 vscale = D3DXVECTOR2( float(3.0f), float(3.0f)); D3DXMatrixTransformation2D( &pTransform, NULL, 0.0f, &vscale, &rotCenter, 0.f, &spritePos ); g_screenSprite->SetTransform(&pTransform); return TRUE; }
HRESULT Li_lstBtnSprite::fn_drawButton(LPD3DXSPRITE dxSpriteInterface) { // Build our matrix to rotate, scale and position our sprite D3DXMATRIX mat; RECT srcRect; srcRect.left = 0; srcRect.right = m_Width; switch (m_direction) { case 0: // Down { // draw the selected button in the list srcRect.top = m_Height / m_lstSize * m_curSelect; srcRect.bottom = m_Height / m_lstSize * (m_curSelect + 1); } break; default: break; } D3DXVECTOR3 translation; translation.x = m_pos.x; translation.y = m_pos.y; translation.z = 0; // out, scaling centre, scaling rotation, scaling, rotation centre, rotation, translation D3DXMatrixTransformation(&mat, NULL, NULL, NULL, NULL, NULL, &translation); dxSpriteInterface->SetTransform(&mat); return dxSpriteInterface->Draw(m_dxTexture,&srcRect,NULL,NULL,0xFFFFFFFF); }
void zz_font_d3d::draw_text_prim_offset (const zz_font_text& text_item, float offsetx, float offsety) { zz_assert(!text_item.to_texture); zz_assert(text_item.msg.get()); zz_assert(text_item.msg.size()); zz_assert(_d3d_font); if (!_d3d_font) return; zz_renderer_d3d * r = (zz_renderer_d3d *)(znzin->renderer); assert(r->is_a(ZZ_RUNTIME_TYPE(zz_renderer_d3d))); LPD3DXSPRITE sprite = r->get_sprite(); zz_assert(sprite); HRESULT hr; D3DXMATRIX saved_tm; D3DXMATRIX new_tm; zz_assert(r->sprite_began()); r->flush_sprite(); r->get_sprite_transform((float*)&saved_tm); // save tm // adjust offset new_tm = saved_tm; // assert not-zero-scale assert(saved_tm._11 != 0); assert(saved_tm._22 != 0); assert(saved_tm._33 != 0); // we does not support rotation assert(saved_tm._12 == 0); assert(saved_tm._13 == 0); assert(saved_tm._21 == 0); assert(saved_tm._23 == 0); assert(saved_tm._31 == 0); assert(saved_tm._32 == 0); new_tm._41 += offsetx * saved_tm._11; new_tm._42 += offsety * saved_tm._22; r->set_sprite_transform((float*)&new_tm); RECT rect = text_item.rect; if (FAILED(hr = _draw_text( sprite, text_item.msg.get(), -1, &rect, text_item.format, text_item.color ))) { ZZ_LOG("font_d3d: DrawText() failed\n", zz_renderer_d3d::get_hresult_string(hr)); } sprite->SetTransform(&saved_tm); // restore tm }
void CGameObject::Draw(LPD3DXSPRITE _spriteHandler,CCamera* _camera){ D3DXMATRIX Scale; D3DXMatrixIdentity(&Scale); D3DXMatrixTransformation2D(&Scale, &D3DXVECTOR2(m_pos.x, m_pos.y), 0.0f, &D3DXVECTOR2(1.f, -1.f),NULL, 0.f, NULL); D3DXMatrixMultiply(&Scale,&Scale, &_camera->Get_ViewPort()); _spriteHandler->SetTransform(&Scale); m_sprite->DrawSprite(_spriteHandler,D3DXVECTOR2(m_pos.x,m_pos.y)); }
void Sprite::Render() { if( m_isUse == false ) return; D3DXMATRIX Tmat, rotation, scale, translation[2]; float width = AVTexture2D::m_Rect.right - AVTexture2D::m_Rect.left; float height = AVTexture2D::m_Rect.bottom - AVTexture2D::m_Rect.top; //float width = m_Info.Width; //float height = m_Info.Height; static LPD3DXSPRITE sprite = AVDirector::GetDiector()->GetApplication()->GetD3DSprite(); D3DXMatrixIdentity(&rotation); D3DXMatrixIdentity(&scale); for(int i=0; i<2; i++)D3DXMatrixIdentity(&translation[i]); sprite->SetTransform( &scale ); // 한개만 해줘도 상관없음. D3DXMatrixTranslation(&translation[0], -(width * m_anchorPoint.x), -(height* m_anchorPoint.y), 0); D3DXMatrixScaling(&scale, m_scale.x, m_scale.y, 1.f); D3DXMatrixRotationZ(&rotation, m_angle); D3DXVECTOR2 vector = AVTexture2D::m_vPosition; D3DXMatrixTranslation(&translation[1], AVTexture2D::m_vPosition.x, AVTexture2D::m_vPosition.y, 0); Tmat = translation[0] * scale * rotation * translation[1]; sprite->SetTransform( &Tmat ); D3DCOLOR color = D3DCOLOR_ARGB((int)m_Color.a, (int)m_Color.r, (int)m_Color.g, (int)m_Color.b); sprite->Draw(m_Texture, &m_Rect, NULL, NULL, color); D3DXMatrixIdentity(&scale); sprite->SetTransform( &scale ); }
void Sprite::Draw(D3DMATRIX _World,InfoSprite _info,LPD3DXSPRITE _Handler) { D3DXMATRIX ma; ma = _info.getMatrixTransform()*_World; _Handler->SetTransform(&ma); _Handler->Draw(m_Image,&this->getRect(_info.getCurFrame()),NULL, &D3DXVECTOR3(0,0,_info.getDepth()),_info.getColor()); }
void Sprite::Draw(float X,float Y,int Index,LPD3DXSPRITE _Handler) { D3DXMATRIX m; D3DXMatrixIdentity(&m); _Handler->SetTransform(&m); _Handler->Draw(m_Image,&this->getRect(Index), NULL,&D3DXVECTOR3(X,Y,0),D3DCOLOR_ARGB(255,255,255,255)); }
void Sprite::Draw(LPD3DXSPRITE _Handler,D3DMATRIX _mtWorld, float _X,float _Y, int _Index,float _Depth,D3DXCOLOR _color) { D3DXMATRIX MaTrix,mtFinal; // D3DXMatrixIdentity(&mtFinal); D3DXVECTOR2 MTTran (_X,_Y); D3DXMatrixTransformation2D(&MaTrix,NULL,0,NULL,NULL,NULL,&MTTran); mtFinal = MaTrix*_mtWorld; _Handler->SetTransform(&mtFinal); _Handler->Draw(m_Image,&this->getRect(_Index),NULL, &D3DXVECTOR3(0,0,_Depth),_color); }
/** Draw a transformed sprite; does all the matrix shit for you */ void Sprite::spriteTransformDraw(LPDIRECT3DTEXTURE9 texture, LPD3DXSPRITE SpriteObj) { //Create 2D vectors for scale and translate values (indicate scale x-wise and y-wise) D3DXVECTOR2 scale(this->scalingX, this->scalingY); D3DXVECTOR2 translate(x, y); //Set center by dividing width and height by 2, take scaling into account D3DXVECTOR2 center((double)(this->width * this->scalingX)/2, (double)(this->height * this->scalingY)/2); //The 2D transformation matrix and the function that actually sets the matrix values D3DXMATRIX mat; D3DXMatrixTransformation2D( &mat, //The matrix; note pass by reference NULL, //scaling center point (not used) 0, //scaling rotation value (not used) &scale, //scaling vector ¢er, //rotation / pivot center rotation, //rotation angle in RADIANS &translate //translation vector ); //Tell sprite object to use the matrix SpriteObj->SetTransform(&mat); //calculate frame location in source image (only useful if it's a spritesheet) int fx = (this->frame % columns) * this->width; int fy = (this->frame / columns) * this->height; RECT sourceRect = {fx, fy, fx + this->width, fy + this->height}; //Draw the sprite frame; note we are not filling in pivot center or position because those are already set //by the matrix SpriteObj->Draw(texture, &sourceRect, NULL, NULL, this->color); /** More on spriteObj->Draw pSrcTexture - a pointer to the texture to be used, see textures pSrcRect - pointer to a rectangle defining the area of the texture to use or NULL for the whole texture pCenter- pointer to a 3D vector specifying the position in the sprite around which it can be rotated or NULL for top left pPosition - pointer to a 3D vector defining the screen position of the sprite. Note: in Direct3D 0,0 is the top left of the screen. Color - colour value that can be used to modulate the texture colours. A value of 0xFFFFFFFF maintains the colour from the texture. Note: you can use the D3DCOLOR_COLORVALUE macro to create a D3DCOLOR from RGB values. */ }//end spriteTransformDraw
HRESULT Li_lstBtnSprite::fn_drawButtonList(LPD3DXSPRITE dxSpriteInterface) { // Build our matrix to rotate, scale and position our sprite D3DXMATRIX mat; RECT srcRect; D3DXVECTOR3 translation; D3DCOLOR col; switch (m_direction) { case 0: // Down { // draw the list button separately for (int i = 0; i < m_lstSize; i++) { // draw the list at the different position srcRect.left = 0; srcRect.right = m_Width; srcRect.top = m_Height / m_lstSize * i; srcRect.bottom = m_Height / m_lstSize * (i + 1); translation.x = m_pos.x; translation.y = m_pos.y + m_Height / m_lstSize * (i + 1); translation.z = 0; if (i == m_curSelect) col = 0xFFFFFFFF; else col = 0x78787878; // out, scaling centre, scaling rotation, scaling, rotation centre, rotation, translation D3DXMatrixTransformation(&mat, NULL, NULL, NULL, NULL, NULL, &translation); dxSpriteInterface->SetTransform(&mat); dxSpriteInterface->Draw(m_dxTexture,&srcRect,NULL,NULL,col); } } break; default: break; } return S_OK; }
/////////////////// // Button Sprite // /////////////////// HRESULT Li_btnSprite::fn_drawButton(LPD3DXSPRITE dxSpriteInterface) { // Build our matrix to rotate, scale and position our sprite D3DXMATRIX mat; RECT srcRect; srcRect.left = 0; srcRect.right = m_Width; switch (m_btnState) { case IDLE: { srcRect.top = 0; srcRect.bottom = m_Height / 3; } break; case PUSH: { srcRect.top = m_Height / 3; srcRect.bottom = m_Height / 3 * 2; } break; case PASS: { srcRect.top = m_Height / 3 * 2; srcRect.bottom = m_Height; } break; } D3DXVECTOR3 translation; translation.x = m_pos.x; translation.y = m_pos.y; translation.z = 0; // out, scaling centre, scaling rotation, scaling, rotation centre, rotation, translation D3DXMatrixTransformation(&mat, NULL, NULL, NULL, NULL, NULL, &translation); dxSpriteInterface->SetTransform(&mat); return dxSpriteInterface->Draw(m_dxTexture,&srcRect,NULL,NULL,0xFFFFFFFF); }
bool OpticMedal::draw(LPD3DXSPRITE sprite) { double time; if(tickTimer) { time = timer.current(); } else { tickTimer = true; timer.start(); time = 0; } D3DXMATRIX aniMat, currMat; sprite->GetTransform(&currMat); D3DXMatrixIdentity(&aniMat); D3DXCOLOR colour = -1; if(this->animate) { if(this->animation.lifetime() > time) { animation.updateState(aniState, time); colour = D3DXCOLOR(aniState.red, aniState.green, aniState.blue, aniState.alpha); float rotation = 6.28318531f * aniState.rotation; D3DXVECTOR2 scaling(aniState.scale_x, aniState.scale_y); D3DXVECTOR2 position(floor(((pResolution->width * aniState.position_x) - translateCentre.x)), floor(((pResolution->height * aniState.position_y) - translateCentre.y))); D3DXMatrixTransformation2D(&aniMat, &transformCentre, 0.0f, &scaling, &transformCentre, rotation, &position); } else { return false; } } aniMat *= currMat; double offset_x = spawnOffsetX; double offset_y = spawnOffsetY; for(auto i = sliders.begin(); i != sliders.end(); ++i) { OpticAnimation& animation = std::get<0>(*i); AnimationState& state = std::get<1>(*i); double time = std::get<2>(*i).current(); animation.updateState(state, time); offset_x += this->_dimensions.first * state.position_x; offset_y += this->_dimensions.second * state.position_y; } if(_endTime > 0 && time > _endTime) { if(!_ending) { endSlideAnimation = defaultEndSlideAnimation(offset_x, offset_y); _ending = true; endTimer.start(); } endSlideAnimation.updateState(endState, endTimer.current()); offset_x = endState.position_x; offset_y = endState.position_y; } sprite->SetTransform(&aniMat); int keepDrawing = 0; /* Faster to erase all of the sprites at once rather than one by one when they've finished drawing */ for(auto i = sprites.begin(); i != sprites.end(); ++i) { keepDrawing |= i->draw(sprite, time, colour, offset_x, offset_y); } sprite->SetTransform(&currMat); return keepDrawing == 1; }
// called after clear_text_texture void zz_font_d3d::draw_text_prim (const zz_font_text& text_item) { if (!text_item.msg.get()) return; size_t length; length = text_item.msg.size(); if (length <= 0) return; // draw nothing assert(_d3d_font); if (!_d3d_font) return; zz_renderer_d3d * r = static_cast<zz_renderer_d3d*>(znzin->renderer); LPD3DXSPRITE sprite = r->get_sprite(); assert(sprite); if (!text_item.use_sprite) { // begin sprite zz_assert(!r->sprite_began()); r->begin_sprite(ZZ_SPRITE_ALPHABLEND, "draw_text_prim"); //조성현 2006 04 25 Text출력.. // we assumes that identity matrix transform is the default D3DXMATRIX mat, mat2; D3DXMatrixIdentity(&mat2); sprite->GetTransform(&mat); mat2._41 = mat._41; mat2._42 = mat._42; mat2._43 = mat._43; sprite->SetTransform(&mat2); } else { zz_assert(r->sprite_began()); } HRESULT hr; if (text_item.to_texture) { // render to texture stage r->enable_zbuffer(false); r->enable_zwrite(false); zz_rect new_rect; int width, height; width = text_item.rect.right - text_item.rect.left; height = text_item.rect.bottom - text_item.rect.top; SetRect(&new_rect, text_item.tex_rect.left, text_item.tex_rect.top, text_item.tex_rect.left + width, text_item.tex_rect.top + height); assert((text_item.tex_rect.top != 0) || (text_item.tex_rect.bottom != 0)); //ZZ_LOG("font: draw_text_prim(%s), [%d, %d]\n", text_item.msg.get(), text_item.tex_rect.top, text_item.tex_rect.top + height); //ZZ_LOG("font: draw_text_prim(%s), [%d, %d, %d, %d]\n", // text_item.msg.get(), // new_rect.left, new_rect.top, new_rect.right, new_rect.bottom); DWORD frontcolor = 0xFFFFFFFF; if (FAILED(hr = _draw_text( sprite, text_item.msg.get(), -1, &new_rect, text_item.format, frontcolor ))) { ZZ_LOG("font_d3d: DrawText() failed\n", zz_renderer_d3d::get_hresult_string(hr)); } // restore states r->enable_zbuffer(true); r->enable_zwrite(true); } else { RECT rect = text_item.rect; if (FAILED(hr = _draw_text( sprite, text_item.msg.get(), -1, &rect, text_item.format, text_item.color ))) { ZZ_LOG("font_d3d: DrawText() failed\n", zz_renderer_d3d::get_hresult_string(hr)); } } if (!text_item.use_sprite) { // end sprite r->end_sprite(); } }
// // -------------------------------------------------------- // Renders the ListBox control. // -------------------------------------------------------- void DirectX::GUI::ListBox::render( LPD3DXSPRITE d3dsprite, const POINT* pos ) { // Compute absolute offset int xpos = m_posX + pos->x; int ypos = m_posY + pos->y; // Get default sprite sizes for scaling operations float fieldSizeX = (float)(m_style->selectionBox.right - m_style->selectionBox.left); float fieldSizeY = (float)(m_style->selectionBox.bottom - m_style->selectionBox.top); int scrollbarWidth = m_style->downArrow.right - m_style->downArrow.left; // Compute backdrop sprite transform Matrix transformField; float fieldScaleX = (float)(m_sizeX-scrollbarWidth) / fieldSizeX; float fieldScaleY = (float)m_sizeY / fieldSizeX; Vector2 scaling( fieldScaleX, fieldScaleY ), position( (float)xpos, (float)ypos ); D3DXMatrixTransformation2D( &transformField, NULL, 0.0, &scaling, NULL, NULL, &position ); // Draw the selection box background d3dsprite->SetTransform( &transformField ); d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->selectionBox, NULL, NULL, 0xFFFFFFFF ); // Determine number of items in list box int nItemsToDraw = m_sizeY / m_spacing; int limit = ( m_items.size( ) < m_topItemIndex+nItemsToDraw ) ? m_items.size( ) : m_topItemIndex+nItemsToDraw; // Draw the highlights on selected items for( int i = m_topItemIndex; i < limit; i++ ) if( m_items[i].selected ) { // Compute highlight sprite transform Matrix transformBackdrop; float highlightSizeX = (float)(m_style->backdrop.right - m_style->backdrop.left); float highlightSizeY = (float)(m_style->backdrop.bottom - m_style->backdrop.top); float highlightScaleX = (float)(m_sizeX-scrollbarWidth) / highlightSizeX; float highlightScaleY = (float)m_spacing / highlightSizeY; Vector2 scaling( highlightScaleX, highlightScaleY ); Vector2 position( (float)xpos, (float)(ypos+(i-m_topItemIndex)*m_spacing) ); Matrix transform; D3DXMatrixTransformation2D( &transformBackdrop, NULL, 0.0, &scaling, NULL, NULL, &position ); // Draw the highlight sprite d3dsprite->SetTransform( &transformBackdrop ); d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->backdrop, NULL, NULL, 0xFFFFFFFF ); } // Draw text for visible list box entries Matrix matrix; D3DXMatrixIdentity( &matrix ); d3dsprite->SetTransform( &matrix ); RECT textRect; SetRect( &textRect, xpos, ypos, xpos+m_sizeX-scrollbarWidth, ypos+m_spacing ); for( int i = m_topItemIndex; i < limit; i++ ) { // Render list item string m_style->font.getFont( )->DrawTextW( d3dsprite, m_items[i].text.c_str( ), -1, &textRect, Center | VCenter, m_style->color ); // Adjust text rectangle for next element textRect.top = textRect.bottom; textRect.bottom += m_spacing; } // Compute arrow transforms Matrix transformUp, transformDw; float arrowSizeX = (float)(m_style->downArrow.right - m_style->downArrow.left); float arrowSizeY = (float)(m_style->downArrow.bottom - m_style->downArrow.top); Vector2 arrowScale( (float)scrollbarWidth / fieldSizeX, (float)scrollbarWidth / fieldSizeY ); Vector2 positionUp( (float)xpos+(float)m_sizeX-(float)scrollbarWidth, (float)ypos ); Vector2 positionDw( (float)xpos+(float)m_sizeX-(float)scrollbarWidth, (float)ypos+(float)m_sizeY-(float)scrollbarWidth ); D3DXMatrixTransformation2D( &transformUp, NULL, 0.0, &arrowScale, NULL, NULL, &positionUp ); D3DXMatrixTransformation2D( &transformDw, NULL, 0.0, &arrowScale, NULL, NULL, &positionDw ); // Render up arrow with correct sprite d3dsprite->SetTransform( &transformUp ); if( (m_state&PRESS_UP) && (m_state&HOVER_UP) ) d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->upArrowPressed, NULL, NULL, 0xFFFFFFFF ); else if( (m_state&HOVER_UP) || (m_state&PRESS_UP) ) d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->upArrowHover, NULL, NULL, 0xFFFFFFFF ); else d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->upArrow, NULL, NULL, 0xFFFFFFFF ); // Render down arrow with correct sprite d3dsprite->SetTransform( &transformDw ); if( (m_state&PRESS_DOWN) && (m_state&HOVER_DOWN) ) d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->downArrowPressed, NULL, NULL, 0xFFFFFFFF ); else if( (m_state&HOVER_DOWN) || (m_state&PRESS_DOWN) ) d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->downArrowHover, NULL, NULL, 0xFFFFFFFF ); else d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->downArrow, NULL, NULL, 0xFFFFFFFF ); // Compute scroller transform Matrix transformScroller; float scrollerSizeY = (float)(m_style->scroller.bottom - m_style->scroller.top); Vector2 scalingScroller( 1.0f, (float)(m_sizeY-2*scrollbarWidth) / (float)(scrollerSizeY) ); Vector2 positionScroller( (float)(xpos+m_sizeX-scrollbarWidth), (float)(ypos+scrollbarWidth) ); D3DXMatrixTransformation2D( &transformScroller, NULL, 0.0, &scalingScroller, NULL, NULL, &positionScroller ); // Render scroll bar backdrop d3dsprite->SetTransform( &transformScroller ); d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->scroller, NULL, NULL, 0xFFFFFFFF ); }
void Sprite::Draw(InfoSprite _info,LPD3DXSPRITE _Handler){ _Handler->SetTransform(&_info.getMatrixTransform()); _Handler->Draw(m_Image,&this->getRect(_info.getCurFrame()),NULL, &D3DXVECTOR3(0,0,_info.getDepth()),_info.getColor()); }
void TransformTexture() { D3DXMATRIX matrix; D3DXMatrixTransformation2D(&matrix, NULL, 0, NULL, NULL, 0, NULL); spriteHandler->SetTransform(&matrix); }
// // -------------------------------------------------------- // Renders the combo box control. // -------------------------------------------------------- void DirectX::GUI::ComboBox::render( LPD3DXSPRITE d3dsprite, const POINT* pos ) { Matrix transform; // Compute absolute offset int xpos = m_posX + pos->x; int ypos = m_posY + pos->y; // Combo box field dimensions float fieldSizeX = (float)(m_style->selectionBox.right - m_style->selectionBox.left); float fieldSizeY = (float)(m_style->selectionBox.bottom - m_style->selectionBox.top); // Draw the selection box background int nItems = (m_state&OPEN) ? m_items.size( ) : 1; Vector2 fieldScale( (float)(m_sizeX-m_sizeY) / fieldSizeX, (float)m_sizeY*nItems / fieldSizeY ); D3DXMatrixTransformation2D( &transform, NULL, 0.0, &fieldScale, NULL, NULL, &Vector2( (float)xpos, (float)ypos ) ); d3dsprite->SetTransform( &transform ); d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->selectionBox, NULL, NULL, 0xFFFFFFFF ); // Render backdrop if( m_state&OPEN ) { // Get index of hovered item int my = DirectX::Manager::instance( )->getMouseY( ); int hoverItem = (my - ypos) / m_sizeY; // Check for valid item index if( hoverItem >= 0 && hoverItem < m_items.size( ) ) { transform._42 = (float)ypos+hoverItem*m_sizeY; transform._22 = (float)m_sizeY / (float)fieldSizeY; d3dsprite->SetTransform( &transform ); d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->backdrop, NULL, NULL, 0xFFFFFFFF ); } } // Set transform for text rendering D3DXMatrixIdentity( &transform ); d3dsprite->SetTransform( &transform ); RECT textRect = { xpos, ypos, xpos+m_sizeX-m_sizeY, ypos+m_sizeY }; // Draw selected item text and other item text if open for( int i = 0; i < nItems; i++ ) { // Render this items assosciated text m_style->font.getFont( )->DrawTextW( d3dsprite, m_items[i].text.c_str( ), -1, &textRect, Center | VCenter, m_style->color ); // Adjust text rectangle height textRect.top = textRect.bottom; textRect.bottom += m_sizeY; } // Compute arrow sprite image and transform int buttonSize = m_style->downArrow.right - m_style->downArrow.left; float arrowScale = (float)m_sizeY / (float)buttonSize; D3DXMatrixTransformation2D( &transform, NULL, 0.0, &Vector2( arrowScale, arrowScale ), NULL, NULL, &Vector2( (float)(xpos+ m_sizeX-m_sizeY), (float)ypos ) ); LPRECT arrow; // Select arrow button sprite if( (m_state&PRESSED_ARROW) && (m_state&HOVER_ARROW) ) arrow = &m_style->downArrowPressed; else if( (m_state&HOVER_ARROW) || (m_state&PRESSED_ARROW) ) arrow = &m_style->downArrowHover; else arrow = &m_style->downArrow; // Render the arrow sprite d3dsprite->SetTransform( &transform ); d3dsprite->Draw( m_style->spriteSheet.getImage( ), arrow, NULL, NULL, 0xFFFFFFFF ); }