-
Notifications
You must be signed in to change notification settings - Fork 9
Template changes #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
OpaKnoppi
wants to merge
8
commits into
pgrit:master
Choose a base branch
from
OpaKnoppi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Template changes #27
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fe90113
template changes
OpaKnoppi 4fb92d0
removed css style out of experiment file as it should be
OpaKnoppi 32d06c2
removed old comments, isPressedDown -> isPressed
OpaKnoppi ccab86d
removed old comments, isPressedDown -> isPressed
OpaKnoppi e750214
seperated example experiment and template experiment, added BaseExper…
OpaKnoppi 2a2a421
Added example template to see all new features and how to use/impleme…
OpaKnoppi 485227b
clean up in templates
OpaKnoppi a47a47d
adapt template to changes in SSIO
OpaKnoppi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
SeeSharp.Templates/content/SeeSharp.Blazor.Template/Pages/BaseExperiment.razor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Components; | ||
| using Microsoft.JSInterop; | ||
| using SeeSharp.Blazor; | ||
|
|
||
| namespace SeeSharp.Blazor.Template.Pages; | ||
|
|
||
| public struct ListenerState { | ||
| public ListenerState() { } | ||
|
|
||
| /// <summary> | ||
| /// The index of the selected image of the current selected flipbook (selected by clicking on it) | ||
| /// </summary> | ||
| public int selectedIndex = 0; | ||
|
|
||
| /// <summary> | ||
| /// Number between 0 and NumSamples. Can be used if data is stored from different iterations | ||
| /// </summary> | ||
| public int currIteration = 0; | ||
|
|
||
| // Add here all action keys for your functionalities | ||
| // Attention: any key press disables the default html scrolling! | ||
| public string actionKey1 = "a"; | ||
| public string actionKey2 = "d"; | ||
| public bool actionKey1Pressed = false; | ||
| public bool actionKey2Pressed = false; | ||
|
|
||
| public int currX = 0; | ||
| public int currY = 0; | ||
|
|
||
| /// <summary> | ||
| /// The key of the current flipbook | ||
| /// </summary> | ||
| public string currFlipKey = ""; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Differences between event type so update methods for flipbooks can ignore events | ||
| /// </summary> | ||
| public enum FiredType { | ||
| Click = 0, | ||
| Move = 1, | ||
| Wheel = 2, | ||
| KeyDown = 4, | ||
| KeyUp = 8, | ||
| } | ||
|
|
||
| public partial class BaseExperiment : ComponentBase { | ||
| protected const int Width = 1280; | ||
| protected const int Height = 720; | ||
| protected const int FlipWidth = 660; | ||
| protected const int FlipHeight = 580; | ||
| protected const int MaxDepth = 10; | ||
| public int NumSamples = 2; | ||
|
|
||
| /// <summary> | ||
| /// Registers all Flipbooks | ||
| /// Key will be the stringified key of a Flipbook which is set by Flipbook.SetKey | ||
| /// A Flipbook key is an array of ints | ||
| /// </summary> | ||
| protected Dictionary<string, FlipBook> registry = new Dictionary<string, FlipBook>(); | ||
| protected ListenerState state = new ListenerState(); | ||
| public static string Reverse(string s) { | ||
| char[] charArray = s.ToCharArray(); | ||
| Array.Reverse(charArray); | ||
| return new string(charArray); | ||
| } | ||
|
|
||
| // SurfacePoint? selected; | ||
| // void OnFlipClick(FlipViewer.OnClickEventArgs args) { | ||
| // if (args.CtrlKey) { | ||
| // selected = scene.RayCast(new(args.X, args.Y)); | ||
| // } | ||
| // } | ||
|
|
||
| /// <summary> | ||
| /// Is fired when clicked on an image in the flipbook | ||
| /// </summary> | ||
| /// <param name="args">ListenerState from HMTL side</param> | ||
| public virtual void OnFlipClick(FlipViewer.OnClickEventArgs args) { | ||
| updateFlipbook(FiredType.Click); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Is fired when the mouse wheel state changes over an image. | ||
| /// This gets only called when the alt key is pressed (from HTML side) | ||
| /// </summary> | ||
| /// <param name="args">ListenerState from HMTL side.</param> | ||
| public virtual void OnFlipWheel(FlipViewer.OnClickEventArgs args) { | ||
| if (state.actionKey1Pressed) { | ||
| // scrolled up | ||
| if (args.deltaY < 0) { | ||
| if (state.currIteration < NumSamples - 1) { | ||
| state.currIteration++; | ||
| updateFlipbook(FiredType.Wheel); | ||
| } | ||
| } | ||
| // scrolled down | ||
| if (args.deltaY >= 0) { | ||
| if (state.currIteration > 0) { | ||
| state.currIteration--; | ||
| updateFlipbook(FiredType.Wheel); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Is fired when mouse position changes over the selected flipbook | ||
| /// </summary> | ||
| /// <param name="args">ListenerState from HMTL side.</param> | ||
| public virtual void OnFlipMouseOver(FlipViewer.OnClickEventArgs args) { | ||
| if (state.currX == args.X && state.currY == args.Y) | ||
| return; | ||
|
|
||
| if (args.X >= 0 && args.X <= Width - 1) | ||
| state.currX = args.X; | ||
| if (args.Y >= 0 && args.Y <= Height - 1) | ||
| state.currY = args.Y; | ||
|
|
||
| updateFlipbook(FiredType.Move); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Is fired when key is pressed or released | ||
| /// </summary> | ||
| /// <param name="args">ListenerState from HMTL side.</param> | ||
| public virtual void OnFlipKey(FlipViewer.OnClickEventArgs args) { | ||
| if (args.key == state.actionKey1) | ||
| state.actionKey1Pressed = args.isPressed; | ||
|
|
||
| if (args.key == state.actionKey2) | ||
| state.actionKey2Pressed = args.isPressed; | ||
|
|
||
| state.currFlipKey = args.registryKey; | ||
| state.selectedIndex = args.selectedIndex; | ||
|
|
||
| if (args.key == state.actionKey1 && !args.isPressed) | ||
| state.currIteration = 0; | ||
|
|
||
| if (args.isPressed) | ||
| updateFlipbook(FiredType.KeyDown); | ||
| else | ||
| updateFlipbook(FiredType.KeyUp); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Catches fired events and forward events to selected flipbooks | ||
| /// </summary> | ||
| /// <param name="fired">Fired type</param> | ||
| public virtual void updateFlipbook(FiredType fired) { | ||
| if (String.IsNullOrEmpty(state.currFlipKey)) | ||
| return; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Runs the experiment when "..." is pressed on the HTML | ||
| /// </summary> | ||
| public virtual void RunExperiment() { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Is executed when Download button is pressed on the HTML | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public virtual async Task OnDownloadClick() { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if fwd-ing the wheel is a good idea from a usability perspective. What's the usage scenario?