~l3kn/quad

3b269791283aef6f5df9778ad25417d087a4daf0 — Leon Rische 5 months ago 7deec99
Replace drag-and-drop with clicking
1 files changed, 35 insertions(+), 64 deletions(-)

M quad.c
M quad.c => quad.c +35 -64
@@ 217,71 217,40 @@ void handleMouse(SDL_Event* event) {
  int ty = (y_ - PADDING) / menu_size;

  switch (event->type) {
  case SDL_MOUSEBUTTONUP:
    if (tx >= 0 && tx < 10 &&
        ty >= 5 && ty < 16 &&
        selection.type != NONE) {
      ty -= 5;

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

      if (tx == 0 && ty == 1 && selection.type == PATTERN) {
        rules[rule].fallback = selection;
        draw();
      }

      if (tx == 2 && ty == 0) {
        rules[rule].quads[0] = selection;
        draw();
      } else if (tx == 3 && ty == 0) {
        rules[rule].quads[1] = selection;
        draw();
      } else if (tx == 2 && ty == 1) {
        rules[rule].quads[2] = selection;
        draw();
      } else if (tx == 3 && ty == 1) {
        rules[rule].quads[3] = selection;
        draw();
      }
    }

    selection.type = NONE;
    break;
  case SDL_MOUSEBUTTONDOWN:
    if (ty >= 0 && ty < 4 && tx >= 0 && tx < 10) {
      selection.type = PATTERN;
      selection.index = tx + (10 * ty);
    } else if ((tx % 6) == 0 && ((ty - 5) % 3) == 0) {
      selection.type = RULE;
      selection.index = tx / 6;
      selection.index += 2 * ((ty - 5) / 3);
    } else if (tx >= 0 && tx < 10 && ty >= 5 && ty < 16) {
      ty -= 5;

      int rule = 2 * (ty / 3);
      ty %= 3;
      if (tx >= 6) {
        tx -= 6;
        rule += 1;
      }
    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 == 1) {
        selection = rules[rule].fallback;
      } else if (tx == 2 && ty == 0) {
        selection = rules[rule].quads[0];
      } else if (tx == 3 && ty == 0) {
        selection = rules[rule].quads[1];
      } else if (tx == 2 && ty == 1) {
        selection = rules[rule].quads[2];
      } else if (tx == 3 && ty == 1) {
        selection = rules[rule].quads[3];
      } else {
        selection.type = NONE;
        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 != NONE) {
          rules[rule].quads[0] = selection;
          draw();
        } else if (tx == 3 && ty == 0 && selection.type != NONE) {
          rules[rule].quads[1] = selection;
          draw();
        } else if (tx == 2 && ty == 1 && selection.type != NONE) {
          rules[rule].quads[2] = selection;
          draw();
        } else if (tx == 3 && ty == 1 && selection.type != NONE) {
          rules[rule].quads[3] = selection;
          draw();
        }
      }
    }
    break;


@@ 310,7 279,9 @@ int main(int argc, char* argv[]) {
    return 1;
  }

  selection.type = NONE;
  selection.type = PATTERN;
  selection.index = 11; // White pattern

  reset();
  draw();