Exemplo n.º 1
0
bool Overlay::get_mouse_coords(int32_t* x, int32_t* y) 
{ 
	//PrintMessage("in:(%i,%i)\n",*x,*y);
	bool ret = parent->get_mouse_coords(x,y);
	//PrintMessage("out:(%i,%i)\n",*x,*y); 

	//if we are painting over the tile, then we need to reroute through stonesense
	if(ret && PaintingOverTileAt(*x,*y)){
		int xpx, ypx, xpos, ypos, zpos;
		SDL_GetMouseState(&xpx, &ypx);
		xpx = xpx - offsetx;
		ypx = ypx - offsety;
		
		//first figure out which tile in the segment it came from
        ScreenToPoint(xpx,ypx,xpos,ypos,zpos);

		//then remove the segment rotation
		correctForRotation(
			xpos, ypos, 
			(4 - ssState.Rotation) % 4,
			ssState.Size.x, ssState.Size.y);

		//add on the segment offset
		xpos = xpos + ssState.Position.x;
		ypos = ypos + ssState.Position.y;
		//zpos = zpos + ssState.Position.z - 1;

		//remove the offset of the df window
		int dfviewx, dfviewy, dfviewz;
		Gui::getViewCoords(dfviewx, dfviewy, dfviewz);
		xpos = xpos - dfviewx + 1;
		ypos = ypos - dfviewy + 1;
		//zpos = zpos - dfviewz;

        if (!df::global::gamemode || *df::global::gamemode == game_mode::ADVENTURE)
        {
            //Adventure mode doesn't have a single-tile border around it.
            xpos = xpos - 1;
            ypos = ypos - 1;
        }

		//check to see if this new loaction is within the area we are painting over
		//since we don't want to accidentally click somewhere in the interface
		if(PaintingOverTileAt(xpos,ypos)) {
			*x = xpos;
			*y = ypos;
			return true;
		} else {
			*x = -1;
			*y = -1;
			return false;
		}
	}

	return ret;
}
Exemplo n.º 2
0
void doMouse()
{
    al_get_mouse_state(&mouse);
    al_get_keyboard_state(&keyboard);
    int32_t keymod = getKeyMods(&keyboard);

    char stepsize = ((keymod&ALLEGRO_KEYMOD_SHIFT) ? MAPNAVIGATIONSTEPBIG : MAPNAVIGATIONSTEP);
    //mouse_callback = mouseProc;
    static int last_mouse_z;
    if(mouse.z < last_mouse_z) {
        action_decrZ(keymod);
        last_mouse_z = mouse.z;
    }
    if(mouse.z > last_mouse_z) {
        action_incrZ(keymod);
        last_mouse_z = mouse.z;
    }
    if( mouse.buttons & 2 ) {
        ssConfig.track_mode = GameConfiguration::TRACKING_NONE;
        int x, y;
        x = mouse.x;
        y = mouse.y;
        int tilex,tiley,tilez;
        ScreenToPoint(x,y,tilex,tiley,tilez);
        int diffx = tilex - ssState.Size.x/2;
        int diffy = tiley - ssState.Size.y/2;
        /*we use changeRelativeToRotation directly, and not through moveViewRelativeToRotation
        because we don't want to move the offset with the mouse. It just feels weird. */
        // changing to +1,+1 which moves the clicked point to one of the 4 surrounding the center of rotation
        changeRelativeToRotation(ssState.Position.x, ssState.Position.y, diffx+1, diffy+1 );
        //moveViewRelativeToRotation(diffx+1, diffy+1);
        timeToReloadSegment = true;
        //rest(50);
    }
    if( mouse.buttons & 1 ) {
        ssConfig.follow_DFcursor = false;
        int x, y;
        x = mouse.x;//pos >> 16;
        y = mouse.y; //pos & 0x0000ffff;
        if(x >= MiniMapTopLeftX && x <= MiniMapBottomRightX && y >= MiniMapTopLeftY && y <= MiniMapBottomRightY) { // in minimap
            ssState.Position.x = (x-MiniMapTopLeftX-MiniMapSegmentWidth/2)/oneTileInPixels;
            ssState.Position.y = (y-MiniMapTopLeftY-MiniMapSegmentHeight/2)/oneTileInPixels;
        } else {
            int tilex,tiley,tilez;

            //get the point in the segment
            ScreenToPoint(x,y,tilex,tiley,tilez);

            //then remove the segment rotation
            correctForRotation(
                tilex, tiley,
                (4 - ssState.Rotation) % 4,
                ssState.Size.x, ssState.Size.y);

            //Convert to zero as top layer convention
            tilez = tilez - (ssState.Size.z-2);

            //add on the segment offset
            tilex = tilex + ssState.Position.x;
            tiley = tiley + ssState.Position.y;
            tilez = tilez + ssState.Position.z - 1;

            ssState.dfCursor.x = tilex;
            ssState.dfCursor.y = tiley;
            ssState.dfCursor.z = tilez;
        }
        timeToReloadSegment = true;
    }
}