IC int calcSphereSector(Fvector& dir) { Fvector2 flat; // flatten flat.set (dir.x,dir.z); flat.norm (); // analyze if (_abs(flat.x)>_abs(flat.y)) { // sector 0,7,3,4 if (flat.x<0) { // sector 3,4 if (flat.y>0) return 3; else return 4; } else { // sector 0,7 if (flat.y>0) return 0; else return 7; } } else { // sector 1,2,6,5 if (flat.x<0) { // sector 2,5 if (flat.y>0) return 2; else return 5; } else { // sector 1,6 if (flat.y>0) return 1; else return 6; } } }
void CRenderTarget::u_calc_tc_noise (Fvector2& p0, Fvector2& p1) { CTexture* T = RCache.get_ActiveTexture (2); VERIFY2 (T, "Texture #3 in noise shader should be setted up"); u32 tw = iCeil(float(T->get_Width ())*param_noise_scale+EPS_S); u32 th = iCeil(float(T->get_Height ())*param_noise_scale+EPS_S); VERIFY2 (tw && th, "Noise scale can't be zero in any way"); // calculate shift from FPSes im_noise_time -= Device.fTimeDelta; if (im_noise_time<0) { im_noise_shift_w = ::Random.randI(tw?tw:1); im_noise_shift_h = ::Random.randI(th?th:1); float fps_time = 1/param_noise_fps; while (im_noise_time<0) im_noise_time += fps_time; } u32 shift_w = im_noise_shift_w; u32 shift_h = im_noise_shift_h; float start_u = (float(shift_w)+.5f)/(tw); float start_v = (float(shift_h)+.5f)/(th); u32 _w = Device.dwWidth; u32 _h = Device.dwHeight; u32 cnt_w = _w / tw; u32 cnt_h = _h / th; float end_u = start_u + float(cnt_w) + 1; float end_v = start_v + float(cnt_h) + 1; p0.set (start_u, start_v ); p1.set (end_u, end_v ); }
void CUIArtefactDetectorElite::Draw() { Fmatrix LM; GetUILocatorMatrix (LM); IUIRender::ePointType bk = UI().m_currentPointType; UI().m_currentPointType = IUIRender::pttLIT; UIRender->CacheSetXformWorld(LM); UIRender->CacheSetCullMode (IUIRender::cmNONE); CUIWindow::Draw (); //. Frect r = m_wrk_area->GetWndRect(); Fvector2 wrk_sz = m_wrk_area->GetWndSize(); Fvector2 rp; m_wrk_area->GetAbsolutePos (rp); Fmatrix M, Mc; float h,p; Device.vCameraDirection.getHP(h,p); Mc.setHPB (h,0,0); Mc.c.set (Device.vCameraPosition); M.invert (Mc); UI().ScreenFrustumLIT().CreateFromRect(Frect().set( rp.x, rp.y, wrk_sz.x, wrk_sz.y )); xr_vector<SDrawOneItem>::const_iterator it = m_items_to_draw.begin(); xr_vector<SDrawOneItem>::const_iterator it_e = m_items_to_draw.end(); for(;it!=it_e;++it) { Fvector p = (*it).pos; Fvector pt3d; M.transform_tiny (pt3d,p); float kz = wrk_sz.y / m_parent->m_fAfDetectRadius; pt3d.x *= kz; pt3d.z *= kz; pt3d.x += wrk_sz.x/2.0f; pt3d.z -= wrk_sz.y; Fvector2 pos; pos.set (pt3d.x, -pt3d.z); pos.sub (rp); if(1 /* r.in(pos)*/ ) { (*it).pStatic->SetWndPos (pos); (*it).pStatic->Draw (); } } UI().m_currentPointType = bk; }
void S2DVert::rotate_pt(const Fvector2& pivot, float cosA, float sinA, float kx) { Fvector2 t = pt; t.sub (pivot); pt.x = t.x*cosA+t.y*sinA; pt.y = t.y*cosA-t.x*sinA; pt.x *= kx; pt.add (pivot); }
u32 CLevelGraph::check_position_in_direction_slow (u32 start_vertex_id, const Fvector2 &start_position, const Fvector2 &finish_position) const { if (!valid_vertex_position(v3d(finish_position))) return (u32(-1)); u32 cur_vertex_id = start_vertex_id, prev_vertex_id = u32(-1); Fbox2 box; Fvector2 identity, start, dest, dir; identity.x = identity.y = header().cell_size()*.5f; start = start_position; dest = finish_position; dir.sub (dest,start); u32 dest_xz = vertex_position(v3d(dest)).xz(); Fvector2 temp; unpack_xz (vertex(start_vertex_id),temp.x,temp.y); float cur_sqr = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y); for (;;) { const_iterator I,E; begin (cur_vertex_id,I,E); bool found = false; for ( ; I != E; ++I) { u32 next_vertex_id = value(cur_vertex_id,I); if ((next_vertex_id == prev_vertex_id) || !valid_vertex_id(next_vertex_id)) continue; CVertex *v = vertex(next_vertex_id); unpack_xz (v,temp.x,temp.y); box.min = box.max = temp; box.grow (identity); if (box.pick_exact(start,dir)) { if (dest_xz == v->position().xz()) { return (is_accessible(next_vertex_id) ? next_vertex_id : u32(-1)); } Fvector2 temp; temp.add (box.min,box.max); temp.mul (.5f); float dist = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y); if (dist > cur_sqr) continue; if (!is_accessible(next_vertex_id)) return (u32(-1)); cur_sqr = dist; found = true; prev_vertex_id = cur_vertex_id; cur_vertex_id = next_vertex_id; break; } } if (!found) { return (u32(-1)); } } }
void CUIDragItem::Draw() { Fvector2 tmp; tmp.sub (GetWndPos(), GetUICursor().GetCursorPosition()); tmp.sub (m_pos_offset); tmp.mul (-1.0f); MoveWndDelta (tmp); inherited::Draw (); if(m_custom_draw) m_custom_draw->OnDraw(this); }
void CUIWeaponCellItem::InitAddon(CUIStatic* s, LPCSTR section, Fvector2 addon_offset, bool b_rotate) { Frect tex_rect; Fvector2 base_scale; if(Heading()) { base_scale.x = GetHeight()/(INV_GRID_WIDTHF*m_grid_size.x); base_scale.y = GetWidth()/(INV_GRID_HEIGHTF*m_grid_size.y); }else { base_scale.x = GetWidth()/(INV_GRID_WIDTHF*m_grid_size.x); base_scale.y = GetHeight()/(INV_GRID_HEIGHTF*m_grid_size.y); } Fvector2 cell_size; cell_size.x = pSettings->r_u32(section, "inv_grid_width")*INV_GRID_WIDTHF; cell_size.y = pSettings->r_u32(section, "inv_grid_height")*INV_GRID_HEIGHTF; tex_rect.x1 = pSettings->r_u32(section, "inv_grid_x")*INV_GRID_WIDTHF; tex_rect.y1 = pSettings->r_u32(section, "inv_grid_y")*INV_GRID_HEIGHTF; tex_rect.rb.add (tex_rect.lt,cell_size); cell_size.mul (base_scale); if(b_rotate) { s->SetWndSize (Fvector2().set(cell_size.y, cell_size.x) ); Fvector2 new_offset; new_offset.x = addon_offset.y*base_scale.x; new_offset.y = GetHeight() - addon_offset.x*base_scale.x - cell_size.x; addon_offset = new_offset; }else { s->SetWndSize (cell_size); addon_offset.mul (base_scale); } s->SetWndPos (addon_offset); s->SetOriginalRect (tex_rect); s->SetStretchTexture (true); s->EnableHeading (b_rotate); if(b_rotate) { s->SetHeading (GetHeading()); Fvector2 offs; offs.set (0.0f, s->GetWndSize().y); s->SetHeadingPivot (Fvector2().set(0.0f,0.0f), /*Fvector2().set(0.0f,0.0f)*/offs, true); } }
void CUIArtefactDetectorElite::Draw() { Fmatrix LM; GetUILocatorMatrix (LM); IUIRender::ePointType bk = UI()->m_currentPointType; UI()->m_currentPointType = IUIRender::pttLIT; UIRender->CacheSetXformWorld(LM); UIRender->CacheSetCullMode (IUIRender::cmNONE); CUIWindow::Draw (); Frect r = m_wrk_area->GetWndRect(); Fvector2 rp; m_wrk_area->GetAbsolutePos (rp); Fmatrix M, Mc; float h,p; Device.vCameraDirection.getHP(h,p); Mc.setHPB (h,0,0); Mc.c.set (Device.vCameraPosition); M.invert (Mc); xr_vector<Fvector>::const_iterator it = m_af_to_draw.begin(); xr_vector<Fvector>::const_iterator it_e = m_af_to_draw.end(); for(;it!=it_e;++it) { Fvector p = (*it); Fvector pt3d; M.transform_tiny (pt3d,p); // float kx = m_wrk_area->GetWndSize().x / m_parent->m_fAfDetectRadius; float kz = m_wrk_area->GetWndSize().y / m_parent->m_fAfDetectRadius; pt3d.x *= kz; pt3d.z *= kz; pt3d.x += m_wrk_area->GetWndSize().x/2.0f; pt3d.z -= m_wrk_area->GetWndSize().y; Fvector2 pos; pos.set (pt3d.x, -pt3d.z); pos.sub (rp); if( r.in(pos) ) { m_af_sign->SetWndPos (pos); m_af_sign->Draw (); } } UI()->m_currentPointType = bk; }
void CDeflector::GetRect (Fvector2 &min, Fvector2 &max) { // Calculate bounds xr_vector<UVtri>::iterator it=UVpolys.begin(); min = max = it->uv[0]; for (;it != UVpolys.end(); it++) { for (int i=0; i<3; i++) { min.min(it->uv[i]); max.max(it->uv[i]); } } }
void CUIDragItem::Draw() { Fvector2 tmp; tmp.sub (GetWndPos(), GetUICursor()->GetCursorPosition()); tmp.sub (m_pos_offset); tmp.mul (-1.0f); MoveWndDelta (tmp); UI()->PushScissor (UI()->ScreenRect(),true); inherited::Draw(); UI()->PopScissor(); }
void CUIPdaWnd::DrawUpdatedSections () { m_updatedSectionImage->Update (); m_oldSectionImage->Update (); Fvector2 tab_pos; UITabControl->GetAbsolutePos (tab_pos); Fvector2 pos; pos = m_sign_places_main[eptQuests]; pos.add(tab_pos); if(g_pda_info_state&pda_section::quests) draw_sign (m_updatedSectionImage, pos); else draw_sign (m_oldSectionImage, pos); pos = m_sign_places_main[eptMap]; pos.add(tab_pos); if(g_pda_info_state&pda_section::map) draw_sign (m_updatedSectionImage, pos); else draw_sign (m_oldSectionImage, pos); pos = m_sign_places_main[eptDiary]; pos.add(tab_pos); if(g_pda_info_state&pda_section::diary) draw_sign (m_updatedSectionImage, pos); else draw_sign (m_oldSectionImage, pos); pos = m_sign_places_main[eptContacts]; pos.add(tab_pos); if(g_pda_info_state&pda_section::contacts) draw_sign (m_updatedSectionImage, pos); else draw_sign (m_oldSectionImage, pos); pos = m_sign_places_main[eptRanking]; pos.add(tab_pos); if(g_pda_info_state&pda_section::ranking) draw_sign (m_updatedSectionImage, pos); else draw_sign (m_oldSectionImage, pos); pos = m_sign_places_main[eptActorStatistic]; pos.add(tab_pos); if(g_pda_info_state&pda_section::statistics) draw_sign (m_updatedSectionImage, pos); else draw_sign (m_oldSectionImage, pos); pos = m_sign_places_main[eptEncyclopedia]; pos.add(tab_pos); if(g_pda_info_state&pda_section::encyclopedia) draw_sign (m_updatedSectionImage, pos); else draw_sign (m_oldSectionImage, pos); }
void CUICustomItem::Render(FVF::TL*& Pointer, const Fvector2& pos, u32 color, float x1, float y1, float x2, float y2) { CTexture* T = RCache.get_ActiveTexture(0); Fvector2 ts; ts.set (float(T->get_Width()),float(T->get_Height())); if (!(uFlags&flValidRect)){ SetRect (0,0,ts.x,ts.y); } if (!(uFlags&flValidOriginalRect)){ iOriginalRect.set(0,0,ts.x,ts.y); uFlags |= flValidOriginalRect; } Fvector2 LTp,RBp; Fvector2 LTt,RBt; //координаты на экране в пикселях UI()->ClientToScreenScaled (LTp, x1,y1); LTp.add (pos); UI()->ClientToScreenScaled (RBp, x2,y2); RBp.add (pos); //текстурные координаты LTt.set ( iOriginalRect.x1/ts.x, iOriginalRect.y1/ts.y); RBt.set ( iOriginalRect.x2/ts.x, iOriginalRect.y2/ts.y); // Check mirror mode if (tmMirrorHorisontal == eMirrorMode || tmMirrorBoth == eMirrorMode) std::swap (LTt.x,RBt.x); if (tmMirrorVertical == eMirrorMode || tmMirrorBoth == eMirrorMode) std::swap (LTt.y,RBt.y); // clip poly sPoly2D S; S.resize(4); S[0].set (LTp.x-0.5f,LTp.y-0.5f, LTt.x,LTt.y); // LT S[1].set (RBp.x-0.5f,LTp.y-0.5f, RBt.x,LTt.y); // RT S[2].set (RBp.x-0.5f,RBp.y-0.5f, RBt.x,RBt.y); // RB S[3].set (LTp.x-0.5f,RBp.y-0.5f, LTt.x,RBt.y); // LB sPoly2D D; // const C2DFrustum& FF = UI()->ScreenFrustum(); sPoly2D* R = UI()->ScreenFrustum().ClipPoly(S,D); // sPoly2D* R = &S; if (R&&R->size()){ for (u32 k=0; k<R->size()-2; k++){ Pointer->set ((*R)[0+0].pt.x, (*R)[0+0].pt.y, color, (*R)[0+0].uv.x, (*R)[0+0].uv.y); Pointer++; Pointer->set ((*R)[k+1].pt.x, (*R)[k+1].pt.y, color, (*R)[k+1].uv.x, (*R)[k+1].uv.y); Pointer++; Pointer->set ((*R)[k+2].pt.x, (*R)[k+2].pt.y, color, (*R)[k+2].uv.x, (*R)[k+2].uv.y); Pointer++; } } }
void CUICursor::InitInternal() { m_static = xr_new<CUIStatic>(); m_static->InitTextureEx ("ui\\ui_ani_cursor", "hud\\cursor"); Frect rect; rect.set (0.0f,0.0f,40.0f,40.0f); m_static->SetOriginalRect (rect); Fvector2 sz; sz.set (rect.rb); if(UI()->is_16_9_mode()) sz.x /= 1.2f; m_static->SetWndSize (sz); m_static->SetStretchTexture (true); }
Fvector2 CUICustomMap::ConvertRealToLocal (const Fvector2& src)// meters->pixels (relatively own left-top pos) { Fvector2 res; if( !Heading() ){ return ConvertRealToLocalNoTransform(src); }else{ Fvector2 heading_pivot = GetStaticItem()->GetHeadingPivot(); res = ConvertRealToLocalNoTransform(src); res.sub(heading_pivot); rotation_(res.x, res.y, GetHeading(), res.x, res.y); res.add(heading_pivot); return res; }; }
void CUILevelMap::Draw() { if(MapWnd()){ for(WINDOW_LIST_it it = m_ChildWndList.begin(); m_ChildWndList.end() != it; ++it) { CMapSpot* sp = smart_cast<CMapSpot*>((*it)); if(sp&&sp->m_bScale){ Fvector2 sz = sp->m_originSize; sz.mul (MapWnd()->GlobalMap()->GetCurrentZoom()); sp->SetWndSize (sz); } } } inherited::Draw(); }
bool CEvaluatorTargetMapShown::evaluate() { if(m_storage->property(1)) return true; if(m_storage->property(2)) return true; Fvector2 pt = m_object->m_tgtCenter; pt.mul (m_object->GlobalMap()->GetCurrentZoom()); Fvector2 _p; m_object->GlobalMap()->GetAbsolutePos(_p); pt.add (_p); Frect rect = m_object->ActiveMapRect(); rect.grow (rect.width(),rect.height()); if (rect.in(pt)) { m_storage->set_property (2,true); return true; } return false; }
void CUIStaticItem::Render() { VERIFY(g_bRendering); UIRender->SetShader(*hShader); if(alpha_ref!=-1) UIRender->SetAlphaRef(alpha_ref); // convert&set pos Fvector2 bp; UI()->ClientToScreenScaled (bp,float(iPos.x),float(iPos.y)); UI()->AlignPixel(bp.x); UI()->AlignPixel(bp.y); // actual rendering Fvector2 pos; Fvector2 f_len; UI()->ClientToScreenScaled (f_len, iVisRect.x2, iVisRect.y2 ); int tile_x = fis_zero(iRem.x)?iTile.x:iTile.x+1; int tile_y = fis_zero(iRem.y)?iTile.y:iTile.y+1; if (! (tile_x>0 && tile_y>0) ) return; // render UIRender->StartPrimitive(8*tile_x*tile_y, IUIRender::ptTriList, UI()->m_currentPointType); for (int x=0; x<tile_x; ++x) { for (int y=0; y<tile_y; ++y) { pos.set (bp.x+f_len.x*x,bp.y+f_len.y*y); inherited::Render (pos,dwColor); } } Frect clip_rect = {iPos.x,iPos.y,iPos.x+iVisRect.x2*iTile.x+iRem.x,iPos.y+iVisRect.y2*iTile.y+iRem.y}; // set scissor UI()->PushScissor (clip_rect); UIRender->FlushPrimitive (); UI()->PopScissor (); if(alpha_ref!=-1) UIRender->SetAlphaRef(0); }
void CUIStaticItem::Render() { VERIFY(g_bRendering); // установить обязательно перед вызовом CustomItem::Render() !!! VERIFY(hShader); RCache.set_Shader (hShader); if(alpha_ref!=-1) CHK_DX(HW.pDevice->SetRenderState(D3DRS_ALPHAREF,alpha_ref)); // convert&set pos Fvector2 bp; UI()->ClientToScreenScaled (bp,float(iPos.x),float(iPos.y)); bp.x = (float)iFloor(bp.x); bp.y = (float)iFloor(bp.y); // actual rendering u32 vOffset; Fvector2 pos; Fvector2 f_len; UI()->ClientToScreenScaled (f_len, iVisRect.x2, iVisRect.y2 ); int tile_x = fis_zero(iRemX)?iTileX:iTileX+1; int tile_y = fis_zero(iRemY)?iTileY:iTileY+1; int x,y; if (!(tile_x&&tile_y)) return; // render FVF::TL* start_pv = (FVF::TL*)RCache.Vertex.Lock (8*tile_x*tile_y,hGeom_fan.stride(),vOffset); FVF::TL* pv = start_pv; for (x=0; x<tile_x; ++x){ for (y=0; y<tile_y; ++y){ pos.set (bp.x+f_len.x*x,bp.y+f_len.y*y); inherited::Render (pv,pos,dwColor); } } std::ptrdiff_t p_cnt = (pv-start_pv)/3; VERIFY((pv-start_pv)<=8*tile_x*tile_y); RCache.Vertex.Unlock (u32(pv-start_pv),hGeom_fan.stride()); // set scissor Frect clip_rect = {iPos.x,iPos.y,iPos.x+iVisRect.x2*iTileX+iRemX,iPos.y+iVisRect.y2*iTileY+iRemY}; UI()->PushScissor (clip_rect); // set geom RCache.set_Geometry (hGeom_fan); if (p_cnt!=0)RCache.Render (D3DPT_TRIANGLELIST,vOffset,u32(p_cnt)); if(alpha_ref!=-1) CHK_DX(HW.pDevice->SetRenderState(D3DRS_ALPHAREF,0)); UI()->PopScissor (); }
void IInputReceiver::IR_GetMousePosIndependent (Fvector2 &f) { Ivector2 p; IR_GetMousePosReal(p); f.set( 2.f*float(p.x)/float(Device.dwWidth)-1.f, 2.f*float(p.y)/float(Device.dwHeight)-1.f ); }
void draw_rect(Fvector2 LTp, Fvector2 RBp, Fvector2 LTt, Fvector2 RBt, u32 clr, Fvector2 const& ts) { UI().AlignPixel (LTp.x); UI().AlignPixel (LTp.y); LTp.add (pt_offset); UI().AlignPixel (RBp.x); UI().AlignPixel (RBp.y); RBp.add (pt_offset); LTt.div (ts); RBt.div (ts); UIRender->PushPoint(LTp.x, LTp.y, 0, clr, LTt.x, LTt.y); UIRender->PushPoint(RBp.x, RBp.y, 0, clr, RBt.x, RBt.y); UIRender->PushPoint(LTp.x, RBp.y, 0, clr, LTt.x, RBt.y); UIRender->PushPoint(LTp.x, LTp.y, 0, clr, LTt.x, LTt.y); UIRender->PushPoint(RBp.x, LTp.y, 0, clr, RBt.x, LTt.y); UIRender->PushPoint(RBp.x, RBp.y, 0, clr, RBt.x, RBt.y); }
void CRenderTarget::u_calc_tc_duality_ss (Fvector2& r0, Fvector2& r1, Fvector2& l0, Fvector2& l1) { // Calculate ordinaty TCs from blur and SS float tw = float(dwWidth); float th = float(dwHeight); if (dwHeight!=Device.dwHeight) param_blur = 1.f; Fvector2 shift,p0,p1; shift.set (.5f/tw, .5f/th); shift.mul (param_blur); p0.set (.5f/tw, .5f/th).add (shift); p1.set ((tw+.5f)/tw, (th+.5f)/th ).add (shift); // Calculate Duality TC float shift_u = param_duality_h*.5f; float shift_v = param_duality_v*.5f; r0.set(p0.x,p0.y); r1.set(p1.x-shift_u,p1.y-shift_v); l0.set(p0.x+shift_u,p0.y+shift_v); l1.set(p1.x,p1.y); }
void RearrangeTabButtons(CUITabControl* pTab, xr_vector<Fvector2>& vec_sign_places) { TABS_VECTOR * btn_vec = pTab->GetButtonsVector(); TABS_VECTOR::iterator it = btn_vec->begin(); TABS_VECTOR::iterator it_e = btn_vec->end(); vec_sign_places.clear (); vec_sign_places.resize (btn_vec->size()); Fvector2 pos; pos.set ((*it)->GetWndPos()); Fvector2 sign_sz; sign_sz.set (9.0f+3.0f, 11.0f); u32 idx = 0; float btn_text_len = 0.0f; CUIStatic* st = NULL; for(;it!=it_e;++it,++idx) { if(idx!=0) { st = xr_new<CUIStatic>(); st->SetAutoDelete(true);pTab->AttachChild(st); st->SetFont((*it)->GetFont()); st->SetTextColor (color_rgba(90,90,90,255)); st->SetText("//"); st->SetWndSize ((*it)->GetWndSize()); st->AdjustWidthToText(); st->SetWndPos (pos); pos.x += st->GetWndSize().x; } vec_sign_places[idx].set(pos); vec_sign_places[idx].y += iFloor(((*it)->GetWndSize().y - sign_sz.y)/2.0f); vec_sign_places[idx].y = (float)iFloor(vec_sign_places[idx].y); pos.x += sign_sz.x; (*it)->SetWndPos (pos); (*it)->AdjustWidthToText(); btn_text_len = (*it)->GetWndSize().x; pos.x += btn_text_len+3.0f; } }
void CUIMpTradeWnd::FillUpSubLevelButtons() { u32 root_cnt = m_store_hierarchy->CurrentLevel().ChildCount(); Fvector2 pos; pos.set (40.0f,90.0f); for(u32 i=0; i<root_cnt; ++i) { const CStoreHierarchy::item& it = m_store_hierarchy->CurrentLevel().ChildAt(i); CUITabButtonMP* btn = it.m_button; btn->m_temp_index = i; Register (btn); btn->SetWndPos (pos); pos.add (btn->GetWndSize().y); pos.y += 40.0f; pos.x = 40.0f; m_shop_wnd->AttachChild (btn); } }
void CServerList::InitHeader() { Fvector2 pos; pos.set (0,0); m_header[0].SetWidth (m_itemInfo.size.icon); pos.x += m_itemInfo.size.icon; m_header[1].SetWidth (m_itemInfo.size.server); m_header[1].SetWndPos (pos); m_header[1].SetTextST ("server name"); pos.x += m_itemInfo.size.server; m_header[2].SetWidth (m_itemInfo.size.map); m_header[2].SetWndPos (pos); m_header[2].SetTextST ("map"); pos.x += m_itemInfo.size.map; m_header[3].SetWidth (m_itemInfo.size.game); m_header[3].SetWndPos (pos); m_header[3].SetTextST ("game type"); pos.x += m_itemInfo.size.game; m_header[4].SetWidth (m_itemInfo.size.players); m_header[4].SetWndPos (pos); m_header[4].SetTextST ("players"); pos.x += m_itemInfo.size.players; m_header[5].SetWidth (m_itemInfo.size.ping); m_header[5].SetWndPos (pos); m_header[5].SetTextST ("ping"); pos.x += m_itemInfo.size.ping; m_header[6].SetWidth (m_itemInfo.size.version); m_header[6].SetWndPos (pos); m_header[6].SetTextST ("version"); for(int i=0; i<LST_COLUMN_COUNT;++i) { m_header_frames[i].SetWndPos (m_header[i].GetWndPos()); m_header_frames[i].SetWidth (m_header[i].GetWndSize().x); m_header_frames[i].Enable (true); m_header_frames[i].Show (true); m_header_frames[i].SetVisible (true); } }
float CUIGlobalMap::CalcOpenRect(const Fvector2& center_point, Frect& map_desired_rect, float tgt_zoom) { Fvector2 new_center_pt; // calculate desired rect in new zoom map_desired_rect.set (0.0f,0.0f, BoundRect().width()*tgt_zoom,BoundRect().height()*tgt_zoom); // calculate center point in new zoom (center_point is in identity global map space) new_center_pt.set (center_point.x*tgt_zoom,center_point.y*tgt_zoom); // get vis width & height Frect vis_abs_rect = m_mapWnd->ActiveMapRect(); float vis_w = vis_abs_rect.width(); float vis_h = vis_abs_rect.height(); // calculate center delta from vis rect Fvector2 delta_pos; delta_pos.set (new_center_pt.x-vis_w*0.5f,new_center_pt.y-vis_h*0.5f); // correct desired rect map_desired_rect.sub (delta_pos.x,delta_pos.y); // clamp pos by vis rect const Frect& r = map_desired_rect; Fvector2 np = r.lt; if (r.x2<vis_w) np.x += vis_w-r.x2; if (r.y2<vis_h) np.y += vis_h-r.y2; if (r.x1>0.0f) np.x = 0.0f; if (r.y1>0.0f) np.y = 0.0f; np.sub (r.lt); map_desired_rect.add (np.x,np.y); // calculate max way dist float dist = 0.f; Frect s_rect,t_rect; s_rect.div (GetWndRect(),GetCurrentZoom(),GetCurrentZoom()); t_rect.div (map_desired_rect,tgt_zoom,tgt_zoom); Fvector2 cpS,cpT; s_rect.getcenter (cpS); t_rect.getcenter (cpT); dist = cpS.distance_to(cpT); return dist; }
// try to positioning clipRect center to vNewPoint void CUICustomMap::SetActivePoint(const Fvector &vNewPoint) { Fvector2 pos; pos.set(vNewPoint.x,vNewPoint.z); Frect bound = BoundRect(); if( FALSE==bound.in(pos) )return; Fvector2 pos_on_map = ConvertRealToLocalNoTransform(pos); Frect map_abs_rect; GetAbsoluteRect(map_abs_rect); Fvector2 pos_abs; pos_abs.set(map_abs_rect.lt); pos_abs.add(pos_on_map); Frect clip_abs_rect = GetClipperRect(); Fvector2 clip_center; clip_abs_rect.getcenter(clip_center); clip_center.sub(pos_abs); MoveWndDelta (clip_center); SetHeadingPivot (pos_on_map, Fvector2().set(0,0), false); }
void CUICellItem::Update() { EnableHeading(m_pParentList->GetVerticalPlacement()); if(Heading()) { SetHeading ( 90.0f * (PI/180.0f) ); SetHeadingPivot (Fvector2().set(0.0f,0.0f), Fvector2().set(0.0f,GetWndSize().y), true); }else ResetHeadingPivot (); inherited::Update(); if ( CursorOverWindow() ) { Frect clientArea; m_pParentList->GetClientArea(clientArea); Fvector2 cp = GetUICursor().GetCursorPosition(); if(clientArea.in(cp)) GetMessageTarget()->SendMessage(this, DRAG_DROP_ITEM_FOCUSED_UPDATE, NULL); } PIItem item = (PIItem)m_pData; if ( item ) { m_has_upgrade = item->has_any_upgrades(); // Fvector2 size = GetWndSize(); // Fvector2 up_size = m_upgrade->GetWndSize(); // pos.x = size.x - up_size.x - 4.0f; Fvector2 pos; pos.set( m_upgrade_pos ); if ( ChildsCount() ) { pos.x += m_text->GetWndSize().x + 2.0f; } m_upgrade->SetWndPos( pos ); } m_upgrade->Show( m_has_upgrade ); }
bool CLevelGraph::neighbour_in_direction (const Fvector &direction, u32 start_vertex_id) const { u32 cur_vertex_id = start_vertex_id, prev_vertex_id = u32(-1); Fbox2 box; Fvector2 identity, start, dest, dir; identity.x = identity.y = header().cell_size()*.5f; start = v2d(vertex_position(start_vertex_id)); dir = v2d(direction); dir.normalize_safe (); dest = dir; dest.mul (header().cell_size()*4.f); dest.add (start); Fvector2 temp; unpack_xz (vertex(start_vertex_id),temp.x,temp.y); float cur_sqr = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y); const_iterator I,E; begin (cur_vertex_id,I,E); for ( ; I != E; ++I) { u32 next_vertex_id = value(cur_vertex_id,I); if ((next_vertex_id == prev_vertex_id) || !is_accessible(next_vertex_id)) continue; unpack_xz (vertex(next_vertex_id),temp.x,temp.y); box.min = box.max = temp; box.grow (identity); if (box.pick_exact(start,dir)) { Fvector2 temp; temp.add (box.min,box.max); temp.mul (.5f); float dist = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y); if (dist > cur_sqr) continue; return (true); } } return (false); }
void RearrangeTabButtons(CUITabControl* pTab) { TABS_VECTOR * btn_vec = pTab->GetButtonsVector(); TABS_VECTOR::iterator it = btn_vec->begin(); TABS_VECTOR::iterator it_e = btn_vec->end(); Fvector2 pos; pos.set ((*it)->GetWndPos()); float size_x; for ( ; it != it_e; ++it ) { (*it)->SetWndPos (pos); (*it)->AdjustWidthToText(); size_x = (*it)->GetWndSize().x + 30.0f; (*it)->SetWidth (size_x); pos.x += size_x - 6.0f; } pTab->SetWidth( pos.x + 5.0f ); pos.x = pTab->GetWndPos().x - pos.x; pos.y = pTab->GetWndPos().y; pTab->SetWndPos( pos ); }
//position and heading for drawing pointer to src pos bool CUICustomMap::GetPointerTo(const Fvector2& src, float item_radius, Fvector2& pos, float& heading) { Frect clip_rect_abs = GetClipperRect(); //absolute rect coords Frect map_rect_abs; GetAbsoluteRect(map_rect_abs); Frect rect; BOOL res = rect.intersection(clip_rect_abs, map_rect_abs); if(!res) return false; rect = clip_rect_abs; rect.sub(map_rect_abs.lt.x,map_rect_abs.lt.y); Fbox2 f_clip_rect_local; f_clip_rect_local.set(rect.x1, rect.y1, rect.x2, rect.y2 ); Fvector2 f_center; f_clip_rect_local.getcenter(f_center); Fvector2 f_dir, f_src; f_src.set(src.x, src.y ); f_dir.sub(f_center, f_src ); f_dir.normalize_safe(); Fvector2 f_intersect_point; res = f_clip_rect_local.Pick2(f_src,f_dir,f_intersect_point); VERIFY(res); heading = -f_dir.getH(); f_intersect_point.mad(f_intersect_point,f_dir,item_radius ); pos.set( iFloor(f_intersect_point.x), iFloor(f_intersect_point.y) ); return true; }