File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ v0.10.0 (WIP):
4
4
From this point ed::EndCreate() and ed::EndDelete() can only be called when
5
5
ed::BeginCreate() and ed::BeginDelete() calls were successful.
6
6
7
+ NEW: Canvas: Add example of zooming at fixed point (#270)
8
+
7
9
CHANGE: Canvas: Use ImDrawCallback_ImCanvas macro as draw callback sentinel (#256), thanks @nspitko
8
10
9
11
BUGFIX: Examples: Call ed::EndCreate() and ed::EndDelete() only when ed::BeginCreate() and ed::BeginDelete() returned true
Original file line number Diff line number Diff line change @@ -188,7 +188,27 @@ struct Example:
188
188
canvas.SetView (drawStartPoint + ImGui::GetMouseDragDelta (1 , 0 .0f ) * viewScale, viewScale);
189
189
}
190
190
else if (isDragging)
191
+ {
191
192
isDragging = false ;
193
+ }
194
+ else if (!isDragging && ImGui::IsItemHovered () && io.MouseWheel )
195
+ {
196
+ auto mousePos = io.MousePos ;
197
+
198
+ // apply new view scale
199
+ auto oldView = canvas.View ();
200
+ auto newViewScale = viewScale * powf (1 .1f , io.MouseWheel );
201
+ canvas.SetView (viewOrigin, newViewScale);
202
+ auto newView = canvas.View ();
203
+
204
+ // calculate origin offset to keep mouse position fixed
205
+ auto screenPosition = canvas.FromLocal (mousePos, oldView);
206
+ auto canvasPosition = canvas.ToLocal (screenPosition, newView);
207
+ auto originOffset = (canvasPosition - mousePos) * newViewScale;
208
+
209
+ // apply new view
210
+ canvas.SetView (viewOrigin + originOffset, newViewScale);
211
+ }
192
212
193
213
viewRect = canvas.ViewRect ();
194
214
You can’t perform that action at this time.
0 commit comments