00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <GLW/GLWTracker.h>
00022 #include <GLW/GLWFont.h>
00023 #include <GLW/GLWToolTip.h>
00024 #include <GLEXT/GLState.h>
00025 #include <common/Keyboard.h>
00026 #include <common/ToolTipResource.h>
00027 #include <graph/OptionsDisplay.h>
00028 #include <client/ScorchedClient.h>
00029 #include <tank/TankContainer.h>
00030 #include <tank/TankState.h>
00031 #include <tank/TankPosition.h>
00032 #include <lang/LangResource.h>
00033
00034 REGISTER_CLASS_SOURCE(GLWTracker);
00035
00036 GLWTracker::GLWTracker(float x, float y, float w, float range) :
00037 GLWidget(x, y, w, w),
00038 range_(range),
00039 dragging_(false), handler_(0), currentX_(0.0f), currentY_(0.0f)
00040 {
00041
00042 }
00043
00044 GLWTracker::~GLWTracker()
00045 {
00046
00047 }
00048
00049 void GLWTracker::mouseDown(int button, float x, float y, bool &skipRest)
00050 {
00051 if (inBox(x, y, x_, y_, w_, h_))
00052 {
00053 skipRest = true;
00054 dragging_ = true;
00055 }
00056 }
00057
00058 void GLWTracker::mouseUp(int button, float x, float y, bool &skipRest)
00059 {
00060 dragging_ = false;
00061 }
00062
00063 void GLWTracker::mouseDrag(int button, float mx, float my, float x, float y, bool &skipRest)
00064 {
00065 if (dragging_)
00066 {
00067 float rangeMult = 1.0f;
00068 unsigned int keyState =
00069 Keyboard::instance()->getKeyboardState();
00070 if (keyState & KMOD_LSHIFT) rangeMult = 0.5f;
00071
00072 currentX_ -= x / w_ * range_ * rangeMult;
00073 if (OptionsDisplay::instance()->getInvertElevation())
00074 {
00075 rangeMult = -rangeMult;
00076 }
00077 currentY_ -= y /w_ * range_ * rangeMult;
00078 if (handler_) handler_->currentChanged(getId(), currentX_, currentY_);
00079
00080 skipRest = true;
00081 }
00082 }
00083
00084 REGISTER_CLASS_SOURCE(GLWTankTracker);
00085
00086 GLWTankTracker::GLWTankTracker() :
00087 GLWTracker(0.0f, 0.0f, 0.0f, 100.0f)
00088 {
00089 setHandler(this);
00090 setToolTip(new ToolTipResource(ToolTip::ToolTipHelp,
00091 "ROTATION_ELEVATION", "Rotation/Elevation",
00092 "ROTATION_ELEVATION_TOOLTIP",
00093 "Change the rotation and elevation of the\n"
00094 "current tank by clicking with the left\n"
00095 "mouse button and dragging up and down,\n"
00096 "left and right.\n"
00097 "Shift key decreases sensitivity."));
00098 }
00099
00100 GLWTankTracker::~GLWTankTracker()
00101 {
00102 }
00103
00104 void GLWTankTracker::draw()
00105 {
00106 Tank *currentTank =
00107 ScorchedClient::instance()->getTankContainer().getCurrentTank();
00108 if (currentTank)
00109 {
00110 if (currentTank->getState().getState() == TankState::sNormal)
00111 {
00112 setCurrentX(currentTank->getPosition().getRotationGunXY().asFloat());
00113 setCurrentY(currentTank->getPosition().getRotationGunYZ().asFloat());
00114 }
00115 }
00116 GLWTracker::draw();
00117 }
00118
00119 void GLWTankTracker::currentChanged(unsigned int id, float valueX, float valueY)
00120 {
00121 Tank *currentTank =
00122 ScorchedClient::instance()->getTankContainer().getCurrentTank();
00123 if (currentTank)
00124 {
00125 if (currentTank->getState().getState() == TankState::sNormal)
00126 {
00127 if (id == getId())
00128 {
00129 currentTank->getPosition().rotateGunXY(fixed::fromFloat(valueX), false);
00130 currentTank->getPosition().rotateGunYZ(fixed::fromFloat(valueY), false);
00131 }
00132 }
00133 }
00134 }