void XUI_Wnd::Render(const iRect& clipper) { if (!m_bVisible) return; iRect rcWindow = GetWindowRect(); ClientToScreen( rcWindow ); // XUI_SetClipping( rcWindow.left, rcWindow.top, rcWindow.Width(), rcWindow.Height() ); //绘制自己 if( m_bOwnerDraw ) { } else { RenderSelf( clipper.TopLeft() ); if( GetFlags(FLAGS_EDIT) ) { // XUI_SetClipping( rcWindow.left-HANDLE_EDGE, rcWindow.top-HANDLE_EDGE, rcWindow.Width()+HANDLE_EDGE*2, rcWindow.Height()+HANDLE_EDGE*2 ); RenderEdit( clipper.TopLeft() ); } } //绘制子控件 for (_uint32 i=0; i<m_pChildren.size(); i++) { m_pChildren[i]->Render(rcWindow); } }
//--------------------------------------------------------// // created: 19:11:2009 18:29 // filename: d:\Develop\StarGame\GameSDK\GameUILib\Source\XUI_Wnd.cpp // author: Albert.xu // // purpose: 查找能包容整个矩形的最深Wnd //--------------------------------------------------------// bool XUI_Wnd::FindRectIn( const iRect &rc, std::list< XUI_Wnd* >& l ) { iRect rcAdjust(rc); AdjustWindow( rcAdjust, true); iRect rcWindow = GetWindowRect(); if( rcWindow.PtInRect( rc.TopLeft() ) && rcWindow.PtInRect( rc.BottomRight() ) ) { for( size_t i = 0; i < m_pChildren.size(); ++i ) { XUI_Wnd* pElement = m_pChildren[i]; iRect rcChildren = pElement->GetWindowRect(); if( rc.PtInRect( rcChildren.TopLeft() ) && rc.PtInRect( rcChildren.BottomRight() ) ) { l.push_back( pElement ); } else if( pElement->FindRectIn( rcAdjust - m_WindowPosition, l ) ) { return true; } } return true; } return false; }
void Painter::setClipRect(iRect rect){ currentTransform.apply(rect); SDL_Rect r; r.x = rect.min.x; r.y = rect.min.y; r.w = rect.getSizeX(); r.h = rect.getSizeY(); SDL_SetClipRect(drawingSurface, &r); }
bool GUIApp::ImageCache::fit(iRect _g, ViewLayerPtr _v) { // NOTE: should use a good algorithm really - http://cgi.csc.liv.ac.uk/~epa/surveyhtml.html float tolerance = 1.2f; // find a position to fit _g in our page. auto it = rows.lower_bound(_g.height()); while (true) { if (it == rows.end() || it->first > _g.height() * tolerance) { // no row exists that's good. make our own? if (int(tx.size().height() - nextfree) < _g.height()) { // no - not enough space left. if (tolerance != 1e8f) { // try restarting without tolerance tolerance = 1e8f; it = rows.lower_bound(_g.height()); continue; } else return false; } // yes - add to bottom it = rows.insert(make_pair(_g.height(), make_pair(nextfree, 0))); nextfree += _g.height(); } if (int(tx.size().width() - it->second.second) >= _g.width()) { // yey - enough space on the row. iRect tr = iRect(it->second.second, it->second.first, _g.width(), _g.height()); vs[_v].pos = tr; vs[_v].index = collated.size() / (6 * 4); fRect ftr = fRect(tr) / fSize(tx.size()); fRect gr = fRect(_g); array<float, 6 * 4> toCopy = {{ ftr.left(), ftr.top(), gr.left(), gr.top(), ftr.left(), ftr.bottom(), gr.left(), gr.bottom(), ftr.right(), ftr.top(), gr.right(), gr.top(), ftr.left(), ftr.bottom(), gr.left(), gr.bottom(), ftr.right(), ftr.top(), gr.right(), gr.top(), ftr.right(), ftr.bottom(), gr.right(), gr.bottom() }}; collated.resize(collated.size() + toCopy.size()); valcpy(&*collated.end() - toCopy.size(), toCopy.data(), toCopy.size()); it->second.second += _g.width(); return true; } ++it; } }
iSpellListView::iSpellListView(iViewMgr* pViewMgr, IViewCmdHandler* pCmdHandler, const iRect& rect, uint32 uid, iHero* pOwner, bool bShowFavorites) : iView(pViewMgr, rect, GENERIC_VIEWPORT, uid, Visible|Enabled) , m_pCmdHandler(pCmdHandler) , m_pOwner(pOwner) , m_typeMask(0), m_curSel(MSP_INVALID) { sint32 bcnt = SSM_COUNT; if (!bShowFavorites) bcnt--; sint32 btnW = iMAX<sint32>(rect.w/2,140) / bcnt; sint32 sbW = btnW*bcnt - 16; iPHScrollBar* pScrollBar = new iPHScrollBar(m_pMgr, this, iRect(sbW+1, 0, 15, rect.h-16), uid+1); AddChild(pScrollBar); m_pSpellListBox = new iSpellListBox(m_pMgr, this, iRect(0, 0, sbW, rect.h-16), uid, m_pOwner); AddChild(m_pSpellListBox); m_pSpellListBox->SetScrollBar(pScrollBar); AddChild(m_pSchoolSwitch = new iBarTabSwitch(pViewMgr, this, iRect(0, rect.h-15, btnW * bcnt, 15), bcnt, uid + 10)); for (uint32 xx=0; xx<bcnt; ++xx) m_pSchoolSwitch->SetTabIcon(SCHOOL_SWITCH_ICONS[xx]); if (m_pOwner) { if (m_pOwner->GetSpellSetMode() == SSM_FAVORITES && !bShowFavorites) m_pSchoolSwitch->SetCurrentTab(SSM_ALL); else m_pSchoolSwitch->SetCurrentTab(m_pOwner->GetSpellSetMode()); } iRect rrc(rect.size()); rrc.DeflateRect(sbW + 16 + 5, 0, 0, 0); AddChild(m_pSpellButton = new iSpellBtn(m_pMgr, this, iRect(rrc.x + (rrc.w/2 - 30), 30, 61,36), uid + 20)); }
void setBounds(const iRect &r) { position = r.min; size = r.getSize(); //surface.create(r.getSizeX(), r.getSizeY(), 1); dirty = true; }
bool SelectionBoxSprite::isVisible(const iRect &world_win) const { if ( (world_win.contains( world_pos + selection_area.min ) && (visible == true ) ) || (world_win.contains( world_pos + selection_area.max ) && (visible == true ) ) ) return( true ); return( false ); }
void UnitInterface::queryUnitsAt(std::vector<UnitID>& working_list, const iRect& rect, PlayerID player_id, unsigned char search_flags) { for(Units::iterator i = units.begin(); i != units.end(); ++i) { UnitBase* unit = i->second; if(!rect.contains(unit->unit_state.location)) continue; if(search_flags == _search_exclude_player && unit->player->getID() == player_id) continue; if(search_flags == _search_player && unit->player->getID() != player_id) continue; working_list.push_back(unit->id); } }
/// /// 区域玩家选取 /// 注意:区域指一个视野区域,而非一个Block。视野区域是多个相邻Block的集合 /// [3/3/2014 baomin] /// xObjectSet XGameMap::FetchObject( iRect rc, const std::function< xgc_bool( xObject ) > &fnFilter ) { xObjectSet objects; rc.NormalizeRect(); if( rc.top < 0 ) rc.top = 0; if( rc.bottom < 0 ) rc.bottom = 0; if( rc.left < 0 ) rc.left = 0; if( rc.right < 0 ) rc.right = 0; if( rc.bottom >= mAreaConf.cy ) rc.bottom = mAreaConf.cy - 1; if( rc.right >= mAreaConf.cx ) rc.right = mAreaConf.cx - 1; for( xgc_int32 y = rc.top; y <= rc.bottom; ++y ) { for( xgc_int32 x = rc.left; x <= rc.right; ++x ) { auto pAreaSet = GetArea( x, y ); if( xgc_nullptr == pAreaSet ) continue; for( auto it = pAreaSet->begin(); it != pAreaSet->end(); ) { XGameObject* pObj = ObjectCast<XGameObject>( *it ); XGC_ASSERT_MESSAGE( pObj, "对象被删除,但未销毁吗?(%p,%08X)", pObj, *it ); if( pObj ) { //在区域范围内 也满足过滤函数时 if( xgc_nullptr == fnFilter || ( fnFilter && fnFilter( *it ) ) ) { objects.insert( *it ); } } ++it; } } } return std::move( objects ); }
void Text::updateText() const { // Clean up current state of text m_vertices.clear(); // Offset between characters (x) and lines (y) Vec2f offset; // TODO(Smeky) Replace this by push_back in the loop as we can't support exact // number of characters because of specials symbols and underline // Resize vertices to support all characters in the string // m_vertices.resize(m_string.length() * 4); for(uint32_t i = 0; i < m_string.length(); i++) { // Store current character from the string const char current = m_string[i]; // Get font glyph corresponding to the current character const Font::Glyph glyph = m_font->getGlyph(current, m_charSize, m_bold); const iRect clip = glyph.clip; // Line breaking if(current == '\n') { offset.x = 0.0; offset.y += glyph.clip.h; continue; } else if(current == ' ') { offset.x += glyph.clip.w; continue; } Vertex v0; Vertex v1; Vertex v2; Vertex v3; // Set position of vertices v0.pos = offset; v1.pos = Vec2f(offset.x + clip.w, offset.y); v2.pos = offset + clip.size(); v3.pos = Vec2f(offset.x, offset.y + clip.h); if(m_italic) { v0.pos.x += glyph.clip.h * 0.208; v1.pos.x += glyph.clip.h * 0.208; } // Calculate normalized clip dimensions const Vec2u& texSize = m_font->getTexture(m_charSize)->getSize(); const Vec2f& cPos = Vec2f(clip.pos()) / texSize; const Vec2f& cSize = Vec2f(clip.size()) / texSize; // Set glyph's texture clip v0.texCoord = cPos; v1.texCoord = cPos + Vec2f(cSize.w, 0); v2.texCoord = cPos + cSize; v3.texCoord = cPos + Vec2f(0, cSize.h); m_vertices.push_back(v0); m_vertices.push_back(v1); m_vertices.push_back(v2); m_vertices.push_back(v3); offset.x += clip.w; } m_needUpdate = false; }
void setBounds(const iRect &r) { position = r.min; size = r.getSize(); }
static inline void worldXYtoClientXY(const iRect& view_win, const iXY& world, iXY *client ) { client->x = world.x - view_win.getLocationX(); client->y = world.y - view_win.getLocationY(); }
static inline void clientXYtoWorldXY(const iRect& view_win, const iXY& client, iXY *world) { world->x = view_win.getLocationX() + client.x; world->y = view_win.getLocationY() + client.y; }
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "2D/Palette.hpp" #include "Views/GameViewGlobals.hpp" #include "Interfaces/GameConfig.hpp" iRect MenuRect(80, 26, 640, 480-26-26); iRect bodyTextRect(MenuRect.getLocationX()+10, MenuRect.getLocationY()+10, MenuRect.getWidth()-10, MenuRect.getHeight()-80); iRect newsRect(bodyTextRect.getLocationX(), bodyTextRect.getEndY() + 10, bodyTextRect.getWidth(), MenuRect.getHeight()-90); iXY mainPos(MenuRect.getLocationX()+8, MenuRect.getLocationY()-26); iXY joinPos(mainPos.x+54, mainPos.y); iXY hostPos(joinPos.x+54, mainPos.y); iXY optionsPos(hostPos.x+54, mainPos.y); iXY helpPos(optionsPos.x+78, mainPos.y); iXY exitPos(MenuRect.getEndX() - 140, mainPos.y); iXY playPos(MenuRect.getEndX()-58, MenuRect.getEndY()); iXY returnToGamePos(mainPos); iXY resignPos(optionsPos);