~l3kn/quad

66f1841f04ffe90f2df08d4ec620a6846e6bd8dd — Leon Rische 6 months ago 3068001
Working state without zoom
1 files changed, 30 insertions(+), 64 deletions(-)

M quad.c
M quad.c => quad.c +30 -64
@@ 8,8 8,6 @@

#include "config.h"
#include "quad.h"
#include "patterns.h"
int colors[2] = { COLOR_BLACK, COLOR_WHITE };
#include "menu.h"

SDL_Window* window = NULL;


@@ 34,21 32,7 @@ int selectorX = PADDING;
int selectorY = PADDING;

void saveBMP() {
  /* SDL_Surface* surface = SDL_GetWindowSurface(window); */
  /* SDL_RenderReadPixels(grammarRenderer, */
  /*                      NULL, */
  /*                      SDL_PIXELFORMAT_ARGB8888, */
                       /* grammarSurface->pixels, */
                       /* grammarSurface->pitch); */
  SDL_SaveBMP(grammarSurface, "quad-render.bmp");
  /* SDL_FreeSurface(surface); */
}

void setColor(SDL_Renderer* renderer, int color) {
  int r = color >> 16;
  int g = (color >> 8) & 255;
  int b = color & 255;
  SDL_SetRenderDrawColor(renderer, r, g, b, SDL_ALPHA_OPAQUE);
}

void renderRule(SDL_Renderer* renderer) {


@@ 64,22 48,13 @@ void draw() {
  SDL_RenderClear(mainRenderer);
  setColor(mainRenderer, colors[1]);

  drawSquare(mainRenderer, CANVAS_X-1, CANVAS_Y-1, SIZE+1, BLACK);
  drawSquare(mainRenderer, CANVAS_X-1, CANVAS_Y-1, SIZE+2, BLACK, true);
  drawMenu(mainRenderer, PADDING, PADDING, &patterns, &rules);

  SDL_Rect src, target;
  src.x = 0;
  src.y = 0;
  src.w = SIZE / zoomFactor;
  src.h = SIZE / zoomFactor;

  target.x = CANVAS_X;
  target.y = CANVAS_Y;
  target.w = SIZE;
  target.h = SIZE;
  SDL_Rect src = makeRect(0, 0, SIZE, SIZE);
  SDL_Rect target = makeRect(CANVAS_X, CANVAS_Y, SIZE, SIZE);

  SDL_RenderCopy(mainRenderer, grammarTexture, &src, &target);
  /* SDL_BlitScaled(grammarSurface, &src, winSurface, &target); */

  if (selector) {
    drawSelector(mainRenderer, selectorX, selectorY, &patterns);


@@ 95,7 70,7 @@ void reset() {
    }
    rules[i].fallback = pat0;
  }
  renderRule(grammarRenderer);
  renderRule(mainRenderer);
  draw();
}



@@ 107,7 82,6 @@ void zoom() {
    if (quad->type == RULE) {
      currentRule = quad->index;
    }
    renderRule(grammarRenderer);
  }
  draw();
}


@@ 193,7 167,7 @@ void handleKey(SDL_Event* event) {
      selectRule(event->key.keysym.sym - SDLK_1);
    }
  }
}
  }
}

void handleMouse(SDL_Event* event) {


@@ 202,8 176,8 @@ void handleMouse(SDL_Event* event) {

  if (x >= CANVAS_X && x < CANVAS_X + SIZE && \
      y >= CANVAS_Y && y < CANVAS_Y + SIZE) {
    int sx = CANVAS_X + TILE_SIZE;
    int sy = CANVAS_Y + TILE_SIZE;
    int sx = CANVAS_X;
    int sy = CANVAS_Y;
    int sQuad = 0;

    if ((x - CANVAS_X) > HALF) {


@@ 247,37 221,28 @@ void handleMouse(SDL_Event* event) {
    int tx = (x - PADDING) / TILE_SIZE;
    int ty = (y - PADDING) / TILE_SIZE;

    if (tx >= 0 && tx < WPATTERNS && \
        ty >= 0 && ty < HPATTERNS) {
      selection.type = PATTERN;
      selection.index = tx + (WPATTERNS * ty);
    } else if (tx >= 0 && tx < WRULES && \
               ty >= HPATTERNS && ty < (HPATTERNS + HRULES)) {
      ty -= HPATTERNS;
      selection.type = RULE;
      selection.index = tx + (WRULES * ty);
    } else if (tx >= 0 && tx < MENU_WIDTH && \
               ty >= (HPATTERNS + HRULES + 1) && ty < MENU_HEIGHT) {
      ty -= (HPATTERNS + HRULES + 1);

      int rule = WEDITRULES * (ty / 3) + (tx / 6);
      int rx = tx % 6;
      int ry = ty % 3;

      if (rx == 0 && ry == 0) {
        selection.type = RULE;
        selection.index = rule;
      } else if (rx == 0 && ry == 1 && selection.type == PATTERN) {
        rules[rule].fallback = selection;
        renderRule(grammarRenderer);
        draw();
      } else if (rx >= 2 && rx <= 3 && ry >= 0 && ry <= 1) {
        int quad = ry * 2 + (rx - 2);
        rules[rule].quads[quad] = selection;
        renderRule(grammarRenderer);
        draw();
      }
    }
    /* if (tx >= 0 && tx < MENU_WIDTH && \ */
    /*     ty >= (HPATTERNS + HRULES + 1) && ty < MENU_HEIGHT) { */
    /*   ty -= (HPATTERNS + HRULES + 1); */

    /*   int rule = WEDITRULES * (ty / 3) + (tx / 6); */
    /*   int rx = tx % 6; */
    /*   int ry = ty % 3; */

    /* if (rx == 0 && ry == 0) { */
    /*   selection.type = RULE; */
    /*   selection.index = rule; */
    /* } else if (rx == 0 && ry == 1 && selection.type == PATTERN) { */
    /*   rules[rule].fallback = selection; */
    /*   renderRule(grammarRenderer); */
    /*   draw(); */
    /* } else if (rx >= 2 && rx <= 3 && ry >= 0 && ry <= 1) { */
    /*   int quad = ry * 2 + (rx - 2); */
    /*   rules[rule].quads[quad] = selection; */
    /*   renderRule(grammarRenderer); */
    /*   draw(); */
    /* } */
    /* } */
  }
}



@@ 348,6 313,7 @@ int main(int argc, char* argv[]) {

  SDL_DestroyRenderer(mainRenderer);
  SDL_DestroyRenderer(grammarRenderer);

  SDL_FreeSurface(grammarSurface);
  SDL_DestroyWindow(window);
  SDL_Quit();