~l3kn/quad

ef2a9e6d9a0bb729634cf5bbcde722a36d94fda0 — Leon Rische 5 months ago cffb46c
Replace quadrants with array
2 files changed, 21 insertions(+), 24 deletions(-)

M quad.c
M quad.h
M quad.c => quad.c +20 -20
@@ 69,10 69,10 @@ void expandNode(int x, int y, int s, Node node) {
void expandRule(int x, int y, int s, Rule* rule) {
  int h = s / 2;
  if (s > limit) {
    expandNode(x, y, h, rule->tl);
    expandNode(x + h, y, h, rule->tr);
    expandNode(x, y + h, h, rule->bl);
    expandNode(x + h, y + h, h, rule->br);
    expandNode(x, y, h, rule->quads[0]);
    expandNode(x + h, y, h, rule->quads[1]);
    expandNode(x, y + h, h, rule->quads[2]);
    expandNode(x + h, y + h, h, rule->quads[3]);
  } else if (rule->fallback.type == PATTERN) {
    expandNode(x, y, s, rule->fallback);
  }


@@ 124,10 124,10 @@ void drawRule(int x, int y, int n) {

  drawNode(x, y + MENU_SIZE, rule.fallback);

  drawNode(x + 2 * MENU_SIZE, y, rule.tl);
  drawNode(x + 3 * MENU_SIZE, y, rule.tr);
  drawNode(x + 2 * MENU_SIZE, y + MENU_SIZE, rule.bl);
  drawNode(x + 3 * MENU_SIZE, y + MENU_SIZE, rule.br);
  drawNode(x + 2 * MENU_SIZE, y, rule.quads[0]);
  drawNode(x + 3 * MENU_SIZE, y, rule.quads[1]);
  drawNode(x + 2 * MENU_SIZE, y + MENU_SIZE, rule.quads[2]);
  drawNode(x + 3 * MENU_SIZE, y + MENU_SIZE, rule.quads[3]);
}

void drawMenu() {


@@ 168,10 168,10 @@ void draw() {
void reset() {
  struct node pat0 = { PATTERN, 0 };
  for (int i = 0; i < 8; i++) {
    rules[i].tl = pat0;
    rules[i].tr = pat0;
    rules[i].bl = pat0;
    rules[i].br = pat0;
    rules[i].quads[0] = pat0;
    rules[i].quads[1] = pat0;
    rules[i].quads[2] = pat0;
    rules[i].quads[3] = pat0;
    rules[i].fallback = pat0;
  }
}


@@ 242,16 242,16 @@ void handleMouse(SDL_Event* event) {
      }

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


@@ 279,13 279,13 @@ void handleMouse(SDL_Event* event) {
      if (tx == 0 && ty == 1) {
        selection = rules[rule].fallback;
      } else if (tx == 2 && ty == 0) {
        selection = rules[rule].tl;
        selection = rules[rule].quads[0];
      } else if (tx == 3 && ty == 0) {
        selection = rules[rule].tr;
        selection = rules[rule].quads[1];
      } else if (tx == 2 && ty == 1) {
        selection = rules[rule].bl;
        selection = rules[rule].quads[2];
      } else if (tx == 3 && ty == 1) {
        selection = rules[rule].br;
        selection = rules[rule].quads[3];
      } else {
        selection.type = NONE;
      }

M quad.h => quad.h +1 -4
@@ 8,9 8,6 @@ typedef struct node {
} Node;

typedef struct rule {
  Node tl;
  Node tr;
  Node bl;
  Node br;
  Node quads[4];
  Node fallback;
} Rule;