/*
* This source file is part of RmlUi, the HTML/CSS Interface Middleware
*
* For the latest information, see http://github.com/mikke89/RmlUi
*
* Copyright (c) 2008-2010 Nuno Silva
* Copyright (c) 2019 The RmlUi Team, and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#include
#include
#include
#include
#include
#include "SystemInterfaceSDL2.h"
#include "RenderInterfaceSDL2.h"
#include
#include
int main(int argc, char **argv)
{
#ifdef RMLUI_PLATFORM_WIN32
DoAllocConsole();
#endif
int window_width = 1024;
int window_height = 768;
SDL_Init( SDL_INIT_VIDEO );
SDL_Window * screen = SDL_CreateWindow("LibRmlUi SDL2 test", 20, 20, window_width, window_height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
SDL_GLContext glcontext = SDL_GL_CreateContext(screen);
int oglIdx = -1;
int nRD = SDL_GetNumRenderDrivers();
for(int i=0; iLoadDocument("assets/demo.rml");
if(Document)
{
Document->Show();
fprintf(stdout, "\nDocument loaded");
}
else
{
fprintf(stdout, "\nDocument is nullptr");
}
bool done = false;
while(!done)
{
SDL_Event event;
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderClear(renderer);
Context->Render();
SDL_RenderPresent(renderer);
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
done = true;
break;
case SDL_MOUSEMOTION:
Context->ProcessMouseMove(event.motion.x, event.motion.y, SystemInterface.GetKeyModifiers());
break;
case SDL_MOUSEBUTTONDOWN:
Context->ProcessMouseButtonDown(SystemInterface.TranslateMouseButton(event.button.button), SystemInterface.GetKeyModifiers());
break;
case SDL_MOUSEBUTTONUP:
Context->ProcessMouseButtonUp(SystemInterface.TranslateMouseButton(event.button.button), SystemInterface.GetKeyModifiers());
break;
case SDL_MOUSEWHEEL:
Context->ProcessMouseWheel(event.wheel.y, SystemInterface.GetKeyModifiers());
break;
case SDL_KEYDOWN:
{
// Intercept F8 key stroke to toggle RmlUi's visual debugger tool
if( event.key.keysym.sym == SDLK_F8 )
{
Rml::Debugger::SetVisible( ! Rml::Debugger::IsVisible() );
break;
}
Context->ProcessKeyDown(SystemInterface.TranslateKey(event.key.keysym.sym), SystemInterface.GetKeyModifiers());
break;
}
default:
break;
}
}
Context->Update();
}
Rml::Core::Shutdown();
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(screen);
SDL_Quit();
return 0;
};