Пример #1
0
void Gamepad::getJoystickValues(unsigned int joystickId, kmVec2* outValue) const
{
    if (joystickId >= _joystickCount)
        return;

    if (_form)
    {
        JoystickControl* joystick = _uiJoysticks[joystickId];
        if (joystick)
        {
            const kmVec2& value = joystick->getValue();
            //outValue->set(value.x, value.y);
			kmVec2Fill(outValue, value.x, value.y);
        }
        else
        {
            //outValue->set(0.0f, 0.0f);
			kmVec2Fill(outValue, 0.0f, 0.0f);
        }
    }
    else
    {
        //outValue->set(_joysticks[joystickId]);
		kmVec2Fill(outValue, _joysticks[joystickId].x, _joysticks[joystickId].y);
    }
}
Пример #2
0
bool CTextureAtlas::Load()
{
    BEATS_ASSERT(!IsLoaded());

    TString fileext = CFilePathTool::GetInstance()->Extension(GetFilePath().c_str());
    if(fileext == _T(".xml"))
    {
        TiXmlDocument doc;
        CSerializer serializer;
        CFilePathTool::GetInstance()->LoadFile(&serializer, GetFilePath().c_str(), _T("rb"));
        if (serializer.GetWritePos() != serializer.GetReadPos())
        {
            doc.Parse((char*)serializer.GetReadPtr());
        }
        TiXmlElement *root = doc.RootElement();
        BEATS_ASSERT(root && strcmp(root->Value(), "Imageset") == 0, 
            _T("TextureAtlas file %s not found or incorrect!"), GetFilePath().c_str());

        const char *textureFile = root->Attribute("Imagefile");
        BEATS_ASSERT(textureFile);
        TCHAR szNameBuffer[MAX_PATH];
        CStringHelper::GetInstance()->ConvertToTCHAR(textureFile, szNameBuffer, MAX_PATH);
        m_texture = CResourceManager::GetInstance()->GetResource<CTexture>(szNameBuffer);
        kmVec2 size;
        kmVec2 point;
        TString strName;
        for(TiXmlElement *elemImage = root->FirstChildElement("Image");
            elemImage != nullptr; elemImage = elemImage->NextSiblingElement("Image"))
        {
            const char *name = elemImage->Attribute("Name");
            BEATS_ASSERT(name);
            kmVec2Fill(&point, 0.f, 0.f);
            kmVec2Fill(&size, 0.f, 0.f);
            elemImage->QueryFloatAttribute("XPos", &point.x);
            elemImage->QueryFloatAttribute("YPos", &point.y);
            elemImage->QueryFloatAttribute("Width", &size.x);
            elemImage->QueryFloatAttribute("Height", &size.y);

            CStringHelper::GetInstance()->ConvertToTCHAR(name, szNameBuffer, MAX_PATH);
            strName.assign(szNameBuffer);
            CreateTextureFrag(strName, point, size);
        }
    }
    else
    {
        m_texture = CResourceManager::GetInstance()->GetResource<CTexture>(GetFilePath());
    }

    m_name = CFilePathTool::GetInstance()->FileName(GetFilePath().c_str());
    super::Load();
    return true;
}
Пример #3
0
void CTexturePreviewDialog::LoadInfoFromFile(wxString& fileName)
{
    wxString path, simpleName, ext;
    wxFileName::SplitPath(fileName, &path, &simpleName, &ext);
    TiXmlDocument doc;
    doc.LoadFile(fileName);
    TiXmlElement *root = doc.RootElement();
    BEATS_ASSERT(root && strcmp(root->Value(), "Imageset") == 0);
    const char *textureFileName = root->Attribute("Imagefile");
    BEATS_ASSERT(textureFileName != NULL);
    path += _T("\\");

    wxBitmap texture;
    {
        //suppress the warning from loading png
        wxLogNull logNo;
        texture.LoadFile(path + textureFileName, wxBITMAP_TYPE_PNG);
    }

    for(TiXmlElement *elemImage = root->FirstChildElement("Image");
        elemImage != nullptr; elemImage = elemImage->NextSiblingElement("Image"))
    {
        const char *textureName = elemImage->Attribute("Name");
        BEATS_ASSERT(textureName);
        kmVec2 point;
        kmVec2Fill(&point, 0.f, 0.f);
        kmVec2 size;
        kmVec2Fill(&size, 0.f, 0.f);
        elemImage->QueryFloatAttribute("XPos", &point.x);
        elemImage->QueryFloatAttribute("YPos", &point.y);
        elemImage->QueryFloatAttribute("Width", &size.x);
        elemImage->QueryFloatAttribute("Height", &size.y);

        wxRect rect(point.x, point.y, size.x, size.y);
        wxIcon icon;
        icon.CopyFromBitmap(texture.GetSubBitmap(rect));
        m_pTexturePreviewIconList->Add(icon);
        TexturePreviewInfo info;
        info.fileName = simpleName + _T(".") + ext;
        info.textureName = textureName;
        info.with.Printf(_T("%d"), rect.GetWidth());
        info.height.Printf(_T("%d"), rect.GetHeight());
        m_texturePreviewInfoList.push_back(info);
    }

    BEATS_ASSERT(m_pTexturePreviewIconList->GetImageCount() == (int)m_texturePreviewInfoList.size());
}
Пример #4
0
void Gamepad::setJoystickValue(unsigned int index, float x, float y)
{
    if (_joysticks[index].x != x || _joysticks[index].y != y)
    {
        //_joysticks[index].set(x, y);
		kmVec2Fill(&_joysticks[index], x, y);
        Form::gamepadJoystickEventInternal(this, index);
    }
}
Пример #5
0
    void create_floor_plane(SDuint world) {
        kmVec2 points[6];

        kmVec2Fill(&points[0], -10.0f, 0.0f);
        kmVec2Fill(&points[1], -10.0f, -1.0f);
        kmVec2Fill(&points[2], 10.0f, 0.0f);

        kmVec2Fill(&points[3], 10.0f, 0.0f);
        kmVec2Fill(&points[4], -10.0f, -1.0f);
        kmVec2Fill(&points[5], 10.0f, -1.0f);

        sdWorldAddMesh(world, 2, points);
    }
