~l3kn/quad

71fb693a984cb7502408e5f96f71fa9ac6a1230e — Leon Rische 5 months ago 99fe451
Only handle mousedown event
1 files changed, 34 insertions(+), 41 deletions(-)

M quad.c
M quad.c => quad.c +34 -41
@@ 225,49 225,43 @@ void handleKey(SDL_Event* event) {
}

void handleMouse(SDL_Event* event) {
  int x_ = event->motion.x;
  int y_ = event->motion.y;
  int tx = (x_ - PADDING) / menu_size;
  int ty = (y_ - PADDING) / menu_size;

  switch (event->type) {
  case SDL_MOUSEBUTTONDOWN:
    if (tx >= 0 && tx < 10) {
      if (ty >= 0 && ty < 4) {
        selection.type = PATTERN;
        selection.index = tx + (10 * ty);
      } else if (ty >= 5 && ty < 16) {
        ty -= 5;

        int rule = 2 * (ty / 3);
        ty %= 3;
        if (tx >= 6) {
          tx -= 6;
          rule += 1;
        }
  int tx = (event->motion.x - PADDING) / menu_size;
  int ty = (event->motion.y - PADDING) / menu_size;

  if (tx >= 0 && tx < 10) {
    if (ty >= 0 && ty < 4) {
      selection.type = PATTERN;
      selection.index = tx + (10 * ty);
    } else if (ty >= 5 && ty < 16) {
      ty -= 5;

      int rule = 2 * (ty / 3);
      ty %= 3;
      if (tx >= 6) {
        tx -= 6;
        rule += 1;
      }

        if (tx == 0 && ty == 0) {
          selection.type = RULE;
          selection.index = rule;
        } else if (tx == 0 && ty == 1 && selection.type == PATTERN) {
          rules[rule].fallback = selection;
          draw();
        } else if (tx == 2 && ty == 0 && selection.type) {
          rules[rule].quads[0] = selection;
          draw();
        } else if (tx == 3 && ty == 0 && selection.type) {
          rules[rule].quads[1] = selection;
          draw();
        } else if (tx == 2 && ty == 1 && selection.type) {
          rules[rule].quads[2] = selection;
          draw();
        } else if (tx == 3 && ty == 1 && selection.type) {
          rules[rule].quads[3] = selection;
          draw();
        }
      if (tx == 0 && ty == 0) {
        selection.type = RULE;
        selection.index = rule;
      } else if (tx == 0 && ty == 1 && selection.type == PATTERN) {
        rules[rule].fallback = selection;
        draw();
      } else if (tx == 2 && ty == 0 && selection.type) {
        rules[rule].quads[0] = selection;
        draw();
      } else if (tx == 3 && ty == 0 && selection.type) {
        rules[rule].quads[1] = selection;
        draw();
      } else if (tx == 2 && ty == 1 && selection.type) {
        rules[rule].quads[2] = selection;
        draw();
      } else if (tx == 3 && ty == 1 && selection.type) {
        rules[rule].quads[3] = selection;
        draw();
      }
    }
    break;
  }
}



@@ 311,7 305,6 @@ int main(int argc, char* argv[]) {
        handleKey(&event);
        break;
      case SDL_MOUSEBUTTONDOWN:
      case SDL_MOUSEBUTTONUP:
        handleMouse(&event);
        break;
      case SDL_WINDOWEVENT: