b7362850534 examples/renderer/08-rotating-textures: Fix compiler warning on MSVC . 37d62deca16 examples/renderer/10-geometry: Fixes and cleanups. 0758b2a0c4c examples: Added renderer/10-geometry 1a90e092623 examples: Added renderer/09-scaling-textures 4fdeb6861bd examples: a few renderer fixes. 66b92e95acf examples: renamed renderer sources to match other example directories. ffcf372d275 examples: Added renderer/08-rotating-textures 0c7334cce39 examples: Added renderer/07-streaming-textures 2bd3d9cfb7b examples: Added renderer/06-textures 9d0b3eded61 examples: added renderer/05-rectangles 3413617cb64 examples: added renderer/04-points b0e528cc88a Switched ifdef from negative to positive 97d1056e16d GPU: MSAA fixes (#10917) 254b36361e5 Add SDL_PRILL? format specifiers specifically for long long type. 6f80d47d64d Use hexidecimal code for ± 4392233007d Removed tabs from headers 89c6bc5f502 Prefer Vulkan even on Windows (#10912) 980b4ff6dbe GPU: Vulkan descriptor management rewrite (#10910) fcb8a2c016c wayland: Fix animated cursor timing ea2e2e451d1 Better fix for initializing Android environment variables 095fb5f5221 Fixed infinite recursion at startup on Android 88a01fbc964 testautomation_stdlib.c: fix -Wformat warnings from mingw with %lld/%llu b4e2777820c examples/renderer/03-lines: Fix compiler warning on Visual Studio. 2e3e5abd7d4 examples/renderer/03-lines: use a gray background. fd0ce75e2ea tests: Fix tests when run with the --high-pixel-density flag 745d5e4991d examples/renderer/03-lines: Make this less obnoxious to look at. 1b266ec13d3 examples: added renderer/03-lines 6771a6020da testcamera: don't enable verbose logging 594edb6bd29 Add Thrustmaster TMX VID & PID to wheel device list. 34c60113607 Fixed Windows build d29a0e3f310 Fixed warning: no previous prototype for function 7a924b36aeb compile_shaders.sh shouldn't be in the SDL framework 1f727b61f3c Sync SDL3 wiki -> header 398dff7c259 Added support for the HORI licensed Steam Controller 481203c074d Fixed Xcode warnings 7edf7fad664 fix bool define when SDL_DEFINE_STDBOOL is defined: ff90570a3cf define SDL_DEFINE_STDBOOL for gcc < 3 git-subtree-dir: external/SDL git-subtree-split: b7362850534295f076c19f7f8bffa06e530d0968
174 lines
5.2 KiB
C
174 lines
5.2 KiB
C
/*
|
|
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
warranty. In no event will the authors be held liable for any damages
|
|
arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
including commercial applications, and to alter it and redistribute it
|
|
freely.
|
|
*/
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3/SDL_main.h>
|
|
#include <SDL3/SDL_test.h>
|
|
|
|
#define RESIZE_BORDER 20
|
|
|
|
static const SDL_Rect drag_areas[] = {
|
|
{ 20, 20, 100, 100 },
|
|
{ 200, 70, 100, 100 },
|
|
{ 400, 90, 100, 100 }
|
|
};
|
|
static const SDL_FRect render_areas[] = {
|
|
{ 20.0f, 20.0f, 100.0f, 100.0f },
|
|
{ 200.0f, 70.0f, 100.0f, 100.0f },
|
|
{ 400.0f, 90.0f, 100.0f, 100.0f }
|
|
};
|
|
|
|
static const SDL_Rect *areas = drag_areas;
|
|
static int numareas = SDL_arraysize(drag_areas);
|
|
|
|
static SDL_HitTestResult SDLCALL
|
|
hitTest(SDL_Window *window, const SDL_Point *pt, void *data)
|
|
{
|
|
int i;
|
|
int w, h, p_w;
|
|
SDL_Point adj_pt;
|
|
float scale;
|
|
|
|
SDL_GetWindowSize(window, &w, &h);
|
|
SDL_GetWindowSizeInPixels(window, &p_w, NULL);
|
|
|
|
scale = (float)p_w / (float)w;
|
|
|
|
adj_pt.x = (int)SDL_floorf(pt->x * scale);
|
|
adj_pt.y = (int)SDL_floorf(pt->y * scale);
|
|
|
|
for (i = 0; i < numareas; i++) {
|
|
if (SDL_PointInRect(&adj_pt, &areas[i])) {
|
|
SDL_Log("HIT-TEST: DRAGGABLE\n");
|
|
return SDL_HITTEST_DRAGGABLE;
|
|
}
|
|
}
|
|
|
|
#define REPORT_RESIZE_HIT(name) \
|
|
{ \
|
|
SDL_Log("HIT-TEST: RESIZE_" #name "\n"); \
|
|
return SDL_HITTEST_RESIZE_##name; \
|
|
}
|
|
|
|
if (pt->x < RESIZE_BORDER && pt->y < RESIZE_BORDER) {
|
|
REPORT_RESIZE_HIT(TOPLEFT);
|
|
} else if (pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER && pt->y < RESIZE_BORDER) {
|
|
REPORT_RESIZE_HIT(TOP);
|
|
} else if (pt->x > w - RESIZE_BORDER && pt->y < RESIZE_BORDER) {
|
|
REPORT_RESIZE_HIT(TOPRIGHT);
|
|
} else if (pt->x > w - RESIZE_BORDER && pt->y > RESIZE_BORDER && pt->y < h - RESIZE_BORDER) {
|
|
REPORT_RESIZE_HIT(RIGHT);
|
|
} else if (pt->x > w - RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
|
|
REPORT_RESIZE_HIT(BOTTOMRIGHT);
|
|
} else if (pt->x < w - RESIZE_BORDER && pt->x > RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
|
|
REPORT_RESIZE_HIT(BOTTOM);
|
|
} else if (pt->x < RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
|
|
REPORT_RESIZE_HIT(BOTTOMLEFT);
|
|
} else if (pt->x < RESIZE_BORDER && pt->y < h - RESIZE_BORDER && pt->y > RESIZE_BORDER) {
|
|
REPORT_RESIZE_HIT(LEFT);
|
|
}
|
|
|
|
SDL_Log("HIT-TEST: NORMAL\n");
|
|
return SDL_HITTEST_NORMAL;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int i;
|
|
int done = 0;
|
|
SDLTest_CommonState *state;
|
|
|
|
/* Initialize test framework */
|
|
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
|
if (!state) {
|
|
return 1;
|
|
}
|
|
|
|
state->window_flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE;
|
|
|
|
/* Parse commandline */
|
|
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
|
|
return 1;
|
|
}
|
|
|
|
if (!SDLTest_CommonInit(state)) {
|
|
return 2;
|
|
}
|
|
|
|
for (i = 0; i < state->num_windows; i++) {
|
|
if (!SDL_SetWindowHitTest(state->windows[i], hitTest, NULL)) {
|
|
SDL_Log("Enabling hit-testing failed for window %d: %s", i, SDL_GetError());
|
|
SDL_Quit();
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
while (!done) {
|
|
SDL_Event e;
|
|
int nothing_to_do = 1;
|
|
|
|
for (i = 0; i < state->num_windows; ++i) {
|
|
SDL_SetRenderDrawColor(state->renderers[i], 0, 0, 127, 255);
|
|
SDL_RenderClear(state->renderers[i]);
|
|
SDL_SetRenderDrawColor(state->renderers[i], 255, 0, 0, 255);
|
|
SDLTest_DrawString(state->renderers[i], (float)state->window_w / 2 - 80.0f, 10.0f, "Drag the red boxes");
|
|
SDL_RenderFillRects(state->renderers[i], render_areas, SDL_arraysize(render_areas));
|
|
SDL_RenderPresent(state->renderers[i]);
|
|
}
|
|
|
|
while (SDL_PollEvent(&e)) {
|
|
SDLTest_CommonEvent(state, &e, &done);
|
|
nothing_to_do = 0;
|
|
|
|
switch (e.type) {
|
|
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
|
SDL_Log("button down!\n");
|
|
break;
|
|
|
|
case SDL_EVENT_MOUSE_BUTTON_UP:
|
|
SDL_Log("button up!\n");
|
|
break;
|
|
|
|
case SDL_EVENT_WINDOW_MOVED:
|
|
SDL_Log("Window event moved to (%d, %d)!\n", (int)e.window.data1, (int)e.window.data2);
|
|
break;
|
|
|
|
case SDL_EVENT_KEY_DOWN:
|
|
if (e.key.key == SDLK_ESCAPE) {
|
|
done = 1;
|
|
} else if (e.key.key == SDLK_X) {
|
|
if (!areas) {
|
|
areas = drag_areas;
|
|
numareas = SDL_arraysize(drag_areas);
|
|
} else {
|
|
areas = NULL;
|
|
numareas = 0;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case SDL_EVENT_QUIT:
|
|
done = 1;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (nothing_to_do) {
|
|
SDL_Delay(50);
|
|
}
|
|
}
|
|
|
|
SDLTest_CommonQuit(state);
|
|
return 0;
|
|
}
|