Skip to content

FlipBook: Image replacement and event handlers#15

Merged
pgrit merged 42 commits intopgrit:masterfrom
OpaKnoppi:master
Feb 18, 2026
Merged

FlipBook: Image replacement and event handlers#15
pgrit merged 42 commits intopgrit:masterfrom
OpaKnoppi:master

Conversation

@OpaKnoppi
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread SimpleImageIO/Image.cs Outdated
}

/// <summary>
/// Calculates the absolute Difference from two equal-sized images with equal channel count
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
/// Calculates the absolute Difference from two equal-sized images with equal channel count
/// Calculates the absolute difference |a - b| of two equal-sized images with equal channel count

Comment thread SimpleImageIO/FlipBook.cs
Comment thread SimpleImageIO/FlipBook.cs
Comment thread SimpleImageIO/FlipBook.cs Outdated
Comment on lines +436 to +437
if (String.IsNullOrEmpty(this.containerId))
this.containerId = id;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why do you only store it the first time?

Seems like this could yield confusing behavior if the same flip book is generated multiple times.

Comment thread SimpleImageIO/FlipBook.cs Outdated
Comment on lines +557 to +575

// string json = $$"""
// {
// "width": {},
// "height": {},
// "containerId": "{}",
// "initialZoom": {},
// "initialTMO": {},
// "initialTMOOverrides": [
// {}
// ],
// "names": [{{string.Join(',', nameStrs.Select(n => $"\"{n}\""))}}],
// "dataUrls": [{{string.Join(',', dataStrs.Select(n => $"\"{n}\""))}}],
// "types": [{{string.Join(',', typeStrs.Select(n => $"\"{n}\""))}}],
// "colorTheme": "{}",
// "groupName": "{{groupName}}",
// "hideTools": {}
// }
// """;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
// string json = $$"""
// {
// "width": {},
// "height": {},
// "containerId": "{}",
// "initialZoom": {},
// "initialTMO": {},
// "initialTMOOverrides": [
// {}
// ],
// "names": [{{string.Join(',', nameStrs.Select(n => $"\"{n}\""))}}],
// "dataUrls": [{{string.Join(',', dataStrs.Select(n => $"\"{n}\""))}}],
// "types": [{{string.Join(',', typeStrs.Select(n => $"\"{n}\""))}}],
// "colorTheme": "{}",
// "groupName": "{{groupName}}",
// "hideTools": {}
// }
// """;

Comment thread FlipViewer/src/ImageContainer.tsx Outdated
Comment on lines +303 to +304
var relX = event.nativeEvent.offsetX;: nativeEvent.
var relY = event.nativeEvent.offsetY;: nativeEvent.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

what happened here?

Comment thread FlipViewer/src/ImageContainer.tsx Outdated
Comment on lines +282 to +287
if (this.props.onWheel)
{
this.props.onWheel(event.deltaY);
}

return;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not tested, but sounds like quite awkward UX to have ALT as a means to override the zoom behavior but also then forward this wheel event in the flip book context?

Comment thread FlipViewer/src/flipviewer.ts Outdated
Comment thread FlipViewer/src/flipviewer.ts Outdated
Comment thread FlipViewer/src/flipviewer.ts Outdated
tms[book.state.selectedIdx].setPixels(images[0] as (Float32Array<ArrayBufferLike>));
}

// flipBook.imageContainer.current.props.rawPixels[flipBook.state.selectedIdx] = images[0] as (Float32Array<ArrayBufferLike>); //TODO: maybe it doesnt work like that
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

?

Comment thread FlipViewer/src/ImageContainer.tsx Outdated
import { JSX } from 'react/jsx-runtime';

export type OnClickHandler = (col: number, row: number, event: MouseEvent) => void
export type OnClickHandler = (buttom: number) => void
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why is the OnClickHandler now only reporting the button, not the clicked pixel?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because OnMouseOverHandler does that. C# stores the current pixel. In some situations, the mouse is not pressed (but only keys) and when I press keys for some actions on the c# side, I still have the current pixel coords.

@pgrit pgrit changed the title template changes FlipBook: Image replacement and event handlers Jan 15, 2026
Comment thread FlipViewer/src/ImageContainer.tsx Outdated
export interface ListenerState {
/// Mouse state
mouseButtom: number;
mouseX: number;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Should document the coordinate system here: Relative to image? Screen space coordinates wrt the Container?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

"top left of image" / "relative to image" still does not specify the units ;) Is it pixels of the image? Browser pixels? Sth else?

Comment thread FlipViewer/src/ImageContainer.tsx Outdated
Comment on lines +34 to +36
let magnifierResolution = 1;
let flagXSwapped = false;
let flagYSwapped = false;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This should be tracked in each container's individual state rather than globally.
Also, the swapping behaviour should probably reset to the default position when the mouse is clicked and only remain in the current state during move events.

Comment thread FlipViewer/src/ImageContainer.tsx Outdated
Comment on lines +38 to +41
let isAnyKeyPressed = false;
export function setKeyPressed(value: boolean): void {
isAnyKeyPressed = value;
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is it a good idea to track this as global state across all flip books?

Comment thread FlipViewer/src/ImageContainer.tsx Outdated
Comment on lines +8 to +11
export type OnClickHandler = (mouseButton: number, mouseX: number, mouseY: number, deltaY: number, ID: string, selectedIdx: number, keyPressed: string, isPressed: boolean) => void
export type OnWheelHandler = (mouseButton: number, mouseX: number, mouseY: number, deltaY: number, ID: string, selectedIdx: number, keyPressed: string, isPressed: boolean) => void
export type OnMouseOverHandler = (mouseButton: number, mouseX: number, mouseY: number, deltaY: number, ID: string, selectedIdx: number, keyPressed: string, isPressed: boolean) => void
export type OnKeyHandler = (mouseButton: number, mouseX: number, mouseY: number, deltaY: number, ID: string, selectedIdx: number, keyPressed: string, isPressed: boolean) => void
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Does it make sense to send deltaY (I assume that is the mouse wheel motion?) for non-wheel events?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

And why do the click handlers now also report key event data?

Comment thread FlipViewer/src/ImageContainer.tsx Outdated

// Listener state that is forwared
export interface ListenerState {
/// Mouse state
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not really an informative comment. State of what exactly? What is the meaning of the value? How does a single number describe the state of your mouse?

Comment thread FlipViewer/src/ImageContainer.tsx Outdated
Comment on lines +23 to +30
/// Key state (Handled by the Flipbook.tsx)
// ID of the Flipbook
ID: string;
// Which image is selected in a Flipbook
selectedIdx: number;
// Key pressed
keyPressed: string;
isPressed: boolean;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Logic here is unclear to me. Do you only track a single key at a time? What happens if multiple keys are pressed simultaneously?

@pgrit pgrit merged commit a20f159 into pgrit:master Feb 18, 2026
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