Skip to content

s25edit backports from s25client#37

Open
morganchristiansson wants to merge 8 commits into
Return-To-The-Roots:masterfrom
morganchristiansson:resize-window
Open

s25edit backports from s25client#37
morganchristiansson wants to merge 8 commits into
Return-To-The-Roots:masterfrom
morganchristiansson:resize-window

Conversation

@morganchristiansson

Copy link
Copy Markdown
  • Allow window resizing
  • Fix segfault with small map&large screen
  • Fix black area with small map&large screen
  • Fix mouse panning on Linux
  • Zoom with mouse wheel

@Flamefire Flamefire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, that definitely improves it!
Some notes inline, a common theme is that any pair of x/y or width/height values should use either Point/PointF or Extent which avoids C&P errors and makes processing easier (single assignment instead of 2, operator support for combining with other Points)
Note: In some places fixed-size variants are used. That is historical and not necessary in almost all cases, so no need to introduce new uses of them unless there is a specific reason for the size requirement.

Thanks again!

Comment thread CMap.cpp Outdated
// we subtract "TRIANGLE_WIDTH/2" Xeven = (MouseX + displayRect.left) / TRIANGLE_WIDTH;
Xeven = (MouseX + displayRect.left - TRIANGLE_WIDTH / 2) / TRIANGLE_WIDTH;
if(Xeven < 0)
while(Xeven < 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this could be a module operation and a single check to account for negative results (possible because neg. values are implementation defined)

@morganchristiansson morganchristiansson Jun 16, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah agree. This was just smallest/simplest fix to a segfault and I didn't care to correct it.
But you're right we should use modulo operation.

Comment thread CMap.cpp Outdated
while(MousePosY < 0)
MousePosY += map->height_pixel;
else if(MousePosY > map->height_pixel)
while(MousePosY > map->height_pixel)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be an infinite loop

Comment thread CMap.cpp
moveMap(offset);

// this whole "warping-thing" is to prevent cursor-moving WITHIN the window while user moves over the map
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change? Isn't handling this "issue" here better where it is caused than where mouse moves should be handled?
IIRC SDL offers a relative mouse mode. As we only support SDL here that might be the best solution if we change this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is matching current s25client VideoSDL2.cpp which doesn't use SDL_EventState.

Comment thread CGame_Event.cpp
if(!mapObj || !mapObj->getMap())
return;
callback::PleaseWait(INITIALIZING_CALL);
TRIANGLE_HEIGHT = 28;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have constants for that? Best using e.g. constexpr Extent DEFAULT_TRIANGLE_SIZE(28, 56) and use that here and in the initialization

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how zoom is currently implemented in s25editor, by writing to uppercase variables.
I just extracted to shared function for mouse wheel zoom.
The zoom is listed as experimental in F1 help.

Comment thread CGame_Event.cpp Outdated
if(y == 0)
break;

const int deltaTH = (y > 0) ? 5 : -5;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the Point/Position/Extent for X/Y or W/H values. We had too many C&P issues in the past

Comment thread CGame_Event.cpp Outdated
const float ratioX = TRIANGLE_WIDTH / oldWidth;
const float ratioY = TRIANGLE_HEIGHT / oldHeight;
const auto size = dr.getSize();
dr.left = static_cast<Sint32>((dr.left + mouseX) * ratioX - mouseX);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can then use the Point operators like (dr.origin + mousePos) * ratioX - mousPos
Maybe even just dr.move()

Comment thread CGame_Event.cpp

case SDL_WINDOWEVENT:
{
switch(Event->window.event)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as this is the only even please use a simple if which is less verbose and avoids the double-break

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread CGame_Init.cpp Outdated
GameResolution.x = width;
GameResolution.y = height;
displayTexture_.reset();
displayTexture_ = makeSdlTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same code is in ReCreateWindow, and maybe somewhere else. Can you make those call this function (or the other way round if better)?

Comment thread CGame_Init.cpp Outdated
return true;
}

void CGame::UpdateDisplaySize(unsigned width, unsigned height)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Extent for the parameter

Comment thread CMap.cpp
// clear the surface before drawing new (in normal case not needed)
// SDL_FillRect( Surf_Map, nullptr, SDL_MapRGB(Surf_Map->format,0,0,0) );
// Clear the surface before drawing so areas not covered by triangles stay black
SDL_FillRect(Surf_Map.get(), nullptr, SDL_MapRGBA(Surf_Map->format, 0, 0, 0, 0));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though it may have been intended at some point: Why is this required?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To draw black background for small map&large screen.
Otherwise mouse and map leave trails that are not drawn over.

@morganchristiansson

Copy link
Copy Markdown
Author

Maybe I should split this into smaller PRs.

I was working on import heightmap as I posted about on Discord, not sure I will submit as PR. And these were some quality of life improvements that felt important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants