X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=tools%2Fdunger%2Fsrc%2Flview.c;h=48014cc5658c759fcfc8fbeeab9d517447d5153a;hb=594c18e3671a27624a867071b5bafd08148652b3;hp=16af53093b5faa9e34467dd1754d1e20d2b459c1;hpb=576f9aa6409354c392d2ff661d61dbf6d967a8f8;p=vrlugburz diff --git a/tools/dunger/src/lview.c b/tools/dunger/src/lview.c index 16af530..48014cc 100644 --- a/tools/dunger/src/lview.c +++ b/tools/dunger/src/lview.c @@ -1,5 +1,7 @@ #include +#include #include "lview.h" +#include "app.h" static struct level *lvl; static struct cell *sel; @@ -11,7 +13,8 @@ int init_lview(struct level *l) { lvl = l; sel = 0; - panx = pany = 0; + panx = 0; + pany = -12; zoom = 1; zoom_lview(0); return 0; @@ -46,31 +49,82 @@ void zoom_lview(float dz) cellsz = xsz > ysz ? ysz : xsz; } -void lview_mouse(int x, int y) +static int bnstate[8]; + +void lview_mbutton(int bn, int press, int x, int y) { + int cx, cy; float hsz = cellsz / 2.0f; sel = pos_to_cell(x + hsz - vpx, vph - y + hsz - vpy, 0, 0); + bnstate[bn] = press; + + if(press) { + if(!sel) return; + + switch(tool) { + case TOOL_DRAW: + if(bn == 0) { + sel->type = CELL_WALK; + } else if(bn == 2) { + sel->type = CELL_SOLID; + } + break; + + case TOOL_PSTART: + cell_coords(sel, &cx, &cy); + if(bn == 0) { + if(sel->type == CELL_WALK) { + lvl->px = cx; + lvl->py = cy; + } + } else if(bn == 2) { + if(lvl->px == cx && lvl->py == cy) { + lvl->px = lvl->py = -1; + } + } + break; + } + } +} + +void lview_mouse(int x, int y) +{ + float hsz = cellsz / 2.0f; + if(!(sel = pos_to_cell(x + hsz - vpx, vph - y + hsz - vpy, 0, 0))) { + return; + } + + switch(tool) { + case TOOL_DRAW: + if(bnstate[0]) { + sel->type = CELL_WALK; + } else if(bnstate[2]) { + sel->type = CELL_SOLID; + } + break; + } } #define LTHICK 0.5f static void draw_cell(struct cell *cell) { - int cidx, row, col; + int row, col; float x, y, hsz; static const float colors[][3] = {{0, 0, 0}, {0.6, 0.6, 0.6}, {0.4, 0.2, 0.1}}; hsz = cellsz * 0.5f; - cidx = cell - lvl->cells; - row = cidx / lvl->width; - col = cidx % lvl->width; - + cell_coords(cell, &col, &row); cell_to_pos(col, row, &x, &y); if(sel == cell) { - glColor3f(0.4, 1.0f, 0.4); + glColor3f(1, 1, 1); } else { - glColor3f(0.5f, 0.5f, 0.5f); + if(col == lvl->px && row == lvl->py) { + glColor3f(0, 1, 0); + } else { + glColor3f(0.5f, 0.5f, 0.5f); + } } glVertex2f(x - hsz, y - hsz); glVertex2f(x + hsz, y - hsz); @@ -91,7 +145,7 @@ static void draw_cell(struct cell *cell) void draw_lview(void) { - int i, j; + int i, j, row, col; struct cell *cell; glBegin(GL_QUADS); @@ -103,6 +157,19 @@ void draw_lview(void) } glEnd(); + if(sel) { + cell_coords(sel, &col, &row); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glTranslatef(10, 10, 0); + + glColor3f(1, 1, 1); + dtx_printf("(%d, %d)", col, row); + dtx_flush(); + + glPopMatrix(); + } } void cell_to_pos(int cx, int cy, float *px, float *py) @@ -126,3 +193,10 @@ struct cell *pos_to_cell(float px, float py, int *cx, int *cy) } return 0; } + +void cell_coords(struct cell *cell, int *col, int *row) +{ + int cidx = cell - lvl->cells; + *row = cidx / lvl->width; + *col = cidx % lvl->width; +}