Commit 7c1d5527 authored by Nicolas Hadacek's avatar Nicolas Hadacek
Browse files

bug fix

svn path=/trunk/kdegames/kmines/; revision=64598
parent 8db08fe3
2.0.9
* fix obscure bug reported by Tobias Oed (was crashing version 1.0.1a !)
: mouse buttons were messing things when pressed simultaneously.
* in the same move : simplified some code and correct a small buglet due to
rounding error (with left mouse button pressed, the first line and first
column case was pressed when the mouse was moved just outside the top and
left side of the field).
2.0.8
* fix bug that was pausing a stopped game when calling highscores
......
IDEAS:
* 3 button mouse emulation [someone needed it for wheel mouse : I think
* 3 button mouse emulation [someone seems to need it for wheel mouse : I think
it should be done at a higher level ...]
* do you have any idea ?
......
......@@ -11,7 +11,7 @@ struct Case {
enum GameType { Easy = 0, Normal, Expert, Custom, NbLevels };
enum GameState { Stopped, Playing, Paused };
enum MouseAction { Reveal = 0, AutoReveal, Mark, UMark };
enum MouseAction { Reveal = 0, AutoReveal, Mark, UMark, None };
enum MouseButton { Left = 0, Mid, Right };
struct Level {
......
#include "field.h"
#include <math.h>
#include <qlayout.h>
#include <qbitmap.h>
#include <qapplication.h>
......@@ -8,7 +10,7 @@
Field::Field(QWidget *parent, const char *name)
: QFrame(parent, name), lev(LEVELS[0]), random(0), state(Stopped),
u_mark(false), cursor(false), _reveal(false), _autoreveal(false)
u_mark(false), cursor(false)
{
setFrameStyle( QFrame::Box | QFrame::Raised );
setLineWidth(2);
......@@ -177,6 +179,7 @@ void Field::restart(bool repaint)
state = Playing;
first_click = true;
currentAction = None;
ic = lev.width/2;
jc = lev.height/2;
......@@ -233,13 +236,14 @@ int Field::jToY(uint j) const
int Field::xToI(int x) const
{
// the cast is necessary when x-frameWidth() is negative (?)
return (int)((double)(x - frameWidth())/cp.size) + 1;
double d = (double)(x - frameWidth()) / cp.size;
return (int)floor(d) + 1;
}
int Field::yToJ(int y) const
{
return (int)((double)(y - frameWidth())/cp.size) + 1;
double d = (double)(y - frameWidth()) / cp.size;
return (int)floor(d) + 1;
}
void Field::uncover(uint i, uint j)
......@@ -275,52 +279,62 @@ MouseAction Field::mapMouseButton(QMouseEvent *e) const
}
}
void Field::mousePressEvent(QMouseEvent *e)
bool Field::revealActions(bool press)
{
if ( state!=Playing ) return;
setMood(Smiley::Stressed);
bool inside = placeCursor(xToI(e->pos().x()), yToJ(e->pos().y()));
switch ( mapMouseButton(e) ) {
switch (currentAction) {
case Reveal:
_reveal = true;
if (inside) pressCase(ic, jc, true);
break;
case Mark:
if (inside) mark();
break;
case UMark:
if (inside) umark();
break;
pressCase(ic, jc, press);
return true;
case AutoReveal:
_autoreveal = true;
if (inside) pressClearFunction(ic, jc, true);
break;
pressClearFunction(ic, jc, press);
return true;
default:
return false;
}
}
void Field::mousePressEvent(QMouseEvent *e)
{
if ( state!=Playing || currentAction!=None ) return;
setMood(Smiley::Stressed);
currentAction = mapMouseButton(e);
if ( !placeCursor(xToI(e->pos().x()), yToJ(e->pos().y())) ) return;
if ( !revealActions(true) )
switch (currentAction) {
case Mark:
mark();
break;
case UMark:
umark();
break;
default:
break;
}
}
void Field::mouseReleaseEvent(QMouseEvent *e)
{
if ( state!=Playing ) return;
MouseAction ma = mapMouseButton(e);
if ( ma!=currentAction ) return;
setMood(Smiley::Normal);
revealActions(false);
currentAction = None;
if (_autoreveal) {
pressClearFunction(ic, jc, false);
_autoreveal = false;
}
_reveal = false;
if ( !placeCursor(xToI(e->pos().x()), yToJ(e->pos().y())) ) return;
switch ( mapMouseButton(e) ) {
switch (ma) {
case Reveal:
reveal();
break;
case Mark:
case UMark:
break;
case AutoReveal:
autoReveal();
break;
default:
break;
}
}
......@@ -328,11 +342,13 @@ void Field::mouseMoveEvent(QMouseEvent *e)
{
if ( state!=Playing ) return;
if (_reveal) pressCase(ic, jc, false);
if (_autoreveal) pressClearFunction(ic, jc, false);
if ( !placeCursor(xToI(e->pos().x()), yToJ(e->pos().y())) ) return;
if (_reveal) pressCase(ic, jc, true);
else if (_autoreveal) pressClearFunction(ic, jc, true);
int i = xToI(e->pos().x());
int j = yToJ(e->pos().y());
if ( i==(int)ic && j==(int)jc ) return; // avoid flicker
revealActions(false);
if ( !placeCursor(i, j) ) return;
revealActions(true);
}
void Field::showMines()
......
......@@ -71,8 +71,8 @@ class Field : public QFrame
bool u_mark, cursor;
uint ic, jc; // current pos
bool _reveal, _autoreveal; // mouse button pressed
MouseAction mb[3]; // mouse bindings
MouseAction currentAction;
CaseProperties cp;
QPixmap pm_flag, pm_mine, pm_exploded, pm_error;
......@@ -90,6 +90,7 @@ class Field : public QFrame
void flagPixmap(QPixmap &, bool mask) const;
void autoReveal();
void _endGame();
bool revealActions(bool press);
const Case &pfield(uint i, uint j) const;
Case &pfield(uint i, uint j);
......@@ -108,7 +109,7 @@ class Field : public QFrame
void setUMark(bool um) { u_mark = um; }
void setCaseProperties(const CaseProperties &);
void setCursor(bool show);
MouseAction mapMouseButton(QMouseEvent *e) const;
MouseAction mapMouseButton(QMouseEvent *) const;
};
#endif // FIELD_H
#define VERSION "2.0.8"
#define LONG_VERSION "2.0.8 (6 September 2000)"
#define VERSION "2.0.9"
#define LONG_VERSION "2.0.9 (21 September 2000)"
#define COPYLEFT "(c) 1996-2000, Nicolas Hadacek"
#define EMAIL "hadacek@kde.org"
#define HOMEPAGE "http://azhyd.free.fr/KDE/kmines.php3"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment