void SpaceStation::DoDockingAnimation(const double timeStep) { matrix4x4d rot, wantRot; vector3d p1, p2, zaxis; for (int i=0; i<MAX_DOCKING_PORTS; i++) { shipDocking_t &dt = m_shipDocking[i]; if (!dt.ship) continue; if (!dt.stage) continue; // docked stage is m_type->numDockingPorts + 1 if (dt.stage > m_type->numDockingStages) continue; GetRotMatrix(rot); double stageDuration = (dt.stage > 0 ? m_type->dockAnimStageDuration[dt.stage-1] : m_type->undockAnimStageDuration[abs(dt.stage)-1]); dt.stagePos += timeStep / stageDuration; if (dt.stage == 1) { // SPECIAL stage! Docking granted but waiting for ship // to dock m_openAnimState[i] += 0.3*timeStep; m_dockAnimState[i] -= 0.3*timeStep; if (dt.stagePos >= 1.0) { if (dt.ship == static_cast<Ship*>(Pi::player)) Pi::onDockingClearanceExpired.emit(this); dt.ship = 0; dt.stage = 0; } continue; } if (dt.stagePos > 1.0) { dt.stagePos = 0; if (dt.stage >= 0) dt.stage++; else dt.stage--; dt.fromPos = rot.InverseOf() * (dt.ship->GetPosition() - GetPosition()); matrix4x4d temp; dt.ship->GetRotMatrix(temp); dt.fromRot = Quaterniond::FromMatrix4x4(temp); } SpaceStationType::positionOrient_t shipOrient; bool onRails = m_type->GetDockAnimPositionOrient(i, dt.stage, dt.stagePos, dt.fromPos, shipOrient, dt.ship); if (onRails) { dt.ship->SetPosition(GetPosition() + rot*shipOrient.pos); wantRot = matrix4x4d::MakeRotMatrix( shipOrient.xaxis, shipOrient.yaxis, shipOrient.xaxis.Cross(shipOrient.yaxis)) * rot; // use quaternion spherical linear interpolation to do // rotation smoothly Quaterniond wantQuat = Quaterniond::FromMatrix4x4(wantRot); Quaterniond q = Quaterniond::Nlerp(dt.fromRot, wantQuat, dt.stagePos); wantRot = q.ToMatrix4x4<double>(); // wantRot.Renormalize(); dt.ship->SetRotMatrix(wantRot); } else { if (dt.stage >= 0) { // set docked dt.ship->SetDockedWith(this, i); CreateBB(); Pi::luaOnShipDocked->Queue(dt.ship, this); } else { if (!dt.ship->IsEnabled()) { // launch ship dt.ship->Enable(); dt.ship->SetFlightState(Ship::FLYING); dt.ship->SetAngVelocity(GetFrame()->GetAngVelocity()); dt.ship->SetForce(vector3d(0,0,0)); dt.ship->SetTorque(vector3d(0,0,0)); if (m_type->dockMethod == SpaceStationType::SURFACE) { dt.ship->SetThrusterState(1, 1.0); // up } else { dt.ship->SetVelocity(GetFrame()->GetStasisVelocityAtPosition(dt.ship->GetPosition())); dt.ship->SetThrusterState(2, -1.0); // forward } Pi::luaOnShipUndocked->Queue(dt.ship, this); } } } if ((dt.stage < 0) && ((-dt.stage) > m_type->numUndockStages)) { dt.stage = 0; dt.ship = 0; } } for (int i=0; i<MAX_DOCKING_PORTS; i++) { m_openAnimState[i] = Clamp(m_openAnimState[i], 0.0, 1.0); m_dockAnimState[i] = Clamp(m_dockAnimState[i], 0.0, 1.0); } }
void Interactor::GetRelative(IntCoord& x, IntCoord& y, World*) const { IntCoord left, bottom; GetPosition(left, bottom); x += left; y += bottom; }
bool Widget::TriggerMouseUp(const MouseButtonEvent &event, bool emit) { HandleMouseUp(event); if (emit) emit = !onMouseUp.emit(event); if (GetContainer()) { MouseButtonEvent translatedEvent = MouseButtonEvent(event.action, event.button, event.pos+GetPosition()); GetContainer()->TriggerMouseUp(translatedEvent, emit); } return !emit; }
void COthelloView::OnMouseMove(UINT nFlags, CPoint point) { int i,j,have=0; CClientDC dc(this); CPoint p; COthelloDoc *pDoc=GetDocument(); for (i=0;i<8;i++) for (j=0;j<8;j++) { p=GetPosition(j,i); if (point.x>p.x && point.x<p.x+35 && point.y>p.y && point.y<p.y+35) { if (m_Current!=i*8+j) { if (m_Current>=0 && (pDoc->m_MainTable).GetTable(m_Current)<1) { if ((pDoc->m_MainTable).IsDown(m_CurCol,m_CurRow,m_CurPlay)) { BiltBitmap(m_CurX,m_CurY,m_CurX+34,m_CurY+34,m_hMaskerX); } else { dc.FillSolidRect(m_CurX,m_CurY,34,34,m_NormalColor); } ::SetClassLong(GetSafeHwnd(),GCL_HCURSOR,NULL); SetCursor(m_hcurDefault); } if ((pDoc->m_MainTable).GetTable(j,i)<1 && (pDoc->m_MainTable).IsDown(j,i,m_CurPlay)) { dc.FillSolidRect(p.x,p.y,34,34,m_SelectColor); ::SetClassLong(GetSafeHwnd(),GCL_HCURSOR,NULL); if (m_CurPlay==T_WHITE) { SetCursor(m_hcurWhite); } else { SetCursor(m_hcurBlack); } } m_Current=i*8+j; m_CurX=p.x; m_CurY=p.y; m_CurCol=j; m_CurRow=i; } have=1; } } if (!have) { if (m_Current>=0 && (pDoc->m_MainTable).GetTable(m_Current)<1) { if ((pDoc->m_MainTable).IsDown(m_CurCol,m_CurRow,m_CurPlay)) { BiltBitmap(m_CurX,m_CurY,m_CurX+34,m_CurY+34,m_hMaskerX); } else { dc.FillSolidRect(m_CurX,m_CurY,34,34,m_NormalColor); } ::SetClassLong(GetSafeHwnd(),GCL_HCURSOR,NULL); SetCursor(m_hcurDefault); } m_Current=-1; } // TODO: Add your message handler code here and/or call default CView::OnMouseMove(nFlags, point); }
BOOL COthelloView::DrawTable(int col, int row, BYTE value) { int c,r,yes=0,i,j; BYTE v; CPoint point; COthelloDoc *pDoc=GetDocument(); if (value==T_WHITE) { // To Left for (c=col-1;c>=0;c--) { v=(pDoc->m_MainTable).GetTable(c,row); if (v==T_BLACK) { continue; } else { if (v==T_WHITE && col-c>1) { for (i=col-1;i>c;i--) { (pDoc->m_MainTable).SetTable(i,row,v); point=GetPosition(i,row); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hWhite); } break; } else { break; } } } // To Left-Top for (c=col-1,r=row-1;c>=0 && r>=0;c--,r--) { v=(pDoc->m_MainTable).GetTable(c,r); if (v==T_BLACK) { continue; } else { if (v==T_WHITE && col-c>1 && row-r>1) { for (i=col-1,j=row-1;i>c && j>r;i--,j--) { (pDoc->m_MainTable).SetTable(i,j,v); point=GetPosition(i,j); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hWhite); } break; } else { break; } } } // To Top for (r=row-1;r>=0;r--) { v=(pDoc->m_MainTable).GetTable(col,r); if (v==T_BLACK) { continue; } else { if (v==T_WHITE && row-r>1) { for (i=row-1;i>r;i--) { (pDoc->m_MainTable).SetTable(col,i,v); point=GetPosition(col,i); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hWhite); } break; } else { break; } } } // To Right-Top for (c=col+1,r=row-1;c<8 && r>=0;c++,r--) { v=(pDoc->m_MainTable).GetTable(c,r); if (v==T_BLACK) { continue; } else { if (v==T_WHITE && c-col>1 && row-r>1) { for (i=col+1,j=row-1;i<c && j>r;i++,j--) { (pDoc->m_MainTable).SetTable(i,j,v); point=GetPosition(i,j); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hWhite); } break; } else { break; } } } // To Right for (c=col+1;c<8;c++) { v=(pDoc->m_MainTable).GetTable(c,row); if (v==T_BLACK) { continue; } else { if (v==T_WHITE && c-col>1) { for (i=col+1;i<c;i++) { (pDoc->m_MainTable).SetTable(i,row,v); point=GetPosition(i,row); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hWhite); } break; } else { break; } } } // To Right-Bottom for (c=col+1,r=row+1;c<8 && r<8;c++,r++) { v=(pDoc->m_MainTable).GetTable(c,r); if (v==T_BLACK) { continue; } else { if (v==T_WHITE && c-col>1 && r-row>1) { for (i=col+1,j=row+1;i<c && j<r;i++,j++) { (pDoc->m_MainTable).SetTable(i,j,v); point=GetPosition(i,j); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hWhite); } break; } else { break; } } } // To Bottom for (r=row+1;r<8;r++) { v=(pDoc->m_MainTable).GetTable(col,r); if (v==T_BLACK) { continue; } else { if (v==T_WHITE && r-row>1) { for (i=row+1;i<r;i++) { (pDoc->m_MainTable).SetTable(col,i,v); point=GetPosition(col,i); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hWhite); } break; } else { break; } } } // To Left-Bottom for (c=col-1,r=row+1;c>=0 && r<8;c--,r++) { v=(pDoc->m_MainTable).GetTable(c,r); if (v==T_BLACK) { continue; } else { if (v==T_WHITE && r-row>1 && col-c>1) { for (i=col-1,j=row+1;i>c && j<r;i--,j++) { (pDoc->m_MainTable).SetTable(i,j,v); point=GetPosition(i,j); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hWhite); } break; } else { break; } } } // No Space!!! return FALSE; } // Black if (value==T_BLACK) { // To Left for (c=col-1;c>=0;c--) { v=(pDoc->m_MainTable).GetTable(c,row); if (v==T_WHITE) { continue; } else { if (v==T_BLACK && col-c>1) { for (i=col-1;i>c;i--) { (pDoc->m_MainTable).SetTable(i,row,v); point=GetPosition(i,row); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hBlack); } break; } else { break; } } } // To Left-Top for (c=col-1,r=row-1;c>=0 && r>=0;c--,r--) { v=(pDoc->m_MainTable).GetTable(c,r); if (v==T_WHITE) { continue; } else { if (v==T_BLACK && col-c>1 && row-r>1) { for (i=col-1,j=row-1;i>c && j>r;i--,j--) { (pDoc->m_MainTable).SetTable(i,j,v); point=GetPosition(i,j); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hBlack); } break; } else { break; } } } // To Top for (r=row-1;r>=0;r--) { v=(pDoc->m_MainTable).GetTable(col,r); if (v==T_WHITE) { continue; } else { if (v==T_BLACK && row-r>1) { for (i=row-1;i>r;i--) { (pDoc->m_MainTable).SetTable(col,i,v); point=GetPosition(col,i); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hBlack); } break; } else { break; } } } // To Right-Top for (c=col+1,r=row-1;c<8 && r>=0;c++,r--) { v=(pDoc->m_MainTable).GetTable(c,r); if (v==T_WHITE) { continue; } else { if (v==T_BLACK && c-col>1 && row-r>1) { for (i=col+1,j=row-1;i<c && j>r;i++,j--) { (pDoc->m_MainTable).SetTable(i,j,v); point=GetPosition(i,j); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hBlack); } break; } else { break; } } } // To Right for (c=col+1;c<8;c++) { v=(pDoc->m_MainTable).GetTable(c,row); if (v==T_WHITE) { continue; } else { if (v==T_BLACK && c-col>1) { for (i=col+1;i<c;i++) { (pDoc->m_MainTable).SetTable(i,row,v); point=GetPosition(i,row); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hBlack); } break; } else { break; } } } // To Right-Bottom for (c=col+1,r=row+1;c<8 && r<8;c++,r++) { v=(pDoc->m_MainTable).GetTable(c,r); if (v==T_WHITE) { continue; } else { if (v==T_BLACK && c-col>1 && r-row>1) { for (i=col+1,j=row+1;i<c && j<r;i++,j++) { (pDoc->m_MainTable).SetTable(i,j,v); point=GetPosition(i,j); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hBlack); } break; } else { break; } } } // To Bottom for (r=row+1;r<8;r++) { v=(pDoc->m_MainTable).GetTable(col,r); if (v==T_WHITE) { continue; } else { if (v==T_BLACK && r-row>1) { for (i=row+1;i<r;i++) { (pDoc->m_MainTable).SetTable(col,i,v); point=GetPosition(col,i); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hBlack); } break; } else { break; } } } // To Left-Bottom for (c=col-1,r=row+1;c>=0 && r<8;c--,r++) { v=(pDoc->m_MainTable).GetTable(c,r); if (v==T_WHITE) { continue; } else { if (v==T_BLACK && r-row>1 && col-c>1) { for (i=col-1,j=row+1;i>c && j<r;i--,j++) { (pDoc->m_MainTable).SetTable(i,j,v); point=GetPosition(i,j); BiltBitmap(point.x,point.y,point.x+33,point.y+33,m_hBlack); } break; } else { break; } } } // No Space!!! return FALSE; } return TRUE; }
/* f == NULL, then absolute position within system */ vector3d Body::GetPositionRelTo(const Frame *relTo) const { matrix4x4d m; Frame::GetFrameTransform(m_frame, relTo, m); return m * GetPosition(); }
void wxSashLayoutWindow::OnCalculateLayout(wxCalculateLayoutEvent& event) { wxRect clientSize(event.GetRect()); int flags = event.GetFlags(); if (!IsShown()) return; // Let's assume that all windows stretch the full extent of the window in // the direction of that window orientation. This will work for non-docking toolbars, // and the status bar. Note that the windows have to have been created in a certain // order to work, else you might get a left-aligned window going to the bottom // of the window, and the status bar appearing to the right of it. The // status bar would have to be created after or before the toolbar(s). wxRect thisRect; // Try to stretch int length = (GetOrientation() == wxLAYOUT_HORIZONTAL) ? clientSize.width : clientSize.height; wxLayoutOrientation orient = GetOrientation(); // We assume that a window that says it's horizontal, wants to be stretched in that // direction. Is this distinction too fine? Do we assume that any horizontal // window needs to be stretched in that direction? Possibly. int whichDimension = (GetOrientation() == wxLAYOUT_HORIZONTAL) ? wxLAYOUT_LENGTH_X : wxLAYOUT_LENGTH_Y; wxQueryLayoutInfoEvent infoEvent(GetId()); infoEvent.SetEventObject(this); infoEvent.SetRequestedLength(length); infoEvent.SetFlags(orient | whichDimension); if (!GetEventHandler()->ProcessEvent(infoEvent)) return; wxSize sz = infoEvent.GetSize(); if (sz.x == 0 && sz.y == 0) // Assume it's invisible return; // Now we know the size it wants to be. We wish to decide where to place it, i.e. // how it's aligned. switch (GetAlignment()) { case wxLAYOUT_TOP: { thisRect.x = clientSize.x; thisRect.y = clientSize.y; thisRect.width = sz.x; thisRect.height = sz.y; clientSize.y += thisRect.height; clientSize.height -= thisRect.height; break; } case wxLAYOUT_LEFT: { thisRect.x = clientSize.x; thisRect.y = clientSize.y; thisRect.width = sz.x; thisRect.height = sz.y; clientSize.x += thisRect.width; clientSize.width -= thisRect.width; break; } case wxLAYOUT_RIGHT: { thisRect.x = clientSize.x + (clientSize.width - sz.x); thisRect.y = clientSize.y; thisRect.width = sz.x; thisRect.height = sz.y; clientSize.width -= thisRect.width; break; } case wxLAYOUT_BOTTOM: { thisRect.x = clientSize.x; thisRect.y = clientSize.y + (clientSize.height - sz.y); thisRect.width = sz.x; thisRect.height = sz.y; clientSize.height -= thisRect.height; break; } case wxLAYOUT_NONE: { break; } } if ((flags & wxLAYOUT_QUERY) == 0) { // If not in query mode, resize the window. // TODO: add wxRect& form to wxWindow::SetSize wxSize sz2 = GetSize(); wxPoint pos = GetPosition(); SetSize(thisRect.x, thisRect.y, thisRect.width, thisRect.height); // Make sure the sash is erased when the window is resized if ((pos.x != thisRect.x || pos.y != thisRect.y || sz2.x != thisRect.width || sz2.y != thisRect.height) && (GetSashVisible(wxSASH_TOP) || GetSashVisible(wxSASH_RIGHT) || GetSashVisible(wxSASH_BOTTOM) || GetSashVisible(wxSASH_LEFT))) Refresh(true); } event.SetRect(clientSize); }
BOOL CStdioFileEx::ReadString(CString& rString) { const int nMAX_LINE_CHARS = 4096; BOOL bReadData = FALSE; LPTSTR lpsz; int nLen = 0; wchar_t* pszUnicodeString = NULL; char * pszMultiByteString= NULL; int nChars = 0; try { // If at position 0, discard byte-order mark before reading if (!m_pStream || (GetPosition() == 0 && m_bIsUnicodeText)) { wchar_t cDummy; // Read(&cDummy, sizeof(_TCHAR)); Read(&cDummy, sizeof(wchar_t)); } // If compiled for Unicode #ifdef _UNICODE if (m_bIsUnicodeText) { // Do standard stuff - Unicode to Unicode. Seems to work OK. bReadData = CStdioFile::ReadString(rString); } else { pszUnicodeString = new wchar_t[nMAX_LINE_CHARS]; pszMultiByteString= new char[nMAX_LINE_CHARS]; // Initialise to something safe memset(pszUnicodeString, 0, sizeof(wchar_t) * nMAX_LINE_CHARS); memset(pszMultiByteString, 0, sizeof(char) * nMAX_LINE_CHARS); // Read the string bReadData = (NULL != fgets(pszMultiByteString, nMAX_LINE_CHARS, m_pStream)); if (bReadData) { // Convert multibyte to Unicode, using the specified code page nChars = GetUnicodeStringFromMultiByteString(pszMultiByteString, pszUnicodeString, nMAX_LINE_CHARS, m_nFileCodePage); if (nChars > 0) { rString = (CString)pszUnicodeString; } } } #else if (!m_bIsUnicodeText) { // Do standard stuff -- read ANSI in ANSI bReadData = CStdioFile::ReadString(rString); // Get the current code page UINT nLocaleCodePage = GetCurrentLocaleCodePage(); // If we got it OK... if (nLocaleCodePage > 0) { // if file code page does not match the system code page, we need to do a double conversion! if (nLocaleCodePage != (UINT)m_nFileCodePage) { int nStringBufferChars = rString.GetLength() + 1; pszUnicodeString = new wchar_t[nStringBufferChars]; // Initialise to something safe memset(pszUnicodeString, 0, sizeof(wchar_t) * nStringBufferChars); // Convert to Unicode using the file code page nChars = GetUnicodeStringFromMultiByteString(rString, pszUnicodeString, nStringBufferChars, m_nFileCodePage); // Convert back to multibyte using the system code page // (This doesn't really confer huge advantages except to avoid "mangling" of non-convertible special // characters. So, if a file in the E.European code page is displayed on a system using the // western European code page, special accented characters which the system cannot display will be // replaced by the default character (a hash or something), rather than being incorrectly mapped to // other, western European accented characters). if (nChars > 0) { // Calculate how much we need for the MB buffer (it might be larger) nStringBufferChars = GetRequiredMultiByteLengthForUnicodeString(pszUnicodeString,nLocaleCodePage); pszMultiByteString= new char[nStringBufferChars]; nChars = GetMultiByteStringFromUnicodeString(pszUnicodeString, pszMultiByteString, nStringBufferChars, nLocaleCodePage); rString = (CString)pszMultiByteString; } } } } else { pszUnicodeString = new wchar_t[nMAX_LINE_CHARS]; // Initialise to something safe memset(pszUnicodeString, 0, sizeof(wchar_t) * nMAX_LINE_CHARS); // Read as Unicode, convert to ANSI // Bug fix by Dennis Jeryd 06/07/2003: initialise bReadData bReadData = (NULL != fgetws(pszUnicodeString, nMAX_LINE_CHARS, m_pStream)); if (bReadData) { // Calculate how much we need for the multibyte string int nRequiredMBBuffer = GetRequiredMultiByteLengthForUnicodeString(pszUnicodeString,m_nFileCodePage); pszMultiByteString= new char[nRequiredMBBuffer]; nChars = GetMultiByteStringFromUnicodeString(pszUnicodeString, pszMultiByteString, nRequiredMBBuffer, m_nFileCodePage); if (nChars > 0) { rString = (CString)pszMultiByteString; } } } #endif // Then remove end-of-line character if in Unicode text mode if (bReadData) { // Copied from FileTxt.cpp but adapted to Unicode and then adapted for end-of-line being just '\r'. nLen = rString.GetLength(); if (nLen > 1 && rString.Mid(nLen-2) == sNEWLINE) { rString.GetBufferSetLength(nLen-2); } else { lpsz = rString.GetBuffer(0); if (nLen != 0 && (lpsz[nLen-1] == _T('\r') || lpsz[nLen-1] == _T('\n'))) { rString.GetBufferSetLength(nLen-1); } } } } // Ensure we always delete in case of exception catch(...) { if (pszUnicodeString) delete [] pszUnicodeString; if (pszMultiByteString) delete [] pszMultiByteString; throw; } if (pszUnicodeString) delete [] pszUnicodeString; if (pszMultiByteString) delete [] pszMultiByteString; return bReadData; }
bool WinFrame::LoadConfig(const std::string& filename) { /* Open file for writing */ std::ifstream file(filename); if (!file.good()) return false; /* Define [R]ead function */ std::string line, ident, value; auto R = [&line](std::size_t& pos) -> std::string { pos = line.find('\"', pos); if (pos != std::string::npos) { auto start = ++pos; pos = line.find('\"', pos); if (pos != std::string::npos) { auto end = pos++; return line.substr(start, end - start); } } return ""; }; auto RInt = [&value]() { int i = 0; std::istringstream stream(value); stream >> i; return i; }; /* Read file content */ while (!file.eof()) { /* Read next line from file */ std::getline(file, line); std::size_t pos = 0; ident = R(pos); value = R(pos); /* Map values to configurations */ if (ident.empty()) continue; if (ident.front() == '$') { if (ident == "$window_x") SetPosition(wxPoint(RInt(), GetPosition().y)); else if (ident == "$window_y") SetPosition(wxPoint(GetPosition().x, RInt())); else if (ident == "$window_width") SetSize(wxSize(RInt(), GetSize().GetHeight())); else if (ident == "$window_height") SetSize(wxSize(GetSize().GetWidth(), RInt())); else if (ident == "$input") SetInput(value); else if (ident == "$degree") SetOptionDegree(value == "yes"); else if (ident == "$cursor") cursorPos_ = RInt(); else if (ident.size() > 9 && ident.substr(0, 9) == "$history_") inCtrl_->GetHistory().Add(value); } else constantsSet_.constants[ident] = value; } return true; }
void CPlayer::Update( float dTime ) { NNObject::Update( dTime ); mPlayerUI->SetRotation( -this->GetRotation() ); mPlayerUI->SetHP( mHp ); mPlayerUI->SetVisible(true); // Die mDie->SetVisible( false ); // Normal mStopNormal->SetVisible( false ); mMoveNormal->SetVisible( false ); mAttackNormal->SetVisible( false ); mDieNormal->SetVisible( false ); // Fire mStopFire->SetVisible( false ); mMoveFire->SetVisible( false ); mAttackFire->SetVisible( false ); mDieFire->SetVisible( false ); // Water mStopWater->SetVisible( false ); mMoveWater->SetVisible( false ); mAttackWater->SetVisible( false ); mDieWater->SetVisible( false ); // Wind mStopWind->SetVisible( false ); mMoveWind->SetVisible( false ); mAttackWind->SetVisible( false ); mDieWind->SetVisible( false ); // Earth mStopEarth->SetVisible( false ); mMoveEarth->SetVisible( false ); mAttackEarth->SetVisible( false ); mDieEarth->SetVisible( false ); SetPosition( GetPosition() + mMoveVelocity * dTime ); switch (mPlayerState) { case IDLE: { switch (mPlayerType) { case TYPE_ZERO: { mStopNormal->SetVisible( true ); } break; case TYPE_A: { mStopFire->SetVisible( true ); } break; case TYPE_B: { mStopWater->SetVisible( true ); } break; case TYPE_C: { mStopWind->SetVisible( true ); } break; case TYPE_D: { mStopEarth->SetVisible( true ); } break; } } break; case WALK: { switch (mPlayerType) { case TYPE_ZERO: { mMoveNormal->SetVisible( true ); } break; case TYPE_A: { mMoveFire->SetVisible( true ); } break; case TYPE_B: { mMoveWater->SetVisible( true ); } break; case TYPE_C: { mMoveWind->SetVisible( true ); } break; case TYPE_D: { mMoveEarth->SetVisible( true ); } break; } //SetPosition( GetPosition() + mMoveVelocity * dTime ); }break; case ATTAACK: { switch (mPlayerType) { case TYPE_ZERO: { mAttackNormal->SetVisible( true ); } break; case TYPE_A: { mAttackFire->SetVisible( true ); } break; case TYPE_B: { mAttackWater->SetVisible( true ); } break; case TYPE_C: { mAttackWind->SetVisible( true ); } break; case TYPE_D: { mAttackEarth->SetVisible( true ); } break; } } break; case DIE: { //mDie->SetVisible( true ); switch (mPlayerType) { case TYPE_ZERO: { mDieNormal->SetVisible( true ); } break; case TYPE_A: { mDieFire->SetVisible( true ); } break; case TYPE_B: { mDieWater->SetVisible( true ); } break; case TYPE_C: { mDieWind->SetVisible( true ); } break; case TYPE_D: { mDieEarth->SetVisible( true ); } break; } SetRotation( 90.f/180.f*3.14f ); mPlayerUI->SetVisible(false); mPlayerUI->SetHP( 0 ); } break; case USER_ACTIVE_SKILL: { SetPosition( GetPosition() + mMoveVelocity * dTime ); } break; case TYPE_ACTIVE_SKILL: { SetPosition( GetPosition() + mMoveVelocity * dTime ); } break; default: break; } }
// -------------------------------------------------------------------------------------------- // // CStdioFileEx::WriteString() // // -------------------------------------------------------------------------------------------- // Returns: void // Parameters: LPCTSTR lpsz // // Purpose: Writes string to file either in Unicode or multibyte, depending on whether the caller specified the // CStdioFileEx::modeWriteUnicode flag. Override of base class function. // Notes: If writing in Unicode we need to: // a) Write the Byte-order-mark at the beginning of the file // b) Write all strings in byte-mode // - If we were compiled in Unicode, we need to convert Unicode to multibyte if // we want to write in multibyte // - If we were compiled in multi-byte, we need to convert multibyte to Unicode if // we want to write in Unicode. // Exceptions: None. // void CStdioFileEx::WriteString(LPCTSTR lpsz) { wchar_t* pszUnicodeString = NULL; char * pszMultiByteString= NULL; try { // If writing Unicode and at the start of the file, need to write byte mark if (m_nFlags & CStdioFileEx::modeWriteUnicode) { // If at position 0, write byte-order mark before writing anything else if (!m_pStream || GetPosition() == 0) { wchar_t cBOM = (wchar_t)nUNICODE_BOM; CFile::Write(&cBOM, sizeof(wchar_t)); } } // If compiled in Unicode... #ifdef _UNICODE // If writing Unicode, no conversion needed if (m_nFlags & CStdioFileEx::modeWriteUnicode) { // Write in byte mode CFile::Write(lpsz, lstrlen(lpsz) * sizeof(wchar_t)); } // Else if we don't want to write Unicode, need to convert else { int nChars = lstrlen(lpsz) + 1; // Why plus 1? Because yes // int nBufferSize = nChars * sizeof(char); // leave space for multi-byte chars int nCharsWritten = 0; int nBufferSize = 0; pszUnicodeString = new wchar_t[nChars]; // Copy string to Unicode buffer lstrcpy(pszUnicodeString, lpsz); // Work out how much space we need for the multibyte conversion nBufferSize = GetRequiredMultiByteLengthForUnicodeString(pszUnicodeString, m_nFileCodePage); pszMultiByteString= new char[nBufferSize]; // Get multibyte string nCharsWritten = GetMultiByteStringFromUnicodeString(pszUnicodeString, pszMultiByteString, nBufferSize, m_nFileCodePage); if (nCharsWritten > 0) { // Do byte-mode write using actual chars written (fix by Howard J Oh) // CFile::Write((const void*)pszMultiByteString, lstrlen(lpsz)); CFile::Write((const void*)pszMultiByteString, nCharsWritten*sizeof(char)); } } // Else if *not* compiled in Unicode #else // If writing Unicode, need to convert if (m_nFlags & CStdioFileEx::modeWriteUnicode) { int nChars = lstrlen(lpsz) + 1; // Why plus 1? Because yes int nBufferSize = nChars * sizeof(wchar_t); int nCharsWritten = 0; pszUnicodeString = new wchar_t[nChars]; pszMultiByteString= new char[nChars]; // Copy string to multibyte buffer lstrcpy(pszMultiByteString, lpsz); nCharsWritten = GetUnicodeStringFromMultiByteString(pszMultiByteString, pszUnicodeString, nChars, m_nFileCodePage); if (nCharsWritten > 0) { // Do byte-mode write using actual chars written (fix by Howard J Oh) // CFile::Write(pszUnicodeString, lstrlen(lpsz) * sizeof(wchar_t)); CFile::Write(pszUnicodeString, nCharsWritten*sizeof(wchar_t)); } else { ASSERT(false); } } // Else if we don't want to write Unicode, no conversion needed, unless the code page differs else { // // Do standard stuff // CStdioFile::WriteString(lpsz); // Get the current code page UINT nLocaleCodePage = GetCurrentLocaleCodePage(); // If we got it OK, and if file code page does not match the system code page, we need to do a double conversion! if (nLocaleCodePage > 0 && nLocaleCodePage != (UINT)m_nFileCodePage) { int nChars = lstrlen(lpsz) + 1; // Why plus 1? Because yes pszUnicodeString = new wchar_t[nChars]; // Initialise to something safe memset(pszUnicodeString, 0, sizeof(wchar_t) * nChars); // Convert to Unicode using the locale code page (the code page we are using in memory) nChars = GetUnicodeStringFromMultiByteString((LPCSTR)(const char*)lpsz, pszUnicodeString, nChars, nLocaleCodePage); // Convert back to multibyte using the file code page // (Note that you can't reliably read a non-Unicode file written in code page A on a system using a code page B, // modify the file and write it back using code page A, unless you disable all this double-conversion code. // In effect, you have to choose between a mangled character display and mangled file writing). if (nChars > 0) { // Calculate how much we need for the MB buffer (it might be larger) nChars = GetRequiredMultiByteLengthForUnicodeString(pszUnicodeString, m_nFileCodePage); pszMultiByteString= new char[nChars]; memset(pszMultiByteString, 0, sizeof(char) * nChars); nChars = GetMultiByteStringFromUnicodeString(pszUnicodeString, pszMultiByteString, nChars, m_nFileCodePage); // Do byte-mode write. This avoids annoying "interpretation" of \n's as \r\n CFile::Write((const void*)pszMultiByteString, nChars * sizeof(char)); } } else { // Do byte-mode write. This avoids annoying "interpretation" of \n's as \r\n CFile::Write((const void*)lpsz, lstrlen(lpsz)*sizeof(char)); } } #endif } // Ensure we always clean up catch(...) { if (pszUnicodeString) delete [] pszUnicodeString; if (pszMultiByteString) delete [] pszMultiByteString; throw; } if (pszUnicodeString) delete [] pszUnicodeString; if (pszMultiByteString) delete [] pszMultiByteString; }
/********************************************************* GetURL(): Do the wget. *********************************************************/ int GetURL (char *TempFile, char *URL, char *TempFileDir) { char CMD[MAXCMD]; char TaintedURL[MAXCMD]; char TmpLine[256]; int rc; FILE *Fin; #if 1 char WgetArgs[]="--no-check-certificate --progress=dot -rc -np -e robots=off -k"; #else /* wget < 1.10 does not support "--no-check-certificate" */ char WgetArgs[]="--progress=dot"; #endif if (!TaintURL(URL,TaintedURL,MAXCMD)) { printf("FATAL: Failed to parse the URL\n"); printf("LOG: Failed to taint the URL '%s'\n",URL); fflush(stdout); DBclose(DB); exit(10); } memset(CMD,'\0',MAXCMD); /*** Wget options: --progress=dot :: display a new line as it progresses. --no-check-certificate :: download HTTPS files even if the cert cannot be validated. (Neal has many issues with SSL and does not view it as very secure.) Without this, some caching proxies and web sites with old certs won't download. Granted, in theory a bad cert should prevent downloads. In reality, 99.9% of bad certs are because the admin did not notice that they expired and not because of a hijacking attempt. ***/ struct stat sb; int rc_system =0; /* Run from scheduler! delete the temp directory, /var/local/lib/fossology/agents/wget */ if (!stat(TempFileDir, &sb) && TempFile && TempFile[0]) { memset(CMD,'\0',MAXCMD); snprintf(CMD,MAXCMD-1, "rm -rf '%s' 2>&1", TempFileDir); rc_system = system(CMD); if (rc_system != 0) exit(23); // failed to delete the temperary directory } if (TempFile && TempFile[0]) { /* Delete the temp file if it exists */ unlink(TempFile); snprintf(CMD,MAXCMD-1,". %s ; /usr/bin/wget %s -P '%s' '%s' %s 2>&1", PROXYFILE,WgetArgs,TempFileDir,TaintedURL,GlobalParam); } else if(TempFileDir && TempFileDir[0]) { snprintf(CMD,MAXCMD-1,". %s ; /usr/bin/wget %s -P '%s' '%s' %s 2>&1", PROXYFILE,WgetArgs, TempFileDir, TaintedURL, GlobalParam); } else { snprintf(CMD,MAXCMD-1,". %s ; /usr/bin/wget %s '%s' %s 2>&1", PROXYFILE,WgetArgs,TaintedURL, GlobalParam); } Fin = popen(CMD,"r"); if (!Fin) { printf("FATAL upload %ld Failed to retrieve file.\n",GlobalUploadKey); printf("LOG upload %ld Failed to run command: %s\n",GlobalUploadKey,CMD); fflush(stdout); DBclose(DB); exit(11); } while(ReadLine(Fin,TmpLine,256) != -1) { /* Track if a line is read. If this does not change after a minute, then heartbeat will not display. This catches cases where wget hangs. */ InitHeartbeat(); } InitHeartbeat(); rc = pclose(Fin); /* rc is the exit status */ if (WIFEXITED(rc) && (WEXITSTATUS(rc) != 0)) { printf("ERROR upload %ld Download failed\n",GlobalUploadKey); printf("LOG upload %ld Download failed; Return code %d from: %s\n",GlobalUploadKey,WEXITSTATUS(rc),CMD); fflush(stdout); unlink(GlobalTempFile); DBclose(DB); exit(12); } if (WIFEXITED(rc) && WIFSIGNALED(rc)) { printf("ERROR upload %ld Download killed by a signal\n",GlobalUploadKey); printf("LOG upload %ld Download killed by signal %d\n",GlobalUploadKey,WTERMSIG(rc)); fflush(stdout); unlink(GlobalTempFile); DBclose(DB); exit(13); } if (WIFEXITED(rc) && WIFSIGNALED(rc)) { printf("ERROR upload %ld Download killed by a signal\n",GlobalUploadKey); printf("LOG upload %ld Download killed by signal %d\n",GlobalUploadKey,WTERMSIG(rc)); fflush(stdout); unlink(GlobalTempFile); DBclose(DB); exit(14); } /* Run from scheduler! store /var/local/lib/fossology/agents/wget/../<files|directories> to one temp file */ if (TempFile && TempFile[0]) { char TempFilePath[MAXCMD]; memset(TempFilePath,'\0',MAXCMD); /* for one url http://a.org/test.deb, TempFilePath should be /var/local/lib/fossology/agents/wget/a.org/test.deb */ int Position = GetPosition(TaintedURL); if (0 == Position) exit(26); snprintf(TempFilePath, MAXCMD-1, "%s/%s", TempFileDir, TaintedURL + Position); if (!stat(TempFilePath, &sb)) { memset(CMD,'\0',MAXCMD); if (S_ISDIR(sb.st_mode)) { snprintf(CMD,MAXCMD-1, "find '%s' -mindepth 1 -type d -empty -exec rmdir {} \\; > /dev/null 2>&1", TempFilePath); system(CMD); // delete all empty directories downloaded memset(CMD,'\0',MAXCMD); snprintf(CMD,MAXCMD-1, "tar -cvvf '%s' -C '%s' ./ 2>&1", TempFile, TempFilePath); } else { snprintf(CMD,MAXCMD-1, "mv '%s' '%s' 2>&1", TempFilePath, TempFile); } rc_system = system(CMD); if (rc_system != 0) exit(24); // failed to store the temperary directory(one file) as one temperary file } } if (TempFile && TempFile[0] && !IsFile(TempFile,1)) { printf("ERROR upload %ld File %s not created from %s\n",GlobalUploadKey,TempFile,URL); printf("LOG upload %ld File not created from command: %s\n",GlobalUploadKey,CMD); fflush(stdout); DBclose(DB); exit(15); } printf("LOG upload %ld Downloaded %s to %s\n",GlobalUploadKey,URL,TempFile); return(0); } /* GetURL() */
SGD::Rectangle CheckPoint::GetRect(void) const { SGD::Rectangle rect = { GetPosition(), GetSize() }; return rect; }
bool SpaceStation::OnCollision(Object *b, Uint32 flags, double relVel) { if ((flags & 0x10) && (b->IsType(Object::SHIP))) { Ship *s = static_cast<Ship*>(b); matrix4x4d rot; GetRotMatrix(rot); bool canDock = true; int port = -1; for (int i=0; i<MAX_DOCKING_PORTS; i++) { if (m_shipDocking[i].ship == s) { port = i; break; } } if (m_type->dockOneAtATimePlease) { for (int i=0; i<m_type->numDockingPorts; i++) { if (m_shipDocking[i].ship && m_shipDocking[i].stage != 1 && (m_shipDocking[i].stage != m_type->numDockingStages+1)) { canDock = false; break; } } } else { // for non-dockOneAtATimePlease, the ship is expected // to hit the right docking trigger surface for that port if (m_shipDocking[flags&0xf].ship != s) canDock = false; } if (port == -1) canDock = false; // hitting docking area of a station if (canDock) { SpaceStationType::positionOrient_t dport; // why stage 2? Because stage 1 is permission to dock // granted, stage 2 is start of docking animation. PiVerify(m_type->GetDockAnimPositionOrient(port, 2, 0.0f, vector3d(0.0), dport, s)); double speed = s->GetVelocity().Length(); // must be oriented sensibly and have wheels down if (IsGroundStation()) { matrix4x4d shiprot; s->GetRotMatrix(shiprot); matrix4x4d invShipRot = shiprot.InverseOf(); vector3d dockingNormal = rot*dport.yaxis; // check player is sortof sensibly oriented for landing const double dot = vector3d(invShipRot[1], invShipRot[5], invShipRot[9]).Dot(dockingNormal); if ((dot < 0.99) || (s->GetWheelState() < 1.0)) return false; } if ((speed < MAX_LANDING_SPEED) && (!s->GetDockedWith()) && (m_shipDocking[port].stage == 1)) { // if there is more docking port anim to do, // don't set docked yet if (m_type->numDockingStages >= 2) { shipDocking_t &sd = m_shipDocking[port]; sd.ship = s; sd.stage = 2; sd.stagePos = 0; sd.fromPos = rot.InverseOf() * (s->GetPosition() - GetPosition()); matrix4x4d temp; s->GetRotMatrix(temp); sd.fromRot = Quaterniond::FromMatrix4x4(temp); s->Disable(); s->ClearThrusterState(); s->SetFlightState(Ship::DOCKING); } else { s->SetDockedWith(this, port); CreateBB(); Pi::luaOnShipDocked->Queue(s, this); } } } return false; } else { return true; } }
WXLRESULT wxStatusBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { if ( nMsg == WM_WINDOWPOSCHANGING ) { WINDOWPOS *lpPos = (WINDOWPOS *)lParam; int x, y, w, h; GetPosition(&x, &y); GetSize(&w, &h); // we need real window coords and not wx client coords AdjustForParentClientOrigin(x, y); lpPos->x = x; lpPos->y = y; lpPos->cx = w; lpPos->cy = h; return 0; } if ( nMsg == WM_NCLBUTTONDOWN ) { // if hit-test is on gripper then send message to TLW to begin // resizing. It is possible to send this message to any window. if ( wParam == HTBOTTOMRIGHT ) { wxWindow *win; for ( win = GetParent(); win; win = win->GetParent() ) { if ( win->IsTopLevel() ) { SendMessage(GetHwndOf(win), WM_NCLBUTTONDOWN, wParam, lParam); return 0; } } } } if ( nMsg == WM_SIZE ) { MSWUpdateFieldsWidths(); if ( HasFlag(wxSTB_ELLIPSIZE_START) || HasFlag(wxSTB_ELLIPSIZE_MIDDLE) || HasFlag(wxSTB_ELLIPSIZE_END) ) { for (int i=0; i<GetFieldsCount(); i++) { // re-set the field text, in case we need to ellipsize // (or de-ellipsize) some parts of it DoUpdateStatusText(i); } } } return wxStatusBarBase::MSWWindowProc(nMsg, wParam, lParam); }
wxObject *wxToolBarAddOnXmlHandler::DoCreateResource() { wxToolBar* toolbar=NULL; if (m_class == _T("tool")) { wxCHECK_MSG(m_toolbar, NULL, _("Incorrect syntax of XRC resource: tool not within a toolbar!")); wxSize bitmapSize = m_toolbar->GetToolBitmapSize(); if (GetPosition() != wxDefaultPosition) { m_toolbar->AddTool(GetID(), #if wxCHECK_VERSION(2, 9, 0) wxEmptyString, #endif GetCenteredBitmap(_T("bitmap"), wxART_TOOLBAR, bitmapSize), GetCenteredBitmap(_T("bitmap2"), wxART_TOOLBAR, bitmapSize), #if !wxCHECK_VERSION(2, 9, 0) GetBool(_T("toggle")), GetPosition().x, GetPosition().y, NULL, #else wxITEM_NORMAL, #endif GetText(_T("tooltip")), GetText(_T("longhelp"))); if (GetBool(_T("disabled"))) { m_toolbar->Realize(); m_toolbar->EnableTool(GetID(),false); } } else { wxItemKind kind = wxITEM_NORMAL; if (GetBool(_T("radio"))) kind = wxITEM_RADIO; if (GetBool(_T("toggle"))) { wxASSERT_MSG( kind == wxITEM_NORMAL, _("can't have both toggleable and radion button at once") ); kind = wxITEM_CHECK; } m_toolbar->AddTool(GetID(), GetText(_T("label")), GetCenteredBitmap(_T("bitmap"), wxART_TOOLBAR, bitmapSize), GetCenteredBitmap(_T("bitmap2"), wxART_TOOLBAR, bitmapSize), kind, GetText(_T("tooltip")), GetText(_T("longhelp"))); if (GetBool(_T("disabled"))) { m_toolbar->Realize(); m_toolbar->EnableTool(GetID(),false); } } return m_toolbar; // must return non-NULL } else if (m_class == _T("separator")) { wxCHECK_MSG(m_toolbar, NULL, _("Incorrect syntax of XRC resource: separator not within a toolbar!")); m_toolbar->AddSeparator(); return m_toolbar; // must return non-NULL } else /*<object class="wxToolBar">*/ { m_isAddon=(m_class == _T("wxToolBarAddOn")); if(m_isAddon) { // special case: Only add items to toolbar toolbar=(wxToolBar*)m_instance; // XRC_MAKE_INSTANCE(toolbar, wxToolBar); } else { int style = GetStyle(_T("style"), wxNO_BORDER | wxTB_HORIZONTAL); #ifdef __WXMSW__ if (!(style & wxNO_BORDER)) style |= wxNO_BORDER; #endif XRC_MAKE_INSTANCE(toolbar, wxToolBar) toolbar->Create(m_parentAsWindow, GetID(), GetPosition(), GetSize(), style, GetName()); wxSize bmpsize = GetSize(_T("bitmapsize")); if (!(bmpsize == wxDefaultSize)) toolbar->SetToolBitmapSize(bmpsize); wxSize margins = GetSize(_T("margins")); if (!(margins == wxDefaultSize)) toolbar->SetMargins(margins.x, margins.y); long packing = GetLong(_T("packing"), -1); if (packing != -1) toolbar->SetToolPacking(packing); long separation = GetLong(_T("separation"), -1); if (separation != -1) toolbar->SetToolSeparation(separation); prepend.Clear(); append.Clear(); } wxXmlNode *children_node = GetParamNode(_T("object")); if (!children_node) children_node = GetParamNode(_T("object_ref")); if (children_node == NULL) return toolbar; m_isInside = TRUE; m_toolbar = toolbar; wxXmlNode *n = children_node; while (n) { if ((n->GetType() == wxXML_ELEMENT_NODE) && (n->GetName() == _T("object") || n->GetName() == _T("object_ref"))) { wxObject *created = CreateResFromNode(n, toolbar, NULL); wxControl *control = wxDynamicCast(created, wxControl); if (!IsOfClass(n, _T("tool")) && !IsOfClass(n, _T("separator")) && control != NULL && control != toolbar) { //Manager::Get()->GetLogManager()->DebugLog(F(_T("control=%p, parent=%p, toolbar=%p"), control, control->GetParent(), toolbar)); toolbar->AddControl(control); } } n = n->GetNext(); } toolbar->Realize(); toolbar->SetCustomOverflowItems( prepend, append); m_isInside = FALSE; m_toolbar = NULL; if(!m_isAddon) { if (m_parentAsWindow && !GetBool(_T("dontattachtoframe"))) { wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame); if (parentFrame) parentFrame->SetToolBar(toolbar); } } m_isAddon=false; return toolbar; } }
Ogre::Vector2 UserInterfaceComponent::GetScreenPosition() const { return GetOffsetPosition() + GetPosition(); }
wxObject *wxAuiToolBarXmlHandler::DoCreateResource() { wxAuiToolBar* toolbar=NULL; if (m_class == _T("tool")) { wxCHECK_MSG(m_toolbar, NULL, _("Incorrect syntax of XRC resource: tool not within a toolbar!")); wxSize bitmapSize = m_toolbar->GetToolBitmapSize(); if (GetPosition() != wxDefaultPosition) { m_toolbar->AddTool(GetID(), GetCenteredBitmap(_T("bitmap"), wxART_OTHER, wxSize(16,16)), NULL, //GetCenteredBitmap(_T("bitmap2"), wxART_TOOLBAR, bitmapSize), GetBool(_T("toggle")), NULL, GetText(_T("tooltip")), GetText(_T("longhelp"))); if (GetBool(_T("disabled"))) { m_toolbar->Realize(); m_toolbar->EnableTool(GetID(),false); } } else { wxItemKind kind = wxITEM_NORMAL; if (GetBool(_T("radio"))) kind = wxITEM_RADIO; if (GetBool(_T("toggle"))) { wxASSERT_MSG( kind == wxITEM_NORMAL, _("can't have both toggleable and radion button at once") ); kind = wxITEM_CHECK; } m_toolbar->AddTool(GetID(), GetText(_T("label")), GetCenteredBitmap(_T("bitmap"), wxART_OTHER, bitmapSize), GetCenteredBitmap(_T("bitmap2"), wxART_OTHER, bitmapSize), kind, GetText(_T("tooltip")), GetText(_T("longhelp"))); if (GetBool(_T("disabled"))) { m_toolbar->Realize(); m_toolbar->EnableTool(GetID(),false); } } return m_toolbar; // must return non-NULL } else if (m_class == _T("overflow_tool")) { wxCHECK_MSG(m_toolbar, NULL, _("Incorrect syntax of XRC resource: tool not within a toolbar!")); wxSize bitmapSize = m_toolbar->GetToolBitmapSize(); wxItemKind kind = wxITEM_NORMAL; if (GetBool(_T("radio"))) kind = wxITEM_RADIO; if (GetBool(_T("toggle"))) { wxASSERT_MSG( kind == wxITEM_NORMAL, _("can't have both toggleable and radion button at once") ); kind = wxITEM_CHECK; } if (GetBool(_T("separator"))) kind = wxITEM_SEPARATOR; m_toolbar->AddOverflowTool(GetID(), GetText(_T("label")), GetCenteredBitmap(_T("bitmap"), wxART_OTHER, bitmapSize), GetText(_T("longhelp")), kind, GetBool(_T("prepend"),0) ); if (GetBool(_T("disabled"))) { m_toolbar->Realize(); m_toolbar->EnableTool(GetID(),false); } return m_toolbar; // must return non-NULL } else if (m_class == _T("separator")) { wxCHECK_MSG(m_toolbar, NULL, _("Incorrect syntax of XRC resource: separator not within a toolbar!")); m_toolbar->AddSeparator(); return m_toolbar; // must return non-NULL } else /*<object class="wxAuiToolBar">*/ { toolbar=(wxAuiToolBar*)m_instance; if(!toolbar && (m_class == _T("wxToolBarAddOn"))) { toolbar = new wxAuiToolBar(m_parentAsWindow, -1, wxDefaultPosition, wxDefaultSize); m_instance = (wxObject *)toolbar; } long style = GetStyle(_T("style"), -1); if (style!=-1) toolbar->SetWindowStyle(style); style = GetStyle(_T("add_style"), -1); if (style!=-1) toolbar->SetWindowStyle(toolbar->GetWindowStyle() | style); style = GetStyle(_T("remove_style"), -1); if (style!=-1) toolbar->SetWindowStyle(toolbar->GetWindowStyle() & ~style); wxSize bmpsize = GetSize(_T("bitmapsize")); // First find the generic bitmap size if (!(bmpsize == wxDefaultSize)) toolbar->SetToolBitmapSize(bmpsize); else { // if no generic size then find the platform dependent size #ifdef __WXMSW__ bmpsize = GetSize(_T("bitmapsize_win")); #endif #ifdef __WXMAC__ bmpsize = GetSize(_T("bitmapsize_mac")); #endif #ifdef __WXGTK__ bmpsize = GetSize(_T("bitmapsize_unix")); #endif if (!(bmpsize == wxDefaultSize)) toolbar->SetToolBitmapSize(bmpsize); } wxSize margins = GetSize(_T("margins")); if (!(margins == wxDefaultSize)) toolbar->SetMargins(margins.x, margins.y); long packing = GetLong(_T("packing"), -1); if (packing != -1) toolbar->SetToolPacking(packing); long separation = GetLong(_T("separation"), -1); if (separation != -1) toolbar->SetToolSeparation(separation); wxXmlNode *children_node = GetParamNode(_T("object")); if (!children_node) children_node = GetParamNode(_T("object_ref")); if (children_node == NULL) return toolbar; m_isInside = TRUE; m_toolbar = toolbar; wxXmlNode *n = children_node; while (n) { if ((n->GetType() == wxXML_ELEMENT_NODE) && (n->GetName() == _T("object") || n->GetName() == _T("object_ref"))) { wxObject *created = CreateResFromNode(n, toolbar, NULL); wxControl *control = wxDynamicCast(created, wxControl); if (!IsOfClass(n, _T("tool")) && !IsOfClass(n, _T("separator")) && control != NULL && control != toolbar) { //Manager::Get()->GetLogManager()->DebugLog(F(_T("control=%p, parent=%p, toolbar=%p"), control, control->GetParent(), toolbar)); toolbar->AddControl(control); } } n = n->GetNext(); } toolbar->Realize(); m_isInside = FALSE; m_toolbar = NULL; m_isAddon=false; return toolbar; } }
/* * New media loaded. Check if data in buffers * is validate and can be reused. */ static void checkBuffers( char *new_vsn) { u_longlong_t currentPos; /* If first request for this thread, allocate buffers. */ if (IoThread->io_numBuffers == 0) { allocBuffers(); strcpy(Instance->ci_vsn, new_vsn); return; } /* If disk archiving, invalidate buffers. */ if (IoThread->io_flags & IO_diskArchiving) { ResetBuffers(); IoThread->io_position = 0; strcpy(Instance->ci_vsn, new_vsn); return; } /* Get current position of removable media file. */ currentPos = GetPosition(); Trace(TR_FILES, "Get position %lld block size %d", currentPos, GetBlockSize()); /* * If we loaded the same VSN as last time this proc was * active, the buffers may be valid and thus data in the buffers * can be reused. If this is not the same VSN, invalidate * the buffers and save VSN label in the thread's context. */ if (strcmp(Instance->ci_vsn, new_vsn) != 0) { int blockSize; /* * New media. If block size has changed set new mau * information. If necessary, reallocate buffers based * on the new block size. */ blockSize = GetBlockSize(); if (IoThread->io_blockSize != blockSize) { freeBuffers(); allocBuffers(); } else { ResetBuffers(); } strcpy(Instance->ci_vsn, new_vsn); } else if (IoThread->io_position != currentPos) { /* * The last known media position does not match the * removable media file's position. Since the position has * changed, buffers must be invalidated. */ ResetBuffers(); } /* * Archive read thread needs mount position to maintain * position on the media. */ IoThread->io_position = currentPos; }
bool WaveReader::LoadAllChunks(nsAutoPtr<nsHTMLMediaElement::MetadataTags> &aTags) { // Chunks are always word (two byte) aligned. NS_ABORT_IF_FALSE(mDecoder->GetResource()->Tell() % 2 == 0, "LoadAllChunks called with unaligned resource"); bool loadFormatChunk = false; bool findDataOffset = false; for (;;) { static const unsigned int CHUNK_HEADER_SIZE = 8; char chunkHeader[CHUNK_HEADER_SIZE]; const char* p = chunkHeader; if (!ReadAll(chunkHeader, sizeof(chunkHeader))) { return false; } PR_STATIC_ASSERT(sizeof(uint32_t) * 2 <= CHUNK_HEADER_SIZE); uint32_t magic = ReadUint32BE(&p); uint32_t chunkSize = ReadUint32LE(&p); int64_t chunkStart = GetPosition(); switch (magic) { case FRMT_CHUNK_MAGIC: loadFormatChunk = LoadFormatChunk(chunkSize); if (!loadFormatChunk) { return false; } break; case LIST_CHUNK_MAGIC: if (!aTags) { LoadListChunk(chunkSize, aTags); } break; case DATA_CHUNK_MAGIC: findDataOffset = FindDataOffset(chunkSize); return loadFormatChunk && findDataOffset; default: break; } // RIFF chunks are two-byte aligned, so round up if necessary. chunkSize += chunkSize % 2; // Move forward to next chunk CheckedInt64 forward = CheckedInt64(chunkStart) + chunkSize - GetPosition(); if (!forward.isValid() || forward.value() < 0) { return false; } static const int64_t MAX_CHUNK_SIZE = 1 << 16; PR_STATIC_ASSERT(uint64_t(MAX_CHUNK_SIZE) < UINT_MAX / sizeof(char)); nsAutoArrayPtr<char> chunk(new char[MAX_CHUNK_SIZE]); while (forward.value() > 0) { int64_t size = std::min(forward.value(), MAX_CHUNK_SIZE); if (!ReadAll(chunk.get(), size)) { return false; } forward -= size; } } return false; }
PRectangle Window::GetClientPosition() { return GetPosition(); }
void cHorse::OnRightClicked(cPlayer & a_Player) { super::OnRightClicked(a_Player); if (m_bIsTame) { if (a_Player.IsCrouched()) { PlayerOpenWindow(a_Player); return; } auto EquipedItemType = a_Player.GetEquippedItem().m_ItemType; if ( !IsSaddled() && ( (EquipedItemType == E_ITEM_SADDLE) || ItemCategory::IsHorseArmor(EquipedItemType) ) ) { // Player is holding a horse inventory item, open the window: PlayerOpenWindow(a_Player); } else { a_Player.AttachTo(this); } } else if (a_Player.GetEquippedItem().IsEmpty()) { // Check if leashed / unleashed to player before try to ride if (!m_IsLeashActionJustDone) { if (m_Attachee != nullptr) { if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID()) { a_Player.Detach(); return; } if (m_Attachee->IsPlayer()) { return; } m_Attachee->Detach(); } m_TameAttemptTimes++; a_Player.AttachTo(this); } } else { m_bIsRearing = true; m_RearTickCount = 0; m_World->BroadcastSoundEffect("entity.horse.angry", GetPosition(), 1.0f, 0.8f); } }
void COthelloView::OnLButtonDown(UINT nFlags, CPoint point) { CClientDC dc(this); COthelloDoc *pDoc=GetDocument(); if (m_Current>=0 && (pDoc->m_MainTable).GetTable(m_Current)<1) { if (m_CurPlay==T_BLACK && (pDoc->m_MainTable).IsDown(m_CurCol,m_CurRow,T_BLACK)) { BiltBitmap(m_CurX,m_CurY,m_CurX+33,m_CurY+33,m_hBlack); (pDoc->m_MainTable).SetTable(m_Current,T_BLACK); DrawTable(m_CurCol,m_CurRow,T_BLACK); if (!(pDoc->m_MainTable).HaveDown(T_WHITE)) { if (!(pDoc->m_MainTable).HaveDown(T_BLACK)) { pDoc->GameOver(); } else { MessageBox("White Pass!!!"); m_CurPlay=T_BLACK; } } else { ::SetClassLong(GetSafeHwnd(),GCL_HCURSOR,NULL); SetCursor(m_hcurWhite); cont: CPoint point,pos; point=pDoc->TryIt(T_WHITE,T_DEPTH); (pDoc->m_MainTable).SetTable(point.x,point.y,T_WHITE); pos=GetPosition(point.x,point.y); //MessageBeep(MB_ICONINFORMATION); BiltBitmap(pos.x,pos.y,pos.x+33,pos.y+33,m_hWhite); Sleep(100); dc.FillSolidRect(pos.x,pos.y,34,34,m_NormalColor); Sleep(100); BiltBitmap(pos.x,pos.y,pos.x+33,pos.y+33,m_hWhite); Sleep(100); dc.FillSolidRect(pos.x,pos.y,34,34,m_NormalColor); Sleep(100); BiltBitmap(pos.x,pos.y,pos.x+33,pos.y+33,m_hWhite); DrawTable(point.x,point.y,T_WHITE); m_CurPlay=T_BLACK; if (!(pDoc->m_MainTable).HaveDown(T_BLACK)) { if (!(pDoc->m_MainTable).HaveDown(T_WHITE)) { pDoc->GameOver(); } else { MessageBox("Black Pass!!!"); m_CurPlay=T_WHITE; goto cont; } } } ::SetClassLong(GetSafeHwnd(),GCL_HCURSOR,NULL); SetCursor(m_hcurDefault); DispDown(pDoc,&dc); } else { if (m_CurPlay==T_WHITE && (pDoc->m_MainTable).IsDown(m_CurCol,m_CurRow,T_WHITE)) { BiltBitmap(m_CurX,m_CurY,m_CurX+33,m_CurY+33,m_hWhite); (pDoc->m_MainTable).SetTable(m_Current,T_WHITE); DrawTable(m_CurCol,m_CurRow,T_WHITE); if (!(pDoc->m_MainTable).HaveDown(T_BLACK)) { if (!(pDoc->m_MainTable).HaveDown(T_WHITE)) { MessageBox("Game Over!!!"); } else { MessageBox("No!!!"); m_CurPlay=T_WHITE; } } else { m_CurPlay=T_BLACK; } ::SetClassLong(GetSafeHwnd(),GCL_HCURSOR,NULL); SetCursor(m_hcurDefault); } } } // TODO: Add your message handler code here and/or call default CView::OnLButtonDown(nFlags, point); }
void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); if (!IsTicking()) { // The base class tick destroyed us return; } auto & Random = GetRandomProvider(); if (!m_bIsMouthOpen) { if (Random.RandBool(0.02)) { m_bIsMouthOpen = true; } } else { if (Random.RandBool(0.10)) { m_bIsMouthOpen = false; } } if ((m_Attachee != nullptr) && (!m_bIsTame)) { if (m_TameAttemptTimes < m_TimesToTame) { if (Random.RandBool(0.02)) { m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, GetPosition().Floor(), int(SmokeDirection::SOUTH_EAST)); m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, GetPosition().Floor(), int(SmokeDirection::SOUTH_WEST)); m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, GetPosition().Floor(), int(SmokeDirection::NORTH_EAST)); m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, GetPosition().Floor(), int(SmokeDirection::NORTH_WEST)); m_World->BroadcastSoundEffect("entity.horse.angry", GetPosition(), 1.0f, 1.0f); m_Attachee->Detach(); m_bIsRearing = true; } } else { m_World->BroadcastParticleEffect("heart", static_cast<Vector3f>(GetPosition()), Vector3f{}, 0, 5); m_bIsTame = true; } } if (m_bIsRearing) { if (m_RearTickCount == 20) { m_bIsRearing = false; m_RearTickCount = 0; } else { m_RearTickCount++; } } m_World->BroadcastEntityMetadata(*this); }
// pos is relative, method returns absolute coords Pos Widget::GetAbsolutePos(const Pos &pos ) const { Pos offset = GetPosition(); offset = _parent->GetAbsolutePos(offset); return pos + offset; }
// These functions are overloaded from cObject void cTextBox::Initialize() { m_Data.setPosition(GetPosition().x + 4, GetPosition().y + 4); }
bool wxStackedColumnChart::Column::HitTest(const wxPoint &point) const { return ((point.x >= GetPosition().m_x) && (point.x <= (GetPosition().m_x + GetWidth()))); }
void CText::RenderPut(const CCanvas* canvas) { RenderPut(canvas, CRectangle(GetPosition(), GetCanvas()->GetDimension()), GetCanvas()->GetDimension()); }
// get the origin of the client area in the client coordinates wxPoint wxRadioBox::GetClientAreaOrigin() const { return GetPosition(); }
void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { if (m_IsInGround) { // Already-grounded projectiles don't move at all return; } const Vector3d PerTickSpeed = GetSpeed() / 20; const Vector3d Pos = GetPosition(); const Vector3d NextPos = Pos + PerTickSpeed; // Test for entity collisions: cProjectileEntityCollisionCallback EntityCollisionCallback(this, Pos, NextPos); a_Chunk.ForEachEntity(EntityCollisionCallback); if (EntityCollisionCallback.HasHit()) { // An entity was hit: Vector3d HitPos = Pos + (NextPos - Pos) * EntityCollisionCallback.GetMinCoeff(); // DEBUG: LOGD("Projectile %d has hit an entity %d (%s) at {%.02f, %.02f, %.02f} (coeff %.03f)", m_UniqueID, EntityCollisionCallback.GetHitEntity()->GetUniqueID(), EntityCollisionCallback.GetHitEntity()->GetClass(), HitPos.x, HitPos.y, HitPos.z, EntityCollisionCallback.GetMinCoeff() ); OnHitEntity(*(EntityCollisionCallback.GetHitEntity()), HitPos); } // TODO: Test the entities in the neighboring chunks, too // Trace the tick's worth of movement as a line: cProjectileTracerCallback TracerCallback(this); if (!cLineBlockTracer::Trace(*m_World, TracerCallback, Pos, NextPos)) { // Something has been hit, abort all other processing return; } // The tracer also checks the blocks for slowdown blocks - water and lava - and stores it for later in its SlowdownCoeff // Update the position: SetPosition(NextPos); // Add slowdown and gravity effect to the speed: Vector3d NewSpeed(GetSpeed()); NewSpeed.y += m_Gravity / 20; NewSpeed *= TracerCallback.GetSlowdownCoeff(); SetSpeed(NewSpeed); SetYawFromSpeed(); SetPitchFromSpeed(); /* LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, speed {%.02f, %.02f, %.02f}, rot {%.02f, %.02f}", m_UniqueID, GetPosX(), GetPosY(), GetPosZ(), GetSpeedX(), GetSpeedY(), GetSpeedZ(), GetYaw(), GetPitch() ); */ }