Day 41/100 100 Days of Code

Day 41/100 100 Days of Code

Rebuild Back Better

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);