Path: blob/main_old/samples/WindowTest/WindowTest.cpp
1693 views
//1// Copyright 2015 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56// WindowTest.cpp: Sample used to test various function of OSWindow78#include <algorithm>9#include <iostream>1011#include "util/OSWindow.h"12#include "util/test_utils.h"1314int main(int argc, char *argv[])15{16OSWindow *window = OSWindow::New();17int width = 400;18int height = 400;19int x = 0;20int y = 0;2122if (!window->initialize("Window Test", width, height))23{24return -1;25}26window->setVisible(true);27window->setPosition(x, y);2829bool running = true;30while (running)31{32Event event;33while (window->popEvent(&event))34{35if (event.Type == Event::EVENT_CLOSED)36{37running = false;38break;39}4041if (event.Type == Event::EVENT_KEY_PRESSED)42{43int newWidth = width;44int newHeight = height;45int newX = x;46int newY = y;47switch (event.Key.Code)48{49case KEY_ESCAPE:50running = false;51break;5253case KEY_W:54newWidth = std::max(0, width + (event.Key.Shift ? -20 : 20));55break;56case KEY_H:57newHeight = std::max(0, height + (event.Key.Shift ? -20 : 20));58break;5960case KEY_LEFT:61newX = x - 20;62break;63case KEY_RIGHT:64newX = x + 20;65break;66case KEY_UP:67newY = y - 20;68break;69case KEY_DOWN:70newY = y + 20;71break;7273case KEY_C:74window->setMousePosition(width / 2, height / 2);75break;76case KEY_T:77window->signalTestEvent();78window->messageLoop();79if (window->didTestEventFire())80{81std::cout << "Test event did fire" << std::endl;82}83else84{85std::cout << "Test event did not fire" << std::endl;86}87break;88case KEY_S:89window->setVisible(false);90window->messageLoop();91angle::Sleep(1000);92window->setVisible(true);93window->messageLoop();94break;9596default:97break;98}99100if (newWidth != width || newHeight != height)101{102width = newWidth;103height = newHeight;104window->resize(width, height);105}106if (newX != x || newY != y)107{108x = newX;109y = newY;110window->setPosition(x, y);111}112113angle::Sleep(0);114window->messageLoop();115if (window->getWidth() != width || window->getHeight() != height)116{117std::cout << "Discrepancy between set dimensions and retrieved dimensions"118<< std::endl;119std::cout << "Width: " << width << " vs. " << window->getWidth() << std::endl;120std::cout << "Height: " << height << " vs. " << window->getHeight()121<< std::endl;122}123if (window->getX() != x || window->getY() != y)124{125std::cout << "Discrepancy between set position and retrieved position"126<< std::endl;127std::cout << "X: " << x << " vs. " << window->getX() << std::endl;128std::cout << "Y: " << y << " vs. " << window->getY() << std::endl;129}130}131}132133angle::Sleep(0);134window->messageLoop();135}136137window->destroy();138}139140141