~l3kn/quad

bf42aafeb5c1ea150c8e8f96c8c9a806e20c9db1 — Leon Rische 6 months ago 22b359d
Replace int with size_t for indices
2 files changed, 16 insertions(+), 16 deletions(-)

M menu.h
M quad.c
M menu.h => menu.h +9 -9
@@ 1,7 1,7 @@
bool outline = true;
bool expand = true;
int limit = 1;
int currentRule;
size_t limit = 1;
size_t currentRule;

SDL_Rect makeRect(int x, int y, int w, int h) {
  SDL_Rect rect;


@@ 14,10 14,10 @@ SDL_Rect makeRect(int x, int y, int w, int h) {
}

void drawSquare(SDL_Renderer* renderer, int x, int y, int s, Pattern pattern, bool outline);
void drawNumber(SDL_Renderer* renderer, int x, int y, int s, int n);
void drawNumber(SDL_Renderer* renderer, int x, int y, int s, size_t n);

void drawNode(SDL_Renderer* renderer, int x, int y, Node node);
void drawRule(SDL_Renderer* renderer, int x, int y, Rule* rule, int n);
void drawRule(SDL_Renderer* renderer, int x, int y, Rule* rule, size_t n);
void drawMenu(SDL_Renderer* renderer,
              int x, int y,
              Pattern patterns[static NPATTERNS],


@@ 58,7 58,7 @@ void drawSquare(SDL_Renderer* renderer,
  drawRect(renderer, x, y, s, s, pattern, outline);
}

void drawNumber(SDL_Renderer* renderer, int x, int y, int s, int n) {
void drawNumber(SDL_Renderer* renderer, int x, int y, int s, size_t n) {
  int h = s / 2;
  int o = s / 4;
  drawSquare(renderer, x + o, y + o, h / 2, (n & 1) > 0, true) ;


@@ 76,7 76,7 @@ void drawNode(SDL_Renderer* renderer, int x, int y, Node node) {
  }
}

void drawRule(SDL_Renderer* renderer, int x, int y, Rule* rule, int n) {
void drawRule(SDL_Renderer* renderer, int x, int y, Rule* rule, size_t n) {
  drawSquare(renderer, x, y, TILE_SIZE, BLACK, currentRule == n);
  drawNumber(renderer, x, y, TILE_SIZE, n);
  drawNode(renderer, x, y + TILE_SIZE, rule->fallback);


@@ 99,7 99,7 @@ void drawSelector(SDL_Renderer* renderer,
           TILE_SIZE * 5,
           false,
           true);
  for (int i = 0; i < NPATTERNS; ++i) {
  for (size_t i = 0; i < NPATTERNS; ++i) {
    int x_ = (i % WPATTERNS) * TILE_SIZE;
    int y_ = (i / WPATTERNS) * TILE_SIZE;
    drawSquare(renderer,


@@ 108,7 108,7 @@ void drawSelector(SDL_Renderer* renderer,
               patterns[i],
               true);
  }
  for (int i = 0; i < NRULES; ++i) {
  for (size_t i = 0; i < NRULES; ++i) {
    int x_ = (i % WRULES) * TILE_SIZE;
    int y_ = (i / WRULES) * TILE_SIZE;
    drawSquare(renderer,


@@ 128,7 128,7 @@ void drawMenu(SDL_Renderer* renderer,
              int x, int y,
              Pattern patterns[static NPATTERNS],
              Rule rules[static NRULES]) {
  for (int i = 0; i < NRULES; ++i) {
  for (size_t i = 0; i < NRULES; ++i) {
    int x_ = (i % WEDITRULES) * WEDIT * TILE_SIZE;
    int y_ = (i / WEDITRULES) * HEDIT * TILE_SIZE;
    drawRule(renderer, x + x_, y + y_, &rules[i], i);

M quad.c => quad.c +7 -7
@@ 14,7 14,7 @@
SDL_Window* window = NULL;
SDL_Renderer* windowRenderer = NULL;

int currentRule = 0;
size_t currentRule = 0;
Node* selNode = NULL;

Rule rules[NRULES];


@@ 68,8 68,8 @@ void draw(bool expand) {

void reset() {
  Node pat0 = { PATTERN, 0 };
  for (int i = 0; i < NRULES; ++i) {
    for (int q = 0; q < 4; ++q) {
  for (size_t i = 0; i < NRULES; ++i) {
    for (size_t q = 0; q < 4; ++q) {
      rules[i].quads[q] = pat0;
    }
    rules[i].fallback = pat0;


@@ 109,7 109,7 @@ void increaseLimit() {
  }
}

void selectRule(int n) {
void selectRule(size_t n) {
  if (n >= 0 && n < NRULES) {
    currentRule = n;
    draw(true);


@@ 176,7 176,7 @@ void handleMouse(SDL_Event* event) {
    int my = (y - MENU_Y);
    int tx = mx / TILE_SIZE;
    int ty = my / TILE_SIZE;
    int index = (ty / HEDIT) * 2 + (tx / WEDIT);
    site_t index = (ty / HEDIT) * 2 + (tx / WEDIT);
    int rx = tx % WEDIT;
    int ry = ty % HEDIT;



@@ 207,9 207,9 @@ void printNode(Node* node) {
}

void printRules() {
  for (int i = 0; i < NRULES; ++i) {
  for (size_t i = 0; i < NRULES; ++i) {
    Rule* rule = &rules[i];
    for (int j = 0; j < 4; ++j) {
    for (size_t j = 0; j < 4; ++j) {
      printNode(&(rule->quads[j]));
    }
    printNode(&(rule->fallback));