Created
September 24, 2022 04:16
-
-
Save Journeyman1337/de69b47cc4bdfaa81212b2b7281abd5a to your computer and use it in GitHub Desktop.
libcontext wip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-FileCopyrightText: 2022 Daniel Valcour <fosssweeper@gmail.com> | |
// | |
// SPDX-License-Identifier: MIT | |
/* | |
Copyright (c) 2022 Daniel Valcour | |
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 <ctx/instance.h> | |
#include <ctx/context.h> | |
#include <ctx/event.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
int main() | |
{ | |
// create the instance | |
CtxInstance_h instance = NULL; | |
CtxResult result; | |
if (result = ctxInstanceCreate(&instance)) | |
{ | |
fprintf(stderr, "error creating instance: %d\n"); | |
goto shutdown; | |
} | |
// create the context | |
CtxContextCreateInfo create_info = { 0 }; | |
create_info.title = "My Window"; | |
create_info.width = 512; | |
create_info.height = 512; | |
CtxContext_h context = NULL; | |
if (result = ctxContextCreate(instance, &create_info, &context)) | |
{ | |
fprintf(stderr, "error creating context: %d\n"); | |
goto shutdown; | |
} | |
while(1) | |
{ | |
CtxEvent event; | |
do | |
{ | |
if (result = ctxInstanceNextEvent(instance, &event)) | |
{ | |
fprintf(stderr, "error getting next event: %d\n"); | |
goto shutdown; | |
} | |
switch (event.type) | |
{ | |
case CTX_EVENT_CONTEXT_CLOSE: | |
goto shutdown; | |
case CTX_EVENT_CONTEXT_SIZE: | |
printf("w=%d h=%d\n", event.context_size.client_width, event.context_size.client_height); | |
break; | |
default: | |
break; | |
} | |
} while (event.type != CTX_EVENT_NONE); | |
} | |
shutdown: | |
ctxContextDestroy(context); | |
context = NULL; | |
if (result = ctxInstanceDestroy(instance)) | |
{ | |
fprintf(stderr, "error destroying instance: %d\n", result); | |
return result; | |
} | |
instance = NULL; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment