fixed dunger build, added current cell coordinates readout
[vrlugburz] / tools / dunger / src / lview.c
index 16af530..e0001fe 100644 (file)
@@ -1,4 +1,5 @@
 #include <GL/gl.h>
+#include <drawtext.h>
 #include "lview.h"
 
 static struct level *lvl;
@@ -46,10 +47,36 @@ 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)
 {
        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;
+               if(bn == 0) {
+                       sel->type = CELL_WALK;
+               } else if(bn == 2) {
+                       sel->type = CELL_SOLID;
+               }
+       }
+}
+
+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;
+       }
+
+       if(bnstate[0]) {
+               sel->type = CELL_WALK;
+       } else if(bnstate[2]) {
+               sel->type = CELL_SOLID;
+       }
 }
 
 #define LTHICK 0.5f
@@ -103,6 +130,21 @@ void draw_lview(void)
        }
        glEnd();
 
+       if(sel) {
+               int cidx = sel - lvl->cells;
+               int row = cidx / lvl->width;
+               int col = cidx % lvl->width;
+
+               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)