Пример #6
0
    void build_world() {
        sonic = sdCharacterCreate(world);

        sdObjectSetPosition(sonic, 3.0f, 3.0f);
        create_floor_plane(world);

        /*kmVec2 slope[3];
        kmVec2Fill(&slope[0], 3.0f, 0.0f);
        kmVec2Fill(&slope[1], 10.0f, 0.0f);
        kmVec2Fill(&slope[2], 10.0f, 3.0f);
        sdWorldAddTriangle(world, slope);*/

        kmVec2 wall[4];

        kmVec2Fill(&wall[0], -10.0f, 0.0f);
        kmVec2Fill(&wall[1], -5.0f, 0.0f);
        kmVec2Fill(&wall[2], -5.0f, 5.0f);
        kmVec2Fill(&wall[3], -10.0f, 5.0f);
        sdWorldAddBox(world, wall);

        /*kmVec2 platform[4];
        kmVec2Fill(&platform[0], 1.0f, 1.5f);
        kmVec2Fill(&platform[1], 3.0f, 1.5f);
        kmVec2Fill(&platform[2], 3.0f, 2.0f);
        kmVec2Fill(&platform[3], 1.0f, 2.0f);
        sdWorldAddBox(world, platform);*/

        box = sdBoxCreate(world, 1.0, 1.0);
        sdObjectSetPosition(box, -4.5f, 0.5f);


     /*   spring2 = sdSpringCreate(world, -45.0f, 10.0f/40.0f);
        sdObjectSetPosition(spring2, 2.0f, 2.25f);*/

        kmVec2 triangle[3];
        kmVec2Fill(&triangle[0], 5, 0);
        kmVec2Fill(&triangle[1], 10, 0);
        kmVec2Fill(&triangle[2], 10, 2);
        sdWorldAddTriangle(world, triangle);

        //sdWorldConstructLoop(world, 4.0f, 8.0f, 8.0f);

        sdWorldSetObjectCollisionCallback(world, &collision_response_thunk, this);
    }
Пример #7
0
void CUIViewAgent::ProcessMouseEvent( wxMouseEvent& event )
{
    __super::ProcessMouseEvent(event);
    
    wxPoint MousePos = event.GetPosition();
    CRenderTarget* pRenderWnd = CRenderManager::GetInstance()->GetCurrentRenderTarget();
    wxGLRenderWindow* pSceneRenderWnd = down_cast<wxGLRenderWindow*>(pRenderWnd);
    BEATS_ASSERT(pSceneRenderWnd != NULL);
    float fScale = pSceneRenderWnd->IsFBOInUse() ? (float)pSceneRenderWnd->GetFBOViewPortWidth() / pSceneRenderWnd->GetWidth() : pSceneRenderWnd->GetScaleFactor();

    MousePos.x /= fScale;
    MousePos.y /= fScale;
    if(event.ButtonDown(wxMOUSE_BTN_LEFT))
    {
        if (m_pMainFrame->m_nCursorIconID == wxCURSOR_ARROW)
        {
            CComponentBase* pSelectedComponent = CWindowManager::GetInstance()->GetControl(MousePos.x, MousePos.y);
            CComponentProxy* pProxy = NULL;
            if (pSelectedComponent)
            {
                pProxy = (CComponentProxy*)CComponentProxyManager::GetInstance()->GetComponentInstance(pSelectedComponent->GetId(), pSelectedComponent->GetGuid());
            }

            if (m_pMainFrame->m_pSelectedComponentProxy != pProxy)
            {
                m_pMainFrame->SelectComponent(pProxy);
            }
        }

        if (m_pMainFrame->m_pSelectedComponentProxy != NULL)
        {
            kmVec2 kmVec2Pos;
            kmVec2Fill(&kmVec2Pos, 0, 0);
            ((CControl*)m_pMainFrame->m_pSelectedComponentProxy->GetHostComponent())->LocalToWorld(kmVec2Pos.x, kmVec2Pos.y);
            m_pMainFrame->m_activeGUIPosOffset = wxPoint(kmVec2Pos.x - MousePos.x, kmVec2Pos.y - MousePos.y);
        }
        UpdateCursorIcon(MousePos);
        ((wxWindow*)m_pMainFrame->m_pViewScreen)->SetCursor(m_pMainFrame->m_nCursorIconID);
    }
    else if(event.ButtonDown(wxMOUSE_BTN_RIGHT))
    {
        m_pMainFrame->SelectComponent(NULL);
        UpdateCursorIcon(MousePos);
        ((wxWindow*)m_pMainFrame->m_pViewScreen)->SetCursor(m_pMainFrame->m_nCursorIconID);
    }
    else if(event.Dragging())
    {
        if (m_pMainFrame->m_pSelectedComponentProxy)
        {
            wxString propertyName;
            int nHitTestRet = m_pMainFrame->m_nHitTestRet;
            if (nHitTestRet == CControl::eHTR_HIT_CONTENT || nHitTestRet == CControl::eHTR_HIT_EDGE)
            {
                propertyName = _T("m_pos");
            }
            else if (nHitTestRet > CControl::eHTR_HIT_CONTENT && nHitTestRet < CControl::eHTR_HIT_ANCHOR)
            {
                propertyName = _T("m_vecSize");
            }
            else
            {
                propertyName = _T("");
            }

            if (!propertyName.IsEmpty())
            {
                CWxwidgetsPropertyBase* pPropertyDescription = static_cast<CWxwidgetsPropertyBase*>(m_pMainFrame->m_pSelectedComponentProxy->GetPropertyDescription(propertyName));
                BEATS_ASSERT(pPropertyDescription != NULL);
                CControl* pWindow = dynamic_cast<CControl*>(m_pMainFrame->m_pSelectedComponentProxy->GetHostComponent());
                BEATS_ASSERT(pWindow != NULL);
                if (nHitTestRet == CControl::eHTR_HIT_CONTENT || nHitTestRet == CControl::eHTR_HIT_EDGE)
                {
                    kmScalar posX = MousePos.x + m_pMainFrame->m_activeGUIPosOffset.x;
                    kmScalar posY = MousePos.y + m_pMainFrame->m_activeGUIPosOffset.y;
                    kmVec2 pos = pWindow->CalcPosFromMouse(posX, posY);
                    SetkmVec2PropertyValue(pPropertyDescription, pos);
                }
                else if (nHitTestRet > CControl::eHTR_HIT_CONTENT && nHitTestRet < CControl::eHTR_HIT_ANCHOR)
                {
                    kmVec2 size = pWindow->CalcSizeFromMouse(MousePos.x, MousePos.y, (CControl::EHitTestResult)nHitTestRet);
                    SetkmVec2PropertyValue(pPropertyDescription, size);
                }
            }
        }
    }
    else if(event.Moving())
    {
        UpdateCursorIcon(MousePos);
    }
}