Skip to content

Commit

Permalink
Updated app.h version
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasgustavsson committed Sep 10, 2022
1 parent 5b93852 commit 2de408c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![build](https://github.com/mattiasgustavsson/dos-like/workflows/build/badge.svg)
![build](https://github.com/mattiasgustavsson/template_project/workflows/build/badge.svg)

# template_project
Basic setup for building something with app.h on Windows/Linux/Mac/Web
Expand Down
47 changes: 19 additions & 28 deletions source/libs/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Licensing information can be found at the end of the file.
------------------------------------------------------------------------------
app.h - v0.4 - Small cross-platform base framework for graphical apps.
app.h - v0.5 - Small cross-platform base framework for graphical apps.
Do this:
#define APP_IMPLEMENTATION
Expand Down Expand Up @@ -187,9 +187,6 @@ Here's a basic sample program which starts a windowed app and plots random pixel
return app_run( app_proc, NULL, NULL, NULL, NULL );
}
// pass-through so the program will build with either /SUBSYSTEM:WINDOWS or /SUBSYSTEN:CONSOLE
extern "C" int __stdcall WinMain( struct HINSTANCE__*, struct HINSTANCE__*, char*, int ) { return main( __argc, __argv ); }
API Documentation
Expand Down Expand Up @@ -715,6 +712,7 @@ details.
#ifdef APP_IMPLEMENTATION
#undef APP_IMPLEMENTATION

#include <stdlib.h>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// OPENGL CODE - Shared between platform implementations
Expand Down Expand Up @@ -767,6 +765,7 @@ details.

#if defined( APP_WASM )
#include <wajic_gl.h>
#define WA_CORO_IMPLEMENT_NANOSLEEP
#include <wajic_coro.h>
#else
#include <GL/glew.h>
Expand Down Expand Up @@ -1657,6 +1656,8 @@ static LRESULT CALLBACK app_internal_wndproc( HWND hwnd, UINT message, WPARAM wp
case WM_LBUTTONDBLCLK:
input_event.type = APP_INPUT_DOUBLE_CLICK; input_event.data.key = APP_KEY_LBUTTON;
app_internal_add_input_event( app, &input_event );
input_event.type = APP_INPUT_KEY_DOWN; input_event.data.key = APP_KEY_LBUTTON;
app_internal_add_input_event(app, &input_event);
break;
case WM_RBUTTONDOWN:
input_event.type = APP_INPUT_KEY_DOWN; input_event.data.key = APP_KEY_RBUTTON;
Expand All @@ -1669,6 +1670,8 @@ static LRESULT CALLBACK app_internal_wndproc( HWND hwnd, UINT message, WPARAM wp
case WM_RBUTTONDBLCLK:
input_event.type = APP_INPUT_DOUBLE_CLICK; input_event.data.key = APP_KEY_RBUTTON;
app_internal_add_input_event( app, &input_event );
input_event.type = APP_INPUT_KEY_DOWN; input_event.data.key = APP_KEY_RBUTTON;
app_internal_add_input_event(app, &input_event);
break;
case WM_MBUTTONDOWN:
input_event.type = APP_INPUT_KEY_DOWN; input_event.data.key = APP_KEY_MBUTTON;
Expand All @@ -1681,6 +1684,8 @@ static LRESULT CALLBACK app_internal_wndproc( HWND hwnd, UINT message, WPARAM wp
case WM_MBUTTONDBLCLK:
input_event.type = APP_INPUT_DOUBLE_CLICK; input_event.data.key = APP_KEY_MBUTTON;
app_internal_add_input_event( app, &input_event );
input_event.type = APP_INPUT_KEY_DOWN; input_event.data.key = APP_KEY_MBUTTON;
app_internal_add_input_event(app, &input_event);
break;
case WM_XBUTTONDOWN:
input_event.type = APP_INPUT_KEY_DOWN; input_event.data.key = HIWORD( wparam ) == 1 ? APP_KEY_XBUTTON1 :APP_KEY_XBUTTON2;
Expand All @@ -1693,6 +1698,8 @@ static LRESULT CALLBACK app_internal_wndproc( HWND hwnd, UINT message, WPARAM wp
case WM_XBUTTONDBLCLK:
input_event.type = APP_INPUT_DOUBLE_CLICK; input_event.data.key = HIWORD( wparam ) == 1 ? APP_KEY_XBUTTON1 :APP_KEY_XBUTTON2;
app_internal_add_input_event( app, &input_event );
input_event.type = APP_INPUT_KEY_DOWN; input_event.data.key = HIWORD( wparam ) == 1 ? APP_KEY_XBUTTON1 :APP_KEY_XBUTTON2;
app_internal_add_input_event(app, &input_event);
break;
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
Expand Down Expand Up @@ -1864,7 +1871,7 @@ static LRESULT CALLBACK app_internal_wndproc( HWND hwnd, UINT message, WPARAM wp
app->GetRawInputDataPtr( (HRAWINPUT) lparam, RID_INPUT, &raw, &size, sizeof( RAWINPUTHEADER ) );
if( raw.header.dwType == RIM_TYPEMOUSE )
{
if( ( raw.data.mouse.usFlags & 1 ) == MOUSE_MOVE_RELATIVE)
if( ( raw.data.mouse.usFlags & 1 ) == MOUSE_MOVE_RELATIVE)
{
float dx = (float) raw.data.mouse.lLastX;
float dy = (float) raw.data.mouse.lLastY;
Expand Down Expand Up @@ -2902,33 +2909,17 @@ void app_window_size( app_t* app, int width, int height )

int app_window_width( app_t* app )
{
int width = app->windowed_w;
if( app->screenmode == APP_SCREENMODE_WINDOW )
{
WINDOWPLACEMENT placement;
placement.length = sizeof( placement );
GetWindowPlacement( app->hwnd, &placement );
width = placement.rcNormalPosition.right - placement.rcNormalPosition.left;
}
RECT r = app_internal_rect( 0, 0, 0, 0 );
AdjustWindowRect( &r, APP_WINDOWED_WS_STYLE | WS_VISIBLE, FALSE );
return width - ( r.right - r.left );
RECT r;
GetClientRect( app->hwnd, &r );
return r.right - r.left;
}


int app_window_height( app_t* app )
{
int height = app->windowed_h;
if( app->screenmode == APP_SCREENMODE_WINDOW )
{
WINDOWPLACEMENT placement;
placement.length = sizeof( placement );
GetWindowPlacement( app->hwnd, &placement );
height = placement.rcNormalPosition.bottom - placement.rcNormalPosition.top;
}
RECT r = app_internal_rect( 0, 0, 0, 0 );
AdjustWindowRect( &r, APP_WINDOWED_WS_STYLE | WS_VISIBLE, FALSE );
return height - ( r.bottom - r.top );
RECT r;
GetClientRect( app->hwnd, &r );
return r.bottom - r.top;
}


Expand Down Expand Up @@ -3389,7 +3380,7 @@ int app_run( int (*app_proc)( app_t*, void* ), void* user_data, void* memctx, vo
int result = 0xff;
int display_count;
int glres;

if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
{
// printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
Expand Down

0 comments on commit 2de408c

Please sign in to comment.