Add a WindowTest sample to test OSWindow manually

This will help port OSWindow to other platforms.

BUG=angleproject:892

Change-Id: If9884d310d80421e2fc09cffd03bcf01327b1eee
Reviewed-on: https://chromium-review.googlesource.com/283900
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2015-07-07 17:07:37 +02:00
Родитель 0b5a4a4916
Коммит 4a290c9919
2 изменённых файлов: 143 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,135 @@
//
// Copyright The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// WindowTest.cpp: Sample used to test various function of OSWindow
#include <iostream>
#include "OSWindow.h"
#include "system_utils.h"
int main(int argc, char *argv[])
{
OSWindow *window = CreateOSWindow();
int width = 400;
int height = 400;
int x = 0;
int y = 0;
if (!window->initialize("Window Test", width, height))
{
return -1;
}
window->setVisible(true);
window->setPosition(x, y);
bool running = true;
while (running)
{
Event event;
while (window->popEvent(&event))
{
if (event.Type == Event::EVENT_CLOSED)
{
running = false;
break;
}
if (event.Type == Event::EVENT_KEY_PRESSED)
{
int newWidth = width;
int newHeight = height;
int newX = x;
int newY = y;
switch (event.Key.Code)
{
case KEY_ESCAPE:
running = false;
break;
case KEY_W:
newWidth = std::max(0, width + (event.Key.Shift ? -20 : 20));
break;
case KEY_H:
newHeight = std::max(0, height + (event.Key.Shift ? -20 : 20));
break;
case KEY_LEFT:
newX = x - 20;
break;
case KEY_RIGHT:
newX = x + 20;
break;
case KEY_UP:
newY = y - 20;
break;
case KEY_DOWN:
newY = y + 20;
break;
case KEY_C:
window->setMousePosition(width / 2, height / 2);
break;
case KEY_T:
window->signalTestEvent();
window->messageLoop();
if (window->didTestEventFire())
{
std::cout << "Test event did fire" << std::endl;
}
else
{
std::cout << "Test event did not fire" << std::endl;
}
break;
case KEY_S:
window->setVisible(false);
window->messageLoop();
angle::Sleep(1000);
window->setVisible(true);
window->messageLoop();
break;
default:
break;
}
if (newWidth != width || newHeight != height)
{
width = newWidth;
height = newHeight;
window->resize(width, height);
}
if (newX != x || newY != y)
{
x = newX;
y = newY;
window->setPosition(x, y);
}
angle::Sleep(0);
window->messageLoop();
if (window->getWidth() != width || window->getHeight() != height)
{
std::cout << "Discrepancy between set dimensions and retrieved dimensions" << std::endl;
std::cout << "Width: " << window->getWidth() << " vs. " << width << std::endl;
std::cout << "Height: " << window->getHeight() << " vs. " << height << std::endl;
}
if (window->getX() != x || window->getY() != y)
{
std::cout << "Discrepancy between set position and retrieved position" << std::endl;
std::cout << "X: " << window->getX() << " vs. " << x << std::endl;
std::cout << "Y: " << window->getY() << " vs. " << y << std::endl;
}
}
}
angle::Sleep(0);
window->messageLoop();
}
window->destroy();
}

Просмотреть файл

@ -206,5 +206,13 @@
'includes': [ '../build/common_defines.gypi', ],
'sources': [ 'tri_fan_microbench/TriFanMicroBench.cpp', ],
},
{
'target_name': 'window_test',
'type': 'executable',
'dependencies': [ 'sample_util' ],
'includes': [ '../build/common_defines.gypi', ],
'sources': [ 'WindowTest/WindowTest.cpp', ],
},
],
}