Ejemplo n.º 1
0
void BitmapFont::loadRange(Image spriteSheet, char32_t start, char32_t end)
{
	int width = spriteSheet.getSize().X;
	int height = spriteSheet.getSize().Y;
	int numChar = (end - start) + 1;
	int widthPerChar = width / numChar;
	for(int i = 0; i < numChar; ++i)
		LoadedCharacters[start + i].Sprite = spriteSheet.cut(Vec2I(widthPerChar*i, 0), Vec2I(widthPerChar, height));
}
Ejemplo n.º 2
0
	void NumericUpDown::InitializeButtons()
	{
		//mDown = (Button*)AddChild(0.0, 0.0, 0.33333f, 1.0f, ComponentType::Button);
		assert(mDown.expired());
		auto down = std::static_pointer_cast<Button>(AddChild(ComponentType::Button));
		mDown = down;
		down->SetName("down");
		down->SetRuntimeChild(true);


		//mUp = (Button*)AddChild(1.0, 0.0, 0.33333f, 1.0f, ComponentType::Button);
		auto up = std::static_pointer_cast<Button>(AddChild(ComponentType::Button));
		mUp = up;
		up->SetName("up");
		up->SetRuntimeChild(true);

		down->ChangeSize(Vec2I(20, 20));
		down->ChangeNPos(Vec2(0, 0));
		down->SetUseAbsPos(false);

		down->SetProperty(UIProperty::REGION, "DownTriangle");
		down->SetProperty(UIProperty::IMAGE_COLOR_OVERLAY, "1, 1, 0, 1");
		down->SetProperty(UIProperty::NO_BACKGROUND, "true");
		down->RegisterEventFunc(UIEvents::EVENT_MOUSE_LEFT_CLICK,
				std::bind(&NumericUpDown::OnDown, this, std::placeholders::_1));
		down->SetEnable(mValue > mMin && mEnable);

		up->ChangeSize(Vec2I(20, 20));
		up->ChangeNPos(Vec2(1, 0));
		up->SetUseAbsPos(false);
		up->SetProperty(UIProperty::REGION, "UpTriangle");
		up->SetProperty(UIProperty::IMAGE_COLOR_OVERLAY, "1, 1, 0, 1");
		up->SetProperty(UIProperty::ALIGNH, "right");
		up->SetProperty(UIProperty::NO_BACKGROUND, "true");
		up->RegisterEventFunc(UIEvents::EVENT_MOUSE_LEFT_CLICK,
				std::bind(&NumericUpDown::OnUp, this, std::placeholders::_1));
		up->SetEnable(mValue < mMax && mEnable);

		SetProperty(UIProperty::TEXT_ALIGN, "center");

		WCHAR buffer[100];
		swprintf_s(buffer, L"%d", mValue);
		SetText(buffer);

		if (up && down){
			mValue = std::min(mValue, mMax);
			mValue = std::max(mValue, mMin);
			SetNumber(mValue);			
		}
	}
Ejemplo n.º 3
0
	bool NumericUpDown::GetProperty(UIProperty::Enum prop, char val[], unsigned bufsize, bool notDefaultOnly)
	{
		switch (prop)
		{
		case UIProperty::NUMERIC_UPDOWN_MINMAX:
		{
			if (notDefaultOnly)
			{
				if (Vec2I(mMin, mMax)== UIProperty::GetDefaultValueVec2I(prop))
					return false;
			}
			auto data = StringMathConverter::ToString(Vec2I(mMin, mMax));
			strcpy_s(val, bufsize, data.c_str());
			return true;
		}
		case UIProperty::NUMERIC_UPDOWN_NUMBER:
		{
			if (notDefaultOnly)
			{
				if (mValue == UIProperty::GetDefaultValueInt(prop))
					return false;
			}
			auto data = StringConverter::ToString(mValue);
			strcpy_s(val, bufsize, data.c_str());
			return true;
		}
		case UIProperty::NUMERIC_UPDOWN_SHIFT_STEP:
		{
			if (notDefaultOnly){
				if (mShiftStep == UIProperty::GetDefaultValueInt(prop))
					return false;
			}
			strcpy_s(val, bufsize, StringConverter::ToString(mShiftStep).c_str());
			return true;
		}
		case UIProperty::NUMERIC_UPDOWN_STEP:
		{
			if (notDefaultOnly){
				if (mStep == UIProperty::GetDefaultValueInt(prop))
					return false;
			}
			strcpy_s(val, bufsize, StringConverter::ToString(mStep).c_str());
			return true;
		}
		}

		return __super::GetProperty(prop, val, bufsize,  notDefaultOnly);
	}
Ejemplo n.º 4
0
	void Application::InitializePlatform()
	{
		mWindowed = true;
		mWindowedSize = Vec2I(800, 600);
		mWindowedPos = Vec2I(0, 0);
		mWindowResizible = true;
		mActive = false;
		mLog->Out("Initializing window..");

		mWndStyle = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;

		WNDCLASSEX wndClass;
		wndClass.cbSize = sizeof(WNDCLASSEX);
		wndClass.style = mWndStyle;
		wndClass.lpfnWndProc = (WNDPROC)WndProcFunc::WndProc;
		wndClass.cbClsExtra = 0;
		wndClass.cbWndExtra = 0;
		wndClass.hInstance = NULL;
		wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
		wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
		wndClass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
		wndClass.lpszMenuName = NULL;
		wndClass.lpszClassName = "o2App";
		wndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

		if (!RegisterClassEx(&wndClass))
		{
			mLog->Error("Can't register class");
			return;
		}

		if (!(mHWnd = CreateWindowEx(NULL, wndClass.lpszClassName, "o2 application",
									 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
									 mWindowedPos.x, mWindowedPos.y, mWindowedSize.x, mWindowedSize.y,
									 NULL, NULL, NULL, NULL)))
		{

			mLog->Error("Can't create window (CreateWindowEx)");
			return;
		}

		mLog->Out("Window initialized!");
	}
Ejemplo n.º 5
0
void BitmapFont::loadGrid(Image spriteSheet, char32_t start, Vec2I charSize)
{
	int maxRow = spriteSheet.getSize().X / charSize.X;
	int maxCollumn = spriteSheet.getSize().Y / charSize.Y;
	for(int collumn = 0; collumn < maxCollumn; ++collumn)
		for(int row = 0; row < maxRow; ++row)
		{
			int index = start + collumn * maxRow + row;
			LoadedCharacters[index].Sprite = spriteSheet.cut(Vec2I(row, collumn)*charSize, charSize);
		}
}
Ejemplo n.º 6
0
	void Application::SetContentSize(const Vec2I& size)
	{
		Vec2I clientRectSize = size;

		RECT clientRect;
		GetClientRect(mHWnd, &clientRect);
		clientRect.right = clientRect.left + size.x;
		clientRect.bottom = clientRect.top + size.y;

		AdjustWindowRect(&clientRect, mWndStyle, false);

		mWindowedPos = Vec2I(clientRect.left, clientRect.top);
		mWindowedSize = Vec2I(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);

		mLog->Out("Set Content Size: %ix%i", size.x, size.y);

		SetFullscreen(!mWindowed);

		mRender->OnFrameResized();
		onResizing();
	}
Ejemplo n.º 7
0
PlaySpace::PlaySpace(GameSurface* surface, const List<std::string>& arguments)
:
Renderer(surface)
{
	gAssets.initAll();
	
	CliArgumentParser argParser;
	argParser.addSwitch("--stress-test");
	
	argParser.parse(arguments);
	IsStressTesting = argParser["--stress-test"].IsSet;
	
	HDRTarget = new Framebuffer(surface->size().X*2, surface->size().Y*2);
	
	Size = Vec2I(5000, 5000);
	
	checkSectorGeneration(0);
	HomeSystem = Systems.front();
	
	Player = new Ship(gAssets.Warship);
	Player->Position = HomeSystem->generatePosition();
	Player->Faction = HomeSystem->Faction;
	Player->FactionColor = getFactionColor(Player->Faction);
	Player->AI = NULL;
	
	Ships.pushBack(Player);
	Objects.pushBack(Player);
	
	// Play sounds
	Music = gAssets.MusicMainTheme.playGlobal();
	
	if(IsStressTesting)
	{
		WorldRNG.LowSeed = 453812932;
		WorldRNG.HighSeed = 354843;
		for(float y = -25000; y < 25000; y += 5000)
			for(float x = -25000; x < 25000; x += 5000)
				checkSectorGeneration({x, y});
			
		for(SolarSystem* system : Systems)
			system->spawnGroup(system->getPosition(), 8, this);
		
		std::cout << "Stress testing: " << Ships.UsedLength << " Ships, " << Systems.UsedLength << " Solar Systems" << std::endl;
	}
}
Ejemplo n.º 8
0
	void CurvePreview::Redraw()
	{
		if (!mCurve)
			return;

		TextureRef texture = mSprite->GetTexture();
		if (!texture || texture->GetSize() != layout->GetSize())
		{
			texture = TextureRef(layout->GetSize(), PixelFormat::R8G8B8A8, Texture::Usage::RenderTarget);
			mSprite->SetTexture(texture);
			mSprite->SetTextureSrcRect(RectI(Vec2I(), texture->GetSize()));
		}

		const Color4 backColor(120, 120, 120, 255);
		const Color4 curveColor(0, 255, 0, 255);

		Camera prevCamera = o2Render.GetCamera();
		Camera currCamera; currCamera.SetRect(mCurve->GetRect());
		currCamera.SetScale(currCamera.GetScale().InvertedY());

		o2Render.SetRenderTexture(texture);
		o2Render.SetCamera(currCamera);
		o2Render.Clear(backColor);

		static Vector<Vertex2> buffer;
		buffer.Clear();

		auto curveColorHex = curveColor.ARGB();

		auto& keys = mCurve->GetKeys();
		for (auto& key : keys)
		{
			buffer.Add(Vertex2(key.position, key.value, curveColorHex, 0, 0));

			auto points = key.GetApproximatedPoints();
			for (int i = 0; i < key.GetApproximatedPointsCount(); i++)
				buffer.Add(Vertex2(points[i], curveColorHex, 0, 0));

			o2Render.DrawAAPolyLine(buffer.Data(), buffer.Count(), 2);
		}

		o2Render.UnbindRenderTexture();
		o2Render.SetCamera(prevCamera);
	}
Ejemplo n.º 9
0
	Vec2I Application::GetScreenResolution() const
	{
		int hor = GetSystemMetrics(SM_CXSCREEN), ver = GetSystemMetrics(SM_CYSCREEN);
		return Vec2I(hor, ver);
	}
Ejemplo n.º 10
0
	Vec2I Application::GetContentSize() const
	{
		RECT clientRect;
		GetClientRect(mHWnd, &clientRect);
		return Vec2I(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
	}
Ejemplo n.º 11
0
void TextField::SetUseBorder(bool use)
{
    if (use && mBorders.empty())
    {
        auto T = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        T->SetHwndId(GetHwndId());
        mBorders.push_back(T);
        T->SetRender3D(mRender3D, GetRenderTargetSize());
        T->SetManualParent(mSelfPtr.lock());
        T->ChangeSizeY(1);
        T->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");


        auto L = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        L->SetHwndId(GetHwndId());
        mBorders.push_back(L);
        L->SetRender3D(mRender3D, GetRenderTargetSize());
        L->SetManualParent(mSelfPtr.lock());
        L->ChangeSizeX(1);
        L->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        auto R = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        R->SetHwndId(GetHwndId());
        mBorders.push_back(R);
        R->SetRender3D(mRender3D, GetRenderTargetSize());
        R->SetManualParent(mSelfPtr.lock());
        R->SetAlign(ALIGNH::RIGHT, ALIGNV::TOP);
        R->ChangeSizeX(1);
        R->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");


        auto B = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        B->SetHwndId(GetHwndId());
        mBorders.push_back(B);
        B->SetRender3D(mRender3D, GetRenderTargetSize());
        B->SetManualParent(mSelfPtr.lock());
        B->SetAlign(ALIGNH::LEFT, ALIGNV::BOTTOM);
        B->ChangeSizeY(1);
        B->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        auto LT = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        LT->SetHwndId(GetHwndId());
        mBorders.push_back(LT);
        LT->SetRender3D(mRender3D, GetRenderTargetSize());
        LT->SetManualParent(mSelfPtr.lock());
        LT->ChangeSize(Vec2I(1, 1));
        LT->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        auto RT = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        RT->SetHwndId(GetHwndId());
        mBorders.push_back(RT);
        RT->SetRender3D(mRender3D, GetRenderTargetSize());
        RT->SetManualParent(mSelfPtr.lock());
        RT->ChangeSize(Vec2I(1, 1));
        RT->SetAlign(ALIGNH::RIGHT, ALIGNV::TOP);
        RT->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        auto LB = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        LB->SetHwndId(GetHwndId());
        mBorders.push_back(LB);
        LB->SetRender3D(mRender3D, GetRenderTargetSize());
        LB->SetManualParent(mSelfPtr.lock());
        LB->ChangeSize(Vec2I(1, 1));
        LB->SetAlign(ALIGNH::LEFT, ALIGNV::BOTTOM);
        LB->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        auto RB = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        RB->SetHwndId(GetHwndId());
        mBorders.push_back(RB);
        RB->SetRender3D(mRender3D, GetRenderTargetSize());
        RB->SetManualParent(mSelfPtr.lock());
        RB->ChangeSize(Vec2I(1, 1));
        RB->SetAlign(ALIGNH::RIGHT, ALIGNV::BOTTOM);
        RB->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        RefreshBorder();
        RefreshScissorRects();
        UIManager::GetInstance().DirtyRenderList(GetHwndId());
    }
    else if (!use && !mBorders.empty())
    {
        mBorders.clear();
        UIManager::GetInstance().DirtyRenderList(GetHwndId());
    }
}
Ejemplo n.º 12
0
void TextField::OnCursorPosChanged(TextManipulator* mani)
{
    TriggerRedraw();
    int cursorPos = mani->GetCursorPos();
    Vec2I textStartWPos = mUIObject->GetTextStartWPos();
    textStartWPos.x += mCursorOffset;
    if (mani->IsHighlighting())
    {
        auto start = mani->GetHighlightStart();
        auto end = cursorPos;
        if (start > end)
        {
            std::swap(start, end);
        }
        if (end - start > 0) {
            auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize);
            if (font) {
                float width = font->GetTextWidth(
                                  ((const char*)mTextw.c_str()) + (start * 2),
                                  (end - start) * 2);
                float leftGap = font->GetTextWidth(
                                    (const char*)mTextw.c_str(), start * 2);
                KeyboardCursor::GetInstance().SetSize(Vec2I((int)width, (int)mTextSize));
                KeyboardCursor::GetInstance().SetPos(
                    Vec2I(textStartWPos.x + (int)leftGap,
                          textStartWPos.y - Round(mTextSize))
                );
            }
        }
        else {
            auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize);
            float aWidth = font->GetTextWidth((const char*)AnsiToWide("A", 1), 2);
            Vec2I cursorSize(Round(aWidth), 2);
            KeyboardCursor::GetInstance().SetSize(Vec2I((int)1, (int)mTextSize));
            KeyboardCursor::GetInstance().SetPos(
                Vec2I(textStartWPos.x, textStartWPos.y - Round(mTextSize))
            );
        }
    }
    else
    {
        auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize);
        float aWidth = font->GetTextWidth((const char*)AnsiToWide("A", 1), 2);
        Vec2I cursorSize(Round(aWidth), 2);
        KeyboardCursor::GetInstance().SetSize(cursorSize);
        float width = font->GetTextWidth(
                          (const char*)mTextw.c_str(), cursorPos * 2);

        Vec2I visualCursorPos(textStartWPos.x + Round(width),
                              textStartWPos.y - WinBase::BOTTOM_GAP - 2);
        KeyboardCursor::GetInstance().SetPos(visualCursorPos);

        // check region
        // right
        Rect region = GetScissorRegion();
        if (region.right - mTextGap.y < visualCursorPos.x + cursorSize.x) {
            int offset = visualCursorPos.x + cursorSize.x - (region.right - mTextGap.y);
            mCursorOffset -= offset;
            mUIObject->SetTextOffsetForCursorMovement(Vec2I(mCursorOffset, 0));
            KeyboardCursor::GetInstance().SetPos(Vec2I(visualCursorPos.x - offset, visualCursorPos.y));
        }
        else {
            if (region.left + mTextGap.x > visualCursorPos.x) {
                int offset = region.left + mTextGap.x - visualCursorPos.x;
                mCursorOffset += offset;
                mUIObject->SetTextOffsetForCursorMovement(Vec2I(mCursorOffset, 0));
                KeyboardCursor::GetInstance().SetPos(Vec2I(visualCursorPos.x + offset, visualCursorPos.y));
            }
        }


    }
}
Ejemplo n.º 13
0
 Vec2I SDLWindowBackend::getSize() const
 {
     //not sure
     return Vec2I();
 }
Ejemplo n.º 14
0
 Vec2I SDLWindowBackend::getPosition() const
 {
     //not sure
     //SDL_getenv("SDL_VIDEO_WINDOW_POS");
     return Vec2I();
 }