void nuiDecoration::GlobalToClientRect(nuiRect& rRect, const nuiWidget* pWidget) const { nuiRect clientRect = GetIdealClientRect(pWidget); // nuiSize bordertop = GetBorder(nuiTop, pWidget); // nuiSize borderleft = GetBorder(nuiLeft, pWidget); nuiSize borderright = GetBorder(nuiRight, pWidget); nuiSize borderbottom = GetBorder(nuiBottom, pWidget); float X1 = (float)clientRect.Left(); float X2 = (float)clientRect.Right(); float X3 = (float)clientRect.Right()+borderright; float Y1 = (float)clientRect.Top(); float Y2 = (float)clientRect.Bottom(); float Y3 = (float)clientRect.Bottom()+borderbottom; const float x0 = (float)rRect.Left(); const float x1 = x0 + X1; const float x3 = (float)rRect.Right(); const float x2 = x3 - (X3 - X2); const float y0 = (float)rRect.Top(); const float y1 = y0 + Y1; const float y3 = (float)rRect.Bottom(); const float y2 = y3 - (Y3 - Y2); rRect.Set(x1, y1, x2, y2, false); }
bool Widget::IsCollide(int x,int y,Direction dir) { //用拷贝的临时方块做判断 int temp_block[4][4]; block_cpy(temp_block,cur_block); Border temp_border; GetBorder(temp_block,temp_border); //先尝试按照某方向走一格 switch(dir) { case UP: BlockRotate(temp_block); GetBorder(temp_block,temp_border); //旋转后要重新计算边界 break; case DOWN: y+=1; break; case LEFT: x-=1; break; case RIGHT: x+=1; break; default: break; } for(int i=temp_border.ubound;i<=temp_border.dbound;i++) for(int j=temp_border.lbound;j<=temp_border.rbound;j++) if(game_area[y+i][x+j]==2&&temp_block[i][j]==1||x+temp_border.lbound<0||x+temp_border.rbound>AREA_COL-1) return true; return false; }
bool wxGenericCollapsiblePane::Create(wxWindow *parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxValidator& val, const wxString& name) { if ( !wxControl::Create(parent, id, pos, size, style, val, name) ) return false; m_strLabel = label; #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) // on Mac we use the disclosure triangle // we need a light gray line above and below, lets approximate with the frame m_pStaticLine = NULL; m_pButton = new wxDisclosureTriangle( this, wxID_ANY, GetBtnLabel(), wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER ); m_pButton->SetBackgroundColour( wxColour( 221, 226, 239 ) ); m_sz = new wxBoxSizer(wxHORIZONTAL); // m_sz->Add(4,4); where shall we put it? m_sz->Add( m_pButton, 1); #else // create children and lay them out using a wxBoxSizer // (so that we automatically get RTL features) m_pButton = new wxButton(this, wxID_ANY, GetBtnLabel(), wxPoint(0, 0), wxDefaultSize, wxBU_EXACTFIT); m_pStaticLine = new wxStaticLine(this, wxID_ANY); // on other platforms we put the static line and the button horizontally m_sz = new wxBoxSizer(wxHORIZONTAL); m_sz->Add(m_pButton, 0, wxLEFT|wxTOP|wxBOTTOM, GetBorder()); m_sz->Add(m_pStaticLine, 1, wxALIGN_CENTER|wxLEFT|wxRIGHT, GetBorder()); #endif // FIXME: at least under wxCE and wxGTK1 the background is black if we don't do // this, no idea why... #if defined(__WXWINCE__) || defined(__WXGTK__) SetBackgroundColour(parent->GetBackgroundColour()); #endif // do not set sz as our sizers since we handle the pane window without using sizers m_pPane = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxNO_BORDER, wxT("wxCollapsiblePanePane") ); // start as collapsed: m_pPane->Hide(); return true; }
void WebListBox::ResizeScrollBars(void) { if (mpHScroll) { WebRect r; r.Set(GetMargin() + GetBorder(), Height() - GetMargin() - GetBorder() - miSliderWidth - 1, Width() - (mpVScroll ? miSliderWidth : 0) - GetMargin() - GetBorder() - 1, Height() - GetMargin() - GetBorder() - 1); mpHScroll->Move(&r); WebRect vr; GetOptionsRect(&vr); mpHScroll->SetWindow(vr.Width()); mpHScroll->Invalidate(); } if (mpVScroll) { WebRect r; r.Set(Width() - 1 - GetMargin() - GetBorder() - miSliderWidth, GetMargin() + GetBorder(), Width() - 1 - GetMargin() - GetBorder(), Height() - 1 - (mpHScroll ? miSliderWidth : 0) - GetMargin() - GetBorder()); mpVScroll->Move(&r); WebRect vr; GetOptionsRect(&vr); mpVScroll->SetWindow(vr.Height()); mpVScroll->Invalidate(); } }
void nuiDecoration::ClientToGlobalRect(nuiRect& rRect, const nuiWidget* pWidget) const { nuiSize bordertop = GetBorder(nuiTop, pWidget); nuiSize borderleft = GetBorder(nuiLeft, pWidget); nuiSize borderright = GetBorder(nuiRight, pWidget); nuiSize borderbottom = GetBorder(nuiBottom, pWidget); rRect.Set(rRect.Left() - borderleft, rRect.Top() - bordertop, rRect.Right() + borderright, rRect.Bottom() + borderbottom, false); }
inline bool MtgCard::operator==(const MtgCard& rhs) { return GetLayout() == rhs.GetLayout() && GetManacost() == rhs.GetManacost() && GetCmc() == rhs.GetCmc() && CompareStringList(GetColors(), rhs.GetColors()) && type == rhs.type && CompareStringList(GetSupertypes(), rhs.GetSupertypes()) && CompareStringList(GetTypes(), rhs.GetTypes()) && CompareStringList(GetSubtypes(), rhs.GetSubtypes()) && GetRarity() == rhs.GetRarity() && text == rhs.GetText() && GetFlavor() == rhs.GetFlavor() && GetArtist() == rhs.GetArtist() && GetNumber() == rhs.GetNumber() && GetPower() == rhs.GetPower() && GetToughness() == rhs.GetToughness() && GetLoyalty() == rhs.GetLoyalty() && GetMultiverseid() == rhs.GetMultiverseid() && CompareIntList(GetVariations(), rhs.GetVariations()) && GetImageName() == rhs.GetImageName() && GetWatermark() == rhs.GetWatermark() && GetBorder() == rhs.GetBorder() && IsTimeshifted() == rhs.IsTimeshifted() && GetHand() == rhs.GetHand() && GetLife() == rhs.GetLife() && IsReserved() == rhs.IsReserved() && GetReleasedate() == rhs.GetReleasedate() && IsStarter() == rhs.IsStarter() && CompareStringPairList(GetRulings(), rhs.GetRulings()) && CompareStringPairList(GetForeignNames(), rhs.GetForeignNames()) && GetOriginalText() == rhs.GetOriginalText() && GetOriginalType() == rhs.GetOriginalType() && CompareStringPairList(GetLegalities(), rhs.GetLegalities()) && GetEdition() == rhs.GetEdition(); }
// the event handler executed when the window background must be painted void wxWindow::OnErase(wxEraseEvent& event) { if ( !m_renderer ) { event.Skip(); return; } DoDrawBackground(*event.GetDC()); #if wxUSE_SCROLLBAR // if we have both scrollbars, we also have a square in the corner between // them which we must paint if ( m_scrollbarVert && m_scrollbarHorz ) { wxSize size = GetSize(); wxRect rectClient = GetClientRect(), rectBorder = m_renderer->GetBorderDimensions(GetBorder()); wxRect rectCorner; rectCorner.x = rectClient.GetRight() + 1; rectCorner.y = rectClient.GetBottom() + 1; rectCorner.SetRight(size.x - rectBorder.width); rectCorner.SetBottom(size.y - rectBorder.height); if ( GetUpdateRegion().Contains(rectCorner) ) { m_renderer->DrawScrollCorner(*event.GetDC(), rectCorner); } } #endif // wxUSE_SCROLLBAR }
bool wxGenericCollapsiblePane::Layout() { #ifdef __WXMAC__ if (!m_pButton || !m_pPane || !m_sz) return false; // we need to complete the creation first! #else if (!m_pButton || !m_pStaticLine || !m_pPane || !m_sz) return false; // we need to complete the creation first! #endif wxSize oursz(GetSize()); // move & resize the button and the static line m_sz->SetDimension(0, 0, oursz.GetWidth(), m_sz->GetMinSize().GetHeight()); m_sz->Layout(); if ( IsExpanded() ) { // move & resize the container window int yoffset = m_sz->GetSize().GetHeight() + GetBorder(); m_pPane->SetSize(0, yoffset, oursz.x, oursz.y - yoffset); // this is very important to make the pane window layout show correctly m_pPane->Layout(); } return true; }
void wxWindow::DoSetClientSize(int width, int height) { // take into account the borders wxRect rectBorder = m_renderer->GetBorderDimensions(GetBorder()); width += rectBorder.x; height += rectBorder.y; // and the scrollbars (as they may be offset into the border, use the // scrollbar position, not size - this supposes that PositionScrollbars() // had been called before) wxSize size = GetSize(); #if wxUSE_SCROLLBAR if ( m_scrollbarVert ) width += size.x - m_scrollbarVert->GetPosition().x; #endif // wxUSE_SCROLLBAR width += rectBorder.width; #if wxUSE_SCROLLBAR if ( m_scrollbarHorz ) height += size.y - m_scrollbarHorz->GetPosition().y; #endif // wxUSE_SCROLLBAR height += rectBorder.height; wxWindowNative::DoSetClientSize(width, height); }
BOOL CRIFFChunkTreeDlg::OnInitDialog() { // InitializeCriticalSection(&critical_section); CResizeableDialog::OnInitDialog(); InitializeCriticalSection(&cs); bChunkTree_stop = false; // __int64 qwPos; // LISTHEADER lh; SendDlgItemMessage(IDOK,WM_SETTEXT,NULL,(LPARAM)LoadString(STR_GEN_OK)); SendDlgItemMessage(IDCANCEL,WM_SETTEXT,NULL,(LPARAM)LoadString(STR_GEN_CANCEL)); SendDlgItemMessage(IDC_WAIT_FOR_COMPLETE_TREE, WM_SETTEXT, NULL, (LPARAM)LoadString(STR_RIFFDLG_FULL)); DWORD dwID; MAIN_THREAD_DATA_STRUCT* mtds = new MAIN_THREAD_DATA_STRUCT; mtds->dlg = this; mtds->source = source; CreateThread(NULL, 1<<20, MainThread, mtds, NULL, &dwID); AttachWindow(*GetDlgItem(IDOK), ATTB_RIGHT, *this, -12); AttachWindow(*GetDlgItem(IDC_SAVE), ATTB_RIGHT, *GetDlgItem(IDOK)); AttachWindow(*GetDlgItem(IDC_SAVE), ATTB_TOP, *GetDlgItem(IDOK), ATTB_BOTTOM, 2); AttachWindow(m_WaitButton, ATTB_TOP, *GetDlgItem(IDC_SAVE), ATTB_BOTTOM, 2); AttachWindow(m_WaitButton, ATTB_RIGHT, *GetDlgItem(IDOK)); int border_x, border_y; GetBorder(border_x, border_y); AttachWindow(m_HexView, ATTB_BOTTOM, *this, -border_y); AttachWindow(m_Tree, ATTB_LEFT, *this, 12); AttachWindow(m_Tree, ATTB_BOTTOM, m_HexView, ATTB_TOP, -1); AttachWindow(m_Tree, ATTB_TOP, *this, border_y + 12); AttachWindow(m_Tree, ATTB_RIGHT, *GetDlgItem(IDOK), ATTB_LEFT, -12); AttachWindow(m_HexView, ATTB_RIGHT, m_Tree); AttachWindow(m_HexView, ATTB_LEFT, m_Tree); AttachWindow(*GetDlgItem(IDOK), ATTB_TOP, m_Tree); m_HexView.SetRange(16*256); m_HexView.SetDataSource(source); m_HexView.SetNewStartPos(0); m_HexView.SetMode(HWLB_MODE_RIFF); /* RECT r; GetWindowRect(&r); PostMessage(WM_SIZE, 0, (r.right-r.left) | ((r.bottom-r.top)<<16)); */ return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurückgeben }
void MakeFBUmask(IplImage *maskrgb, IplImage *&res, int unknownsize) { vector<CvPoint> borders; GetBorder(maskrgb, borders); if (res) cvReleaseImage(&res); res = cvCloneImage(maskrgb); for (int i = 0; i < (int)borders.size(); i++) if (borders[i].x != -1 && borders[i].y != -1) circleit(res, borders[i].x, borders[i].y, unknownsize, C_UNKNOW); }
void GUIControl::Draw() { if(IsVisible()) { if(GetTexture()) { COLOR4 c = GetColor(); glColor4ub(c.r, c.g, c.b, c.a); if(GetCurrentPattern() == 0) { DrawTexture(GetX(), GetY(), 0, 0, GetWidth(), GetHeight(), GetTexture(), false, false, 100, 100); } else { DrawTexture(GetX(), GetY(), GetCurrentPattern() * GetWidth(), 0, GetCurrentPattern() * GetWidth() + GetWidth(), GetHeight(), GetTexture(), false, false, 100, 100); } } if(GetCaption() && GetCaptionFont()) { COLOR4 c = GetCurrentCaptionColor(); glColor4ub(c.r, c.g, c.b, c.a); PrintText(GetCaption(), GetCaptionFont(), GetX() + GetCaptionX(), GetY() + GetCaptionY()); } if(GetBorder()) { if(GetBorderType() == btAlways) { Box(GetX(), GetY(), GetWidth(), GetHeight()); } else if(GetBorderType() == btOnMouseMove) { if(_draw_border) Box(GetX(), GetY(), GetWidth(), GetHeight()); } } } }
void wxWindow::DoDrawBorder(wxDC& dc, const wxRect& rect) { // draw outline unless the update region is enitrely inside it in which // case we don't need to do it #if 0 // doesn't seem to work, why? if ( wxRegion(rect).Contains(GetUpdateRegion().GetBox()) != wxInRegion ) #endif { m_renderer->DrawBorder(dc, GetBorder(), rect, GetStateFlags()); } }
wxPoint wxWindow::GetClientAreaOrigin() const { wxPoint pt = wxWindowBase::GetClientAreaOrigin(); #if wxUSE_TWO_WINDOWS #else if ( m_renderer ) pt += m_renderer->GetBorderDimensions(GetBorder()).GetPosition(); #endif return pt; }
void Border::CreateBorder() { const int CONST_SQUARE_SIDE = 12, CONST_NUM_SQUARES = Game::GetFieldWidth()/CONST_SQUARE_SIDE, CONST_POSITION_EXTENSION = 24;// see Game CONST_TOP_BAR_L variable for(int i = 0; i < (CONST_NUM_SQUARES - 1); i++) { //top sf::RectangleShape borderSquare(sf::Vector2f(11.0, 11.0)); borderSquare.setFillColor(sf::Color(102, 0, 0));//this is the brown color borderSquare.setOrigin(borderSquare.getLocalBounds().left - 1.0, borderSquare.getLocalBounds().top - 1.0); borderSquare.setPosition(i * 12, CONST_POSITION_EXTENSION); GetBorder().push_back(borderSquare); //right side sf::RectangleShape borderSquare_2(sf::Vector2f(11.0, 11.0)); borderSquare_2.setFillColor(sf::Color(102, 0, 0));//this is the brown color borderSquare_2.setOrigin(borderSquare_2.getLocalBounds().left - 1.0, borderSquare_2.getLocalBounds().top - 1.0); borderSquare_2.setPosition((CONST_NUM_SQUARES - 1) * CONST_SQUARE_SIDE, i * CONST_SQUARE_SIDE + CONST_POSITION_EXTENSION); GetBorder().push_back(borderSquare_2); //bottom sf::RectangleShape borderSquare_3(sf::Vector2f(11.0, 11.0)); borderSquare_3.setFillColor(sf::Color(102, 0, 0));//this is the brown color borderSquare_3.setOrigin(borderSquare_3.getLocalBounds().left - 1.0, borderSquare_3.getLocalBounds().top - 1.0); borderSquare_3.setPosition( (i + 1) * CONST_SQUARE_SIDE, (CONST_NUM_SQUARES - 1) * CONST_SQUARE_SIDE + CONST_POSITION_EXTENSION); GetBorder().push_back(borderSquare_3); //left side sf::RectangleShape borderSquare_4(sf::Vector2f(11.0, 11.0)); borderSquare_4.setFillColor(sf::Color(102, 0, 0));//this is the brown color borderSquare_4.setOrigin(borderSquare_4.getLocalBounds().left - 1.0, borderSquare_4.getLocalBounds().top - 1.0); borderSquare_4.setPosition(0.0, (i + 1) * CONST_SQUARE_SIDE + CONST_POSITION_EXTENSION); GetBorder().push_back(borderSquare_4); } }
wxSize wxStaticText::DoGetBestSize() const { wxClientDC dc(const_cast<wxStaticText *>(this)); wxFont font(GetFont()); if (!font.Ok()) font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); dc.SetFont(font); wxCoord widthTextMax, heightTextTotal; dc.GetMultiLineTextExtent(GetLabelText(), &widthTextMax, &heightTextTotal); #ifdef __WXWINCE__ if ( widthTextMax ) widthTextMax += 2; #endif // __WXWINCE__ // border takes extra space // // TODO: this is probably not wxStaticText-specific and should be moved wxCoord border; switch ( GetBorder() ) { case wxBORDER_STATIC: case wxBORDER_SIMPLE: border = 1; break; case wxBORDER_SUNKEN: border = 2; break; case wxBORDER_RAISED: case wxBORDER_DOUBLE: border = 3; break; default: wxFAIL_MSG( _T("unknown border style") ); // fall through case wxBORDER_NONE: border = 0; } widthTextMax += 2*border; heightTextTotal += 2*border; wxSize best(widthTextMax, heightTextTotal); CacheBestSize(best); return best; }
FVector2D SButton::ComputeDesiredSize(float LayoutScaleMultiplier) const { // When there is no widget in the button, it sizes itself based on // the border image specified by the style. if (ChildSlot.GetWidget() == SNullWidget::NullWidget) { return GetBorder()->ImageSize; } else { return SBorder::ComputeDesiredSize(LayoutScaleMultiplier); } }
void wxWindow::DoGetClientSize(int *width, int *height) const { // if it is a native window, we assume it handles the scrollbars itself // too - and if it doesn't, there is not much we can do if ( !m_renderer ) { wxWindowNative::DoGetClientSize(width, height); return; } int w, h; wxWindowNative::DoGetClientSize(&w, &h); // we assume that the scrollbars are positioned correctly (by a previous // call to PositionScrollbars()) here wxRect rectBorder; if ( m_renderer ) rectBorder = m_renderer->GetBorderDimensions(GetBorder()); if ( width ) { #if wxUSE_SCROLLBAR // in any case, take account of the scrollbar if ( m_scrollbarVert ) w -= m_scrollbarVert->GetSize().x; #endif // wxUSE_SCROLLBAR // account for the left and right borders *width = w - rectBorder.x - rectBorder.width; // we shouldn't return invalid width if ( *width < 0 ) *width = 0; } if ( height ) { #if wxUSE_SCROLLBAR if ( m_scrollbarHorz ) h -= m_scrollbarHorz->GetSize().y; #endif // wxUSE_SCROLLBAR *height = h - rectBorder.y - rectBorder.height; // we shouldn't return invalid height if ( *height < 0 ) *height = 0; } }
void wxWindow::PositionScrollbars() { #if wxUSE_SCROLLBAR // do not use GetClientSize/Rect as it relies on the scrollbars being // correctly positioned wxSize size = GetSize(); wxBorder border = GetBorder(); wxRect rectBorder = m_renderer->GetBorderDimensions(border); bool inside = m_renderer->AreScrollbarsInsideBorder(); int height = m_scrollbarHorz ? m_scrollbarHorz->GetSize().y : 0; int width = m_scrollbarVert ? m_scrollbarVert->GetSize().x : 0; wxRect rectBar; if ( m_scrollbarVert ) { rectBar.x = size.x - width; if ( inside ) rectBar.x -= rectBorder.width; rectBar.width = width; rectBar.y = 0; if ( inside ) rectBar.y += rectBorder.y; rectBar.height = size.y - height; if ( inside ) rectBar.height -= rectBorder.y + rectBorder.height; m_scrollbarVert->SetSize(rectBar, wxSIZE_NO_ADJUSTMENTS); } if ( m_scrollbarHorz ) { rectBar.y = size.y - height; if ( inside ) rectBar.y -= rectBorder.height; rectBar.height = height; rectBar.x = 0; if ( inside ) rectBar.x += rectBorder.x; rectBar.width = size.x - width; if ( inside ) rectBar.width -= rectBorder.x + rectBorder.width; m_scrollbarHorz->SetSize(rectBar, wxSIZE_NO_ADJUSTMENTS); } RefreshScrollbars(); #endif // wxUSE_SCROLLBAR }
wxSize wxGenericCollapsiblePane::DoGetBestSize() const { // NB: do not use GetSize() but rather GetMinSize() wxSize sz = m_sz->GetMinSize(); // when expanded, we need more vertical space if ( IsExpanded() ) { sz.SetWidth(wxMax( sz.GetWidth(), m_pPane->GetBestSize().x )); sz.SetHeight(sz.y + GetBorder() + m_pPane->GetBestSize().y); } return sz; }
void Widget::ResetBlock() { //产生当前方块 block_cpy(cur_block,next_block); GetBorder(cur_block,cur_border); //产生下一个方块 int block_id=rand()%7; CreateBlock(next_block,block_id); //设置初始方块坐标,以方块左上角为锚点 block_point start_point; start_point.pos_x=AREA_COL/2-2; start_point.pos_y=0; block_pos=start_point; }
NS_IMETHODIMP nsIFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding) { aBorderAndPadding.SizeTo(0, 0, 0, 0); nsresult rv = GetBorder(aBorderAndPadding); if (NS_FAILED(rv)) return rv; nsMargin padding; rv = GetPadding(padding); if (NS_FAILED(rv)) return rv; aBorderAndPadding += padding; return rv; }
void wxListBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) { if ( GetWindowStyle() & wxLB_INT_HEIGHT ) { // we must round up the height to an entire number of rows // the client area must contain an int number of rows, so take borders // into account wxRect rectBorders = GetRenderer()->GetBorderDimensions(GetBorder()); wxCoord hBorders = rectBorders.y + rectBorders.height; wxCoord hLine = GetLineHeight(); height = ((height - hBorders + hLine - 1) / hLine)*hLine + hBorders; } wxListBoxBase::DoSetSize(x, y, width, height, sizeFlags); }
void nuiDecoration::GetBorders(const nuiWidget* pWidget, float& rLeft, float& rRight, float& rTop, float& rBottom, float& rHorizontal, float& rVertical) const { if (!mBorderEnabled) { rLeft = rRight = rTop = rBottom = rHorizontal = rVertical = 0; return; } rLeft = GetBorder(nuiLeft, pWidget); rRight = GetBorder(nuiRight, pWidget); rTop = GetBorder(nuiTop, pWidget); rBottom = GetBorder(nuiBottom, pWidget); rHorizontal = GetBorder(nuiFillHorizontal, pWidget); rVertical = GetBorder(nuiFillVertical, pWidget); }
void GUIVidget::Draw() { if(IsVisible()) { if(GetTexture()) { COLOR4 c = GetColor(); glColor4ub(c.r, c.g, c.b, c.a); DrawTexture(GetX(), GetY(), 0, 0, GetWidth(), GetHeight(), GetTexture(), false, false, 100, 100); } if(GetBorder()) { if(GetBorderType() == btAlways) { Box(GetX()-1, GetY()-1, GetWidth()+1, GetHeight()+1); } } } }
LPDISPATCH CXTPChartRadarAreaSeriesStyle::OleGetBorder() { return XTPGetDispatch(GetBorder()); }
void Widget::BlockMove(Direction dir) { switch (dir) { case UP: if(IsCollide(block_pos.pos_x,block_pos.pos_y,UP)) break; //逆时针旋转90度 BlockRotate(cur_block); //防止旋转后bug,i和j从0到4重新设置方块 for(int i=0;i<4;i++) for(int j=0;j<4;j++) game_area[block_pos.pos_y+i][block_pos.pos_x+j]=cur_block[i][j]; //重新计算边界 GetBorder(cur_block,cur_border); break; case DOWN: //方块到达边界则不再移动 if(block_pos.pos_y+cur_border.dbound==AREA_ROW-1) { ConvertStable(block_pos.pos_x,block_pos.pos_y); ResetBlock(); break; } //碰撞检测,只计算上下左右边界,先尝试走一格,如果碰撞则稳定方块后跳出 if(IsCollide(block_pos.pos_x,block_pos.pos_y,DOWN)) { //只有最终不能下落才转成稳定方块 ConvertStable(block_pos.pos_x,block_pos.pos_y); ResetBlock(); break; } //恢复方块上场景 for(int j=cur_border.lbound;j<=cur_border.rbound;j++) game_area[block_pos.pos_y][block_pos.pos_x+j]=0; //没有碰撞则下落一格 block_pos.pos_y+=1; //方块下降一格,拷贝到场景,注意左右边界 for(int i=0;i<4;i++) //必须是0到4 for(int j=cur_border.lbound;j<=cur_border.rbound;j++) if(block_pos.pos_y+i<=AREA_ROW-1&&game_area[block_pos.pos_y+i][block_pos.pos_x+j]!=2) //注意场景数组不越界,而且不会擦出稳定的方块 game_area[block_pos.pos_y+i][block_pos.pos_x+j]=cur_block[i][j]; break; case LEFT: //到左边界或者碰撞不再往左 if(block_pos.pos_x+cur_border.lbound==0||IsCollide(block_pos.pos_x,block_pos.pos_y,LEFT)) break; //恢复方块右场景 for(int i=cur_border.ubound;i<=cur_border.dbound;i++) game_area[block_pos.pos_y+i][block_pos.pos_x+3]=0; block_pos.pos_x-=1; //方块左移一格,拷贝到场景 for(int i=cur_border.ubound;i<=cur_border.dbound;i++) for(int j=0;j<4;j++) if(block_pos.pos_x+j>=0&&game_area[block_pos.pos_y+i][block_pos.pos_x+j]!=2) //注意场景数组不越界 game_area[block_pos.pos_y+i][block_pos.pos_x+j]=cur_block[i][j]; break; case RIGHT: if(block_pos.pos_x+cur_border.rbound==AREA_COL-1||IsCollide(block_pos.pos_x,block_pos.pos_y,RIGHT)) break; //恢复方块左场景 for(int i=cur_border.ubound;i<=cur_border.dbound;i++) game_area[block_pos.pos_y+i][block_pos.pos_x]=0; block_pos.pos_x+=1; //方块右移一格,拷贝到场景 for(int i=cur_border.ubound;i<=cur_border.dbound;i++) for(int j=0;j<4;j++) if(block_pos.pos_x+j<=AREA_COL-1&&game_area[block_pos.pos_y+i][block_pos.pos_x+j]!=2) //注意场景数组不越界 game_area[block_pos.pos_y+i][block_pos.pos_x+j]=cur_block[i][j]; break; case SPACE: //一次到底 //一格一格下移,直到不能下移 while(block_pos.pos_y+cur_border.dbound<AREA_ROW-1&&!IsCollide(block_pos.pos_x,block_pos.pos_y,DOWN)) { //恢复方块上场景 for(int j=cur_border.lbound;j<=cur_border.rbound;j++) game_area[block_pos.pos_y][block_pos.pos_x+j]=0; //没有碰撞则下落一格 block_pos.pos_y+=1; //方块下降一格,拷贝到场景,注意左右边界 for(int i=0;i<4;i++) //必须是0到4 for(int j=cur_border.lbound;j<=cur_border.rbound;j++) if(block_pos.pos_y+i<=AREA_ROW-1&&game_area[block_pos.pos_y+i][block_pos.pos_x+j]!=2) //注意场景数组不越界,而且不会擦出稳定的方块 game_area[block_pos.pos_y+i][block_pos.pos_x+j]=cur_block[i][j]; } ConvertStable(block_pos.pos_x,block_pos.pos_y); ResetBlock(); break; default: break; } //处理消行,整个场景上面的行依次下移 int i=AREA_ROW-1; int line_count=0; //记消行数 while(i>=1) { bool is_line_full=true; for(int j=0;j<AREA_COL;j++) if(game_area[i][j]==0) { is_line_full=false; i--; break; } if(is_line_full) { for(int k=i;k>=1;k--) for(int j=0;j<AREA_COL;j++) game_area[k][j]=game_area[k-1][j]; line_count++;//每次增加消行的行数 } } score+=line_count*10; //得分 //判断游戏是否结束 for(int j=0;j<AREA_COL;j++) if(game_area[0][j]==2) //最顶端也有稳定方块 GameOver(); }
void Border::DrawBorder(sf::RenderWindow& rwMainWindow) { for(int i = 0; i < GetBorder().size(); i++) rwMainWindow.draw(m_vectBorder[i]); }
void GetBorder(IplImage *mask, vector<CvPoint> &borders) { GetBorder(mask, C_FG, borders); }
bool wxWindow::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { // Get default border wxBorder border = GetBorder(style); style &= ~wxBORDER_MASK; style |= border; long actualStyle = style; // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW // as under the other platforms actualStyle |= wxCLIP_CHILDREN; actualStyle &= ~wxVSCROLL; actualStyle &= ~wxHSCROLL; #ifdef __WXMSW__ // without this, borders (non-client areas in general) are not repainted // correctly when resizing; apparently, native NC areas are fully repainted // even without this style by MSW, but wxUniv implements client area // itself, so it doesn't work correctly for us // // FIXME: this is very expensive, we need to fix the (commented-out) code // in OnSize() instead actualStyle |= wxFULL_REPAINT_ON_RESIZE; #endif if ( !wxWindowNative::Create(parent, id, pos, size, actualStyle, name) ) return false; // Set full style again, including those we didn't want present // when calling the base window Create(). wxWindowBase::SetWindowStyleFlag(style); // if we allow or should always have a vertical scrollbar, make it if ( style & wxVSCROLL || style & wxALWAYS_SHOW_SB ) { #if wxUSE_TWO_WINDOWS SetInsertIntoMain( true ); #endif #if wxUSE_SCROLLBAR m_scrollbarVert = new wxWindowScrollBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL); #endif // wxUSE_SCROLLBAR #if wxUSE_TWO_WINDOWS SetInsertIntoMain( false ); #endif } // if we should allow a horizontal scrollbar, make it if ( style & wxHSCROLL ) { #if wxUSE_TWO_WINDOWS SetInsertIntoMain( true ); #endif #if wxUSE_SCROLLBAR m_scrollbarHorz = new wxWindowScrollBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_HORIZONTAL); #endif // wxUSE_SCROLLBAR #if wxUSE_TWO_WINDOWS SetInsertIntoMain( false ); #endif } #if wxUSE_SCROLLBAR if (m_scrollbarHorz || m_scrollbarVert) { // position it/them PositionScrollbars(); } #endif // wxUSE_SCROLLBAR return true; }