Open7

OpenSiv3D v0.6.6 新規追加・更新サンプル

Ryo SuzukiRyo Suzuki

シンプルなメニューバー

# include <Siv3D.hpp> // OpenSiv3D v0.6.6

void Main()
{
	const Array<std::pair<String, Array<String>>> menus
	{
		{ U"ゲーム", { U"新規", U"スコア", U"終了" }},
		{ U"ヘルプ", { U"\U000F0625  遊び方", U"\U000F14F7  リリースノート", U"ライセンス" }},
	};

	SimpleMenuBar menuBar{ menus };

	while (System::Update())
	{
		if (const auto item = menuBar.update())
		{
			// 「終了」が押されたら
			if (item == MenuBarItemIndex{ 0, 2 })
			{
				return;
			}

			// 「ライセンス」が押されたら
			if (item == MenuBarItemIndex{ 1, 2 })
			{
				LicenseManager::ShowInBrowser();
			}
		}

		menuBar.draw();
	}
}
# include <Siv3D.hpp> // OpenSiv3D v0.6.6

void Main()
{
	Scene::SetBackground(ColorF{ 0.7, 0.9, 0.8 });

	Vec2 pos = Scene::Center(), target = pos, velocity = Vec2::Zero();

	const Array<std::pair<String, Array<String>>> menus
	{
		{ U"ファイル", { U"新規作成", U"開く", U"名前を付けて保存", U"終了" }},
		{ U"編集", { U"元に戻す", U"切り取り", U"コピー", U"貼り付け", U"削除", U"検索する", U"次を検索", U"前を検索" }},
		{ U"表示", { U"拡大", U"縮小" }},
		{ U"ヘルプ", { U"\U000F0625  使い方", U"\U000F14F7  リリースノート", U"ライセンス" }},
	};

	SimpleMenuBar menuBar{ menus };
	menuBar
		.setItemEnabled(1, 0, false)
		.setItemEnabled(1, 1, false)
		.setItemEnabled(1, 2, false)
		.setItemEnabled(1, 4, false)
		.setItemEnabled(1, 5, false)
		.setItemEnabled(1, 6, false)
		.setItemEnabled(1, 7, false);

	const SimpleMenuBar::ColorPalette palette
	{
		.menuBarColor = ColorF{ 0.82, 0.92, 0.86 },
		.activeMenuColor = ColorF{ 0.78, 0.88, 0.82 },
		.menuTextColor = ColorF{ 0.11 },
		.itemBoxColor = ColorF{ 0.99 },
		.itemMouseoverColor = ColorF{ 0.1, 0.4, 0.3 },
		.itemTextColor = ColorF{ 0.11 },
		.itemMouseoverTextColor = ColorF{ 1.0 },
		.itemDisabledTextColor = ColorF{ 0.8 },
		.itemRectShadowColor = ColorF{ 0.0, 0.5 }
	};

	menuBar.setColorPalette(palette);

	while (System::Update())
	{
		if (const auto item = menuBar.update())
		{
			Print << U"menuIndex: {}, itemIndex: {}"_fmt(item->menuIndex, item->itemIndex);
		}

		if (Scene::Rect().mouseOver() && (not MouseL.cleared()))
		{
			Cursor::RequestStyle(CursorStyle::Hand);

			if (MouseL.down())
			{
				target = Cursor::Pos();
			}
		}

		pos = Math::SmoothDamp(pos, target, velocity, 0.25);

		pos.asCircle(40).drawShadow(Vec2{ 2, 2 }, 8).draw();

		menuBar.draw();
	}
}
Ryo SuzukiRyo Suzuki

入力処理を打ち切る機能

# include <Siv3D.hpp> // OpenSiv3D v0.6.6

void Main()
{
	Vec2 pos = Scene::Center(), target = pos, velocity = Vec2::Zero();

	const Rect rect{ 200, 300, 200, 100 };

	while (System::Update())
	{
		if (rect.leftClicked())
		{
			// このフレームの以降の MouseL 入力を無効化する
			MouseL.clearInput();
		}

		if (MouseL.down())
		{
			target = Cursor::Pos();
		}

		pos = Math::SmoothDamp(pos, target, velocity, 0.25);

		pos.asCircle(40).drawShadow(Vec2{ 2, 2 }, 8).draw();

		rect.draw(Palette::Skyblue);
	}
}
Ryo SuzukiRyo Suzuki

OrderedTable

# include <Siv3D.hpp> // OpenSiv3D v0.6.6

void Main()
{
	OrderedTable<int32, String> ot;
	ot.emplace(7, U"seven");
	ot.emplace(5, U"five");
	ot.emplace(10, U"ten");
	ot.emplace(1, U"one");

	HashTable<int32, String> ht;
	ht.emplace(7, U"seven");
	ht.emplace(5, U"five");
	ht.emplace(10, U"ten");
	ht.emplace(1, U"one");

	// キーの昇順でアクセスできる
	for (auto&& [key, value] : ot)
	{
		Print << key << U": " << value;
	}

	Print << U"----";

	for (auto&& [key, value] : ht)
	{
		Print << key << U": " << value;
	}

	while (System::Update())
	{

	}
}
Ryo SuzukiRyo Suzuki

Rect, RectF, RoundRect の枠の上下グラデーション

# include <Siv3D.hpp> // OpenSiv3D v0.6.6

void Main()
{
	while (System::Update())
	{
		const ColorF topColor = HSV{ ColorF{ 0.9, 0.6, 0.2 } } + HSV{ (Scene::Time() * 30), 0, 0 };
		const ColorF bottomColor = HSV{ ColorF{ 0.6, 0.2, 0.6 } } + HSV{ (Scene::Time() * 30), 0, 0 };

		// New!
		Rect{ 50, 50, 300, 250 }.drawFrame(12, 0, Arg::top = topColor, Arg::bottom = bottomColor);

		// New!
		RoundRect{ 450, 50, 300, 250, 40 }.drawFrame(12, 0, Arg::top = topColor, Arg::bottom = bottomColor);
	}
}
Ryo SuzukiRyo Suzuki

RoundRect の上下グラデーション

# include <Siv3D.hpp> // OpenSiv3D v0.6.6

void Main()
{
	while (System::Update())
	{
		const ColorF topColor = HSV{ ColorF{ 0.9, 0.6, 0.2 } } + HSV{ (Scene::Time() * 30), 0, 0 };
		const ColorF bottomColor = HSV{ ColorF{ 0.6, 0.2, 0.6 } } + HSV{ (Scene::Time() * 30), 0, 0 };

		// New!
		RoundRect{ 50, 50, 300, 250, 40 }.draw(Arg::top = topColor, Arg::bottom = bottomColor);
	}
}
Ryo SuzukiRyo Suzuki

タスクバーにタスクの進捗状況を表示する機能 (Windows 版)

# include <Siv3D.hpp> // OpenSiv3D v0.6.6

void Main()
{
	int32 count = 0;

	while (System::Update())
	{
		if (count <= 600)
		{
			// 1.0 を渡すと完了する
			Platform::Windows::Window::SetTaskbarProgressBar(count / 600.0);
		}

		++count;
	}
}
Ryo SuzukiRyo Suzuki

2 つの長方形の重なる領域

# include <Siv3D.hpp> // OpenSiv3D v0.6.6

void Main()
{
	const Rect rect1{ 200, 100, 300, 200 };

	while (System::Update())
	{
		const Rect rect2{ Cursor::Pos(), 200, 300 };

		rect1.drawFrame(1, 0);

		rect2.drawFrame(1, 0);

		if (const auto overlap = rect1.getOverlap(rect2))
		{
			overlap.draw(Palette::Orange);
		}
	}
}