-
Notifications
You must be signed in to change notification settings - Fork 351
Add "query playground" #406
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
Merged
cwillisf
merged 9 commits into
scratchfoundation:develop
from
cwillisf:playground-webpack
Feb 14, 2019
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
31db3d8
Build playground using Webpack
fba2d90
Stub queryPlayground.html
e8d7127
Use query playground to compare GPU vs. CPU implementations
a358c8f
Lint cleanup
992977d
Add debug canvas support to isTouching CPU path
99d6e46
Adjust rendering for crisp pixels
59cef02
Mark correct viewport corners with red dots
028b4eb
Adjust cursor coordinates for devicePixelRatio
c390124
Convert 'force GPU' flag into 'useGpuMode' enum
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['scratch'], | ||
env: { | ||
browser: true | ||
}, | ||
rules: { | ||
'no-console': 'off' | ||
} | ||
}; |
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,37 @@ | ||
// Adapted from code by Simon Sarris: http://stackoverflow.com/a/10450761 | ||
const getMousePos = function (event, element) { | ||
const stylePaddingLeft = parseInt(document.defaultView.getComputedStyle(element, null).paddingLeft, 10) || 0; | ||
const stylePaddingTop = parseInt(document.defaultView.getComputedStyle(element, null).paddingTop, 10) || 0; | ||
const styleBorderLeft = parseInt(document.defaultView.getComputedStyle(element, null).borderLeftWidth, 10) || 0; | ||
const styleBorderTop = parseInt(document.defaultView.getComputedStyle(element, null).borderTopWidth, 10) || 0; | ||
|
||
// Some pages have fixed-position bars at the top or left of the page | ||
// They will mess up mouse coordinates and this fixes that | ||
const html = document.body.parentNode; | ||
const htmlTop = html.offsetTop; | ||
const htmlLeft = html.offsetLeft; | ||
|
||
// Compute the total offset. It's possible to cache this if you want | ||
let offsetX = 0; | ||
let offsetY = 0; | ||
if (typeof element.offsetParent !== 'undefined') { | ||
do { | ||
offsetX += element.offsetLeft; | ||
offsetY += element.offsetTop; | ||
} while ((element = element.offsetParent)); | ||
} | ||
|
||
// Add padding and border style widths to offset | ||
// Also add the <html> offsets in case there's a position:fixed bar | ||
// This part is not strictly necessary, it depends on your styling | ||
offsetX += stylePaddingLeft + styleBorderLeft + htmlLeft; | ||
offsetY += stylePaddingTop + styleBorderTop + htmlTop; | ||
|
||
// We return a simple javascript object with x and y defined | ||
return { | ||
x: event.pageX - offsetX, | ||
y: event.pageY - offsetY | ||
}; | ||
}; | ||
|
||
module.exports = getMousePos; |
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.
Maybe this is a weird idea. What if this wasn't drawing but was calling delegate methods. Methods on debugCanvasContext. Then the different playground pages could change what they use about this data if that would be useful.
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.
I like the idea of delegates. That could also solve another problem I've been having, where using "the" debug canvas is basically impossible in some projects since you only get a brief glimpse of the thing you're interested in before the canvas gets overwritten by the next thing. This could be solved by including some basic context info when calling the delegate method so the delegate could decide which data to handle, and how.
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.
I explored this idea a bit and it started getting super complicated, mainly due to the differences between the CPU and GPU paths. It might be better (or at least easier) to have canvas-fetching delegates or something like that... I dunno. Anyway, I still like the idea but I think I'm filing it under "future work"...