#include <GL/gl.h>
#include <drawtext.h>
#include "lview.h"
+#include "app.h"
static struct level *lvl;
static struct cell *sel;
{
lvl = l;
sel = 0;
- panx = pany = 0;
+ panx = 0;
+ pany = -12;
zoom = 1;
zoom_lview(0);
return 0;
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;
- if(bn == 0) {
- sel->type = CELL_WALK;
- } else if(bn == 2) {
- sel->type = CELL_SOLID;
+
+ 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;
}
}
}
return;
}
- if(bnstate[0]) {
- sel->type = CELL_WALK;
- } else if(bnstate[2]) {
- sel->type = CELL_SOLID;
+ 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);
void draw_lview(void)
{
- int i, j;
+ int i, j, row, col;
struct cell *cell;
glBegin(GL_QUADS);
glEnd();
if(sel) {
- int cidx = sel - lvl->cells;
- int row = cidx / lvl->width;
- int col = cidx % lvl->width;
+ cell_coords(sel, &col, &row);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
}
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;
+}