If you touch the square, coords are spewed to stdout
This commit is contained in:
parent
a2b73ab710
commit
81302d524b
|
@ -0,0 +1,61 @@
|
|||
---
|
||||
Standard: Auto
|
||||
Language: Cpp
|
||||
BasedOnStyle: LLVM
|
||||
ColumnLimit: 0
|
||||
IndentWidth: 8
|
||||
TabWidth: 8
|
||||
UseTab: ForIndentation
|
||||
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignConsecutiveBitFields: true
|
||||
AlignConsecutiveDeclarations: true
|
||||
AlignConsecutiveMacros: true
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: AlignAfterOperator
|
||||
AlignTrailingComments: true
|
||||
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Always
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
|
||||
AlwaysBreakAfterDefinitionReturnType: TopLevel
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
|
||||
BreakBeforeBinaryOperators: All
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeTernaryOperators: true
|
||||
|
||||
BreakStringLiterals: false
|
||||
BreakConstructorInitializers: AfterColon
|
||||
|
||||
IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentGotoLabels: true
|
||||
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ContinuationIndentWidth: 2
|
||||
Cpp11BracedListStyle: true
|
||||
IncludeBlocks: Regroup
|
||||
InsertTrailingCommas: Wrapped
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SpaceAfterCStyleCast: true
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SpaceBeforeParens: Always
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
|
||||
...
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
Checks: 'performance-*,portability-*,readability-*,bugprone-*,concurrency-*,llvm-*,clang-analyzer-core.*,clang-analyzer-nullability.*,clang-analyzer-optin.portability.UnixAPI,clang-analyzer-security.*,clang-analyzer-unix.*,clang-analyzer-valist.*,clang-analyzer-apiModeling.*,cert-*-c,-readability-isolate-declaration,-readability-braces-around-statements,-readability-named-parameter'
|
||||
WarningsAsErrors: ''
|
||||
HeaderFilterRegex: ''
|
||||
AnalyzeTemporaryDtors: false
|
||||
FormatStyle: file
|
|
@ -0,0 +1,2 @@
|
|||
project
|
||||
src/*.o
|
|
@ -13,6 +13,7 @@ CFLAGS :=\
|
|||
|
||||
# Sources / Results
|
||||
SRC :=\
|
||||
src/rectangle.c \
|
||||
src/init.c \
|
||||
src/main.c
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <SDL2/SDL_render.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include <stdlib.h>
|
||||
#define HEX_POKE 0xFF
|
||||
|
||||
int
|
||||
main (int argc, char *argv[]) {
|
||||
|
@ -40,10 +41,10 @@ main (int argc, char *argv[]) {
|
|||
rectangle->y = rand () % 500;
|
||||
|
||||
SDL_SetRenderTarget (main_render, background);
|
||||
SDL_SetRenderDrawColor (main_render, 0x00, 0x00, 0x00, 0x00);
|
||||
SDL_SetRenderDrawColor (main_render, 0x00, HEX_POKE, 0x00, 0x00);
|
||||
SDL_RenderClear (main_render);
|
||||
SDL_RenderDrawRect (main_render, rectangle);
|
||||
SDL_SetRenderDrawColor (main_render, 0xFF, 0x00, 0x00, 0x00);
|
||||
SDL_SetRenderDrawColor (main_render, HEX_POKE, 0x00, 0x00, 0x00);
|
||||
SDL_RenderFillRect (main_render, rectangle);
|
||||
SDL_SetRenderTarget (main_render, NULL);
|
||||
SDL_RenderCopy (main_render, background, NULL, NULL);
|
||||
|
@ -56,8 +57,8 @@ main (int argc, char *argv[]) {
|
|||
while (SDL_PollEvent (main_event)) {
|
||||
switch (main_event->type) {
|
||||
case SDL_MOUSEMOTION:
|
||||
printf ("Mouse motion detected!\n");
|
||||
printf ("Current mouse position: (%d,%d)\t", main_event->motion.x, main_event->motion.y);
|
||||
if (check_interaction_in_rect (main_event->motion.x, main_event->motion.y, rectangle))
|
||||
printf ("You touched the square! X position: %d, Y position %d\n", main_event->motion.x, main_event->motion.y);
|
||||
break;
|
||||
|
||||
/* Yes I acknowledge this is a very hacky way to exit the program, my apologies */
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
/* ----------------------------------------------------------
|
||||
* @@@@@@@ @@@ @@@ @@@@@@ @@@@@@@ @@@@@@@@ @@@ @@@
|
||||
* @@@@@@@ @@@ @@@ @@@@@@@ @@@@@@@@ @@@@@@@@@@ @@@ @@@
|
||||
* @@! @@! !@@ @@@ @@! @@@ @@! @@@@ @@! !@@
|
||||
* !@! !@! @!! @!@ !@! @!@ !@! @!@!@ !@! @!!
|
||||
* @!! !@!@! @!@!!@ @!@!!@! @!@ @! !@! !@@!@!
|
||||
* !!! @!!! !!@!@! !!@!@! !@!!! !!! @!!!
|
||||
* !!: !!: !!: !!: :!! !!:! !!! !: :!!
|
||||
* :!: :!: :!: :!: !:! :!: !:! :!: !:!
|
||||
* :: :: :: :::: :: ::: ::::::: :: :: :::
|
||||
* ----------------------------------------------------------
|
||||
*
|
||||
* rectangle.c - defines special functions for rectangles
|
||||
*
|
||||
* Copyright (C) MMXXIII Patrick D. Covaci <ty3r0x@chaox.ro>
|
||||
*
|
||||
* The source is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "window.h"
|
||||
|
||||
/* Function to check if a coordinate (x, y) is inside a rectangle */
|
||||
int
|
||||
check_interaction_in_rect (int x_cursor, int y_cursor, struct SDL_Rect *rect) {
|
||||
/* Check X coordinate is within rectangle range */
|
||||
if (x_cursor >= rect->x && x_cursor < (rect->x + rect->w)) {
|
||||
/* Check Y coordinate is within rectangle range */
|
||||
if (y_cursor >= rect->y && y_cursor < (rect->y + rect->h)) {
|
||||
/* X and Y is inside the rectangle */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* X or Y is outside the rectangle */
|
||||
return 0;
|
||||
}
|
|
@ -45,6 +45,6 @@ extern SDL_Rect *rectangle;
|
|||
extern SDL_Event *main_event;
|
||||
|
||||
int init_program (void);
|
||||
void define_rect (SDL_Rect *rectangle, int pos_x, int pos_y, int width, int height);
|
||||
int check_interaction_in_rect (int x_cursor, int y_cursor, struct SDL_Rect *rect);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue