Skip to main content

Command Palette

Search for a command to run...

Day 41/100 100 Days of Code

Rebuild Back Better

Updated
1 min readView as Markdown
Day 41/100 100 Days of Code
C

AKA Chris, is a software developer from Athens, Greece. He started programming with basic when he was very young. He lost interest in programming during school years but after an unsuccessful career in audio, he decided focus on what he really loves which is technology.

He loves working with older languages like C and wants to start programming electronics and microcontrollers because he wants to get into embedded systems programming.

I finished my study late today and didn't work much on my application. Here's what I did today:

  1. I defined macros for the screen's width and height size and mouse button values
#define LEFT_MOUSE_BUTTON 1
#define RIGHT_MOUSE_BUTTON 4
#define SCREEN_WIDTH 1280
#define SCREEN_HEIGHT 720
  1. I added mouseX, and mouseY float variables to get the current position of the mouse, added a Uint32 buttons variable to get which mouse button is pressed,
    float mouseX, mouseY;
    Uint32 buttons;
  1. Used the PumpEvents() function to get the latest input event and the SDL_GetMouseState() to update mouseX, and mouseY as well as get which button is pressed:
  SDL_PumpEvents();
  buttons = SDL_GetMouseState(&mouseX, &mouseY);
  1. Added conditional statements for the button presses:
  if (buttons == LEFT_MOUSE_BUTTON)
  {
      std::cout << "Pressed Button: " << buttons << std::endl;
      std::cout << "Mouse X: " << mouseX << "Mouse Y: " << mouseY << std::endl;
  }

  if (buttons == RIGHT_MOUSE_BUTTON)
  {
      std::cout << "Pressed the left button" << std::endl;
  }
  1. Updated the window creation by adding the new macros I created:
    window = SDL_CreateWindow("Rebuild Back Better",
                  SCREEN_WIDTH,
                  SCREEN_HEIGHT,
                  0);

100 Days of Code

Part 41 of 50

100 days of code is a good initiative to go into hard mode and spend more time in programming. These 100 days will be focused on completing projects and research.

Up next

Day 42/100 100 Days of Code

Rebuild Back Better