I'm sorry, better description:
I'm using your code from wiki and what I want to achieve:
- draw scene with sprites (sun) etc. + move view + zoom view to pixel
- draw GUI over this scene (this black box with text), 1:1, without any transformations
Scene:
https://imgur.com/a/IIdk31) Your code without changes, working -
2) When I call window.setView(ViewGUI) -
In first seconds is your function, it doesn't work anymore, it reset View.
From cca 5 sec. there is my code based on your, it works +- but view follows mouse cursor
I made global variable Zoom (zoom = zoom + 0.01) and put zoomViewAt() into drawing function.
Probably I can fix this mouse following but I'm not sure if it's right way or not, these view seems little bit tricky. The solution could be simpler as your suggestion. But I do not know exactly where to use it.
My code (it's not C but commands have similar syntax):
Procedure SFML_DRAW;
begin
if ViewResized then begin // when is window resized
sfRenderWindow_setSize(renderWindow, PanelSize_u );
sfView_reset( View, ViewRect );
sfView_reset( View_GUI, ViewRect_GUI );
ViewResized := false;
end;
// MAIN SCENE
sfview_move( view, ViewPos ); // arrow keys = move view to sides
// sfRenderWindow_setView( RenderWindow, View );
zoomViewAt( mouse, RenderWindow, Zoom ); // Zoom
// View := sfRenderWindow_getView( RenderWindow );
// Draw sprites
spr_Draw_I( renderWindow, tex_sun, sun_pos.x, sun_pos.y, 0, 0, 0 );
spr_Draw_I( renderWindow, tex_sun, 200, 100, 0, 0, 0 );
// Screen boundary
Draw_Rect_Line( -1, -1, Form1.Panel1.width + 1, Form1.Panel1.height + 1, 180, sfGreen );
// GUI
//sfView_reset( View, ViewRect );
sfRenderWindow_setView( RenderWindow, View_GUI );
Game.DrawInfo( Form1.Panel1.Width - 210, 0, 12 ); // Black box with text
end;
Controls:
//GET_WHEEL_DELTA_WPARAM(wParam);
WM_MOUSEWHEEL : if Smallint(HiWord(wParam)) < 0 then begin
//sfRenderWindow_setView( RenderWindow, View );
zoomViewAt( Mouse, RenderWindow, 1.1 );
//View := sfRenderWindow_getView( RenderWindow );
end else begin
// sfRenderWindow_setView( RenderWindow, View );
zoomViewAt( Mouse, RenderWindow, (1 / 1.1) );
//View := sfRenderWindow_getView( RenderWindow );
end;
if sfKeyboard_isKeyPressed(sfKeyU) = 1 then
begin
Zoom := Zoom + 0.01;
end;
if sfKeyboard_isKeyPressed(sfKeyI) = 1 then
begin
if zoom > 0.01 then Zoom := Zoom - 0.01;
end;