Skip to content

Commit

Permalink
Added System->Video->Zoom menu and fixed GLVideoDriver bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ferris committed May 16, 2013
1 parent c906f73 commit 63f4ffd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions GLVideoDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void GLVideoDriver::SetOutput(int width, int height, const unsigned int *data)
}
wglMakeCurrent(dc, rc);

glViewport(0, 0, viewport->GetWidth(), viewport->GetHeight());
glClear(GL_COLOR_BUFFER_BIT);

glBindTexture(GL_TEXTURE_2D, textureHandle);
Expand Down
40 changes: 34 additions & 6 deletions Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ int Main(const List<String>& arguments)
try
{
Chip8 chip8;
int zoom = 8;

auto running = true;

auto window = Window::Create("Vip8");
window->KeyDown += [&] (Key key) { if (key == Key::Escape) running = false; };
window->Closing += [&] { running = false; };

auto resizeWindow = [&] { window->SetDesiredSize(chip8.GetOutputWidth() * zoom, chip8.GetOutputHeight() * zoom); };
resizeWindow();

auto loadRomImage = [&] (const String& fileName)
{
try
Expand Down Expand Up @@ -77,7 +73,34 @@ int Main(const List<String>& arguments)
systemAudioLatencyMenu->AddChild(systemAudioLatency1000ms);
systemAudioMenu->AddChild(systemAudioLatencyMenu);
systemMenu->AddChild(systemAudioMenu);
// TODO: finish system menu

auto systemVideoMenu = Menu::Create("Video");
auto systemVideoZoomMenu = Menu::Create("Zoom");
const int numZooms = 4;
const int zoomSizes[] = { 4, 8, 16, 32 };
int zoomIndex = 1;
auto systemVideoZoomItems = new MenuItem *[numZooms];
auto reflectZoom = [&]
{
auto size = zoomSizes[zoomIndex];
window->SetDesiredSize(chip8.GetOutputWidth() * size, chip8.GetOutputHeight() * size);
for (int i = 0; i < numZooms; i++) systemVideoZoomItems[i]->SetChecked(i == zoomIndex);
};
for (int i = 0; i < numZooms; i++)
{
auto size = zoomSizes[i];
systemVideoZoomItems[i] = MenuItem::Create(String(size) + "x" + size);
systemVideoZoomItems[i]->Click += [&, i]
{
zoomIndex = i;
reflectZoom();
};
systemVideoZoomMenu->AddChild(systemVideoZoomItems[i]);
}
reflectZoom();
systemVideoMenu->AddChild(systemVideoZoomMenu);
systemMenu->AddChild(systemVideoMenu);

menu->AddChild(systemMenu);
auto helpMenu = Menu::Create("Help");
auto helpAbout = MenuItem::Create("About...");
Expand Down Expand Up @@ -119,7 +142,12 @@ int Main(const List<String>& arguments)
delete systemAudioLatency250ms;
delete systemAudioLatency500ms;
delete systemAudioLatency1000ms;
// merhp

delete systemVideoMenu;
delete systemVideoZoomMenu;
for (int i = 0; i < numZooms; i++) delete systemVideoZoomItems[i];
delete [] systemVideoZoomItems;

delete helpMenu;
delete helpAbout;
delete viewport;
Expand Down

0 comments on commit 63f4ffd

Please sign in to comment.