File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 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):
44 From this point ed::EndCreate() and ed::EndDelete() can only be called when
55 ed::BeginCreate() and ed::BeginDelete() calls were successful.
66
7+ NEW: Canvas: Add example of zooming at fixed point (#270)
8+
79 CHANGE: Canvas: Use ImDrawCallback_ImCanvas macro as draw callback sentinel (#256), thanks @nspitko
810
911 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:
188188 canvas.SetView (drawStartPoint + ImGui::GetMouseDragDelta (1 , 0 .0f ) * viewScale, viewScale);
189189 }
190190 else if (isDragging)
191+ {
191192 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+ }
192212
193213 viewRect = canvas.ViewRect ();
194214
You can’t perform that action at this time.
0 commit comments