Skip to content

Commit 9978c52

Browse files
committed
minor changes
1 parent f14d60d commit 9978c52

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

extras/videoDrivers/SDL2/VideoSDL2.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@
3131
#endif
3232

3333
#define CHECK_SDL(call) \
34-
do \
35-
{ \
34+
([&]() -> bool { \
3635
if((call) == -1) \
36+
{ \
3737
PrintError(SDL_GetError()); \
38-
} while(false)
38+
return false; \
39+
} \
40+
return true; \
41+
})()
3942

4043
namespace {
4144
template<typename T>
@@ -541,7 +544,7 @@ void VideoSDL2::MoveWindowToCenter()
541544
SDL_Rect usableBounds;
542545
CHECK_SDL(SDL_GetDisplayUsableBounds(SDL_GetWindowDisplayIndex(window), &usableBounds));
543546
int top, left, bottom, right;
544-
if(SDL_GetWindowBordersSize(window, &top, &left, &bottom, &right) != 0)
547+
if(CHECK_SDL(SDL_GetWindowBordersSize(window, &top, &left, &bottom, &right)) != 0)
545548
top = left = bottom = right = 0;
546549
usableBounds.w -= left + right;
547550
usableBounds.h -= top + bottom;

libs/s25main/Settings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ void Settings::Load()
322322
interface.mapScrollMode = static_cast<MapScrollMode>(iniInterface->getIntValue("map_scroll_mode"));
323323
} catch(const std::runtime_error&)
324324
{
325-
// ScrollSame(old invertMouse) is 0 so invert value
326-
interface.mapScrollMode = static_cast<MapScrollMode>(!iniInterface->getBoolValue("invert_mouse"));
325+
interface.mapScrollMode =
326+
iniInterface->getBoolValue("invert_mouse") ? MapScrollMode::ScrollSame : MapScrollMode::ScrollOpposite;
327327
s25util::warning(
328328
"Value 'map_scroll_mode' not found! Using 'invert_mouse' instead - please recheck your settings!");
329329
}

libs/s25main/TerrainRenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ void TerrainRenderer::Draw(const Position& firstPt, const Position& lastPt, cons
808808
#else
809809
// Modulate2x
810810
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
811-
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 2.0f);
811+
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, TEXTURE_COLOR_DIVISOR);
812812
#endif
813813

814814
// Disable alpha blending

libs/s25main/WindowManager.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#include "WindowManager.h"
66
#include "CollisionDetection.h"
77
#include "Loader.h"
8+
#include "Point.h"
89
#include "RttrConfig.h"
910
#include "Settings.h"
1011
#include "Window.h"
1112
#include "commonDefines.h"
1213
#include "desktops/Desktop.h"
14+
#include "driver/MouseCoords.h"
1315
#include "drivers/ScreenResizeEvent.h"
1416
#include "drivers/VideoDriverWrapper.h"
1517
#include "files.h"
@@ -26,8 +28,13 @@
2628
#include "s25util/MyTime.h"
2729
#include <algorithm>
2830

29-
// Calc square
30-
#define SQR(x) ((x) * (x))
31+
namespace {
32+
template<typename T>
33+
constexpr T square(T x)
34+
{
35+
return x * x;
36+
}
37+
} // namespace
3138

3239
WindowManager::WindowManager()
3340
: cursor_(Cursor::Hand), disable_mouse(false), lastMousePos(Position::Invalid()), curRenderSize(0, 0),
@@ -360,18 +367,18 @@ void WindowManager::Msg_LeftUp(MouseCoords mc)
360367
// Ggf. Doppelklick untersuche
361368
unsigned time_now = VIDEODRIVER.GetTickCount();
362369

363-
if(!VIDEODRIVER.IsTouch())
370+
if(VIDEODRIVER.IsTouch())
364371
{
365-
if(time_now - lastLeftClickTime < DOUBLE_CLICK_INTERVAL && mc.pos == lastLeftClickPos)
366-
mc.dbl_click = true;
372+
if(time_now - lastLeftClickTime < TOUCH_DOUBLE_CLICK_INTERVAL)
373+
{
374+
// Calculate distance between two points
375+
const PointF diff = static_cast<PointF>(mc.pos - lastLeftClickPos);
376+
if(square(diff.x) + square(diff.y) <= square(TOUCH_MAX_DOUBLE_CLICK_DISTANCE))
377+
mc.dbl_click = true;
378+
}
367379

368-
} else if(time_now - lastLeftClickTime < TOUCH_DOUBLE_CLICK_INTERVAL)
369-
{
370-
// Calculate distance between two points
371-
unsigned cDistance = SQR(mc.pos.x - lastLeftClickPos.x) + SQR(mc.pos.y - lastLeftClickPos.y);
372-
if(cDistance <= SQR(TOUCH_MAX_DOUBLE_CLICK_DISTANCE))
373-
mc.dbl_click = true;
374-
}
380+
} else if(time_now - lastLeftClickTime < DOUBLE_CLICK_INTERVAL && mc.pos == lastLeftClickPos)
381+
mc.dbl_click = true;
375382

376383
if(!mc.dbl_click)
377384
{

libs/s25main/desktops/dskGameInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class dskGameInterface :
117117
/// Updatet das Post-Icon mit der Nachrichtenanzahl und der Taube
118118
void UpdatePostIcon(unsigned postmessages_count, bool showPigeon);
119119

120-
/// Wird beim Linksklick ausgeführt und überprüft die klick Position auf Gebäude/Straßen
120+
/// Executed during left click. Checks click pos for buildings/roads
121121
bool ContextClick(const MouseCoords& mc);
122122

123123
void Msg_ButtonClick(unsigned ctrl_id) override;

0 commit comments

Comments
 (0)