Make the blur as-close to the css one as possible

This commit is contained in:
Dariusz Niemczyk 2021-08-17 17:47:40 +02:00
parent a999cad49d
commit 2ee26d0681
No known key found for this signature in database
GPG key ID: 28DFE7164F497CB6
4 changed files with 22 additions and 27 deletions

View file

@ -29,7 +29,7 @@ limitations under the License.
top: 0; top: 0;
height: 100vh; height: 100vh;
width: 100%; width: 100%;
background-color: rgba(255, 255, 255, .02); background-color: rgba(255, 255, 255, .055);
} }
} }
@ -42,10 +42,10 @@ limitations under the License.
pointer-events: none; pointer-events: none;
overflow: hidden; overflow: hidden;
&:first-of-type { &:nth-of-type(2n-1) {
opacity: 0.19; opacity: 0.2;
} }
&:last-of-type { &:nth-of-type(2n) {
opacity:0.12; opacity:0.1;
} }
} }

View file

@ -240,8 +240,8 @@ $appearance-tab-border-color: $room-highlight-color;
// blur amounts for left left panel (only for element theme, used in _mods.scss) // blur amounts for left left panel (only for element theme, used in _mods.scss)
:root { :root {
--roomlist-background-blur-amount: 60px; --llp-background-blur: 60px;
--groupFilterPanel-background-blur-amount: 30px; --lp-background-blur: 30px;
} }
$composer-shadow-color: rgba(0, 0, 0, 0.28); $composer-shadow-color: rgba(0, 0, 0, 0.28);

View file

@ -363,8 +363,8 @@ $appearance-tab-border-color: $input-darker-bg-color;
// blur amounts for left left panel (only for element theme, used in _mods.scss) // blur amounts for left left panel (only for element theme, used in _mods.scss)
:root { :root {
--roomlist-background-blur-amount: 40px; --llp-background-blur: 40px;
--groupFilterPanel-background-blur-amount: 20px; --lp-background-blur: 20px;
} }
$composer-shadow-color: rgba(0, 0, 0, 0.04); $composer-shadow-color: rgba(0, 0, 0, 0.04);

View file

@ -78,16 +78,14 @@ export default class BackdropPanel extends React.PureComponent<IProps, IState> {
}; };
private refreshBackdropImage = (): void => { private refreshBackdropImage = (): void => {
const spacesCtx = this.leftLeftPanelRef.current.getContext("2d"); const leftLeftPanelContext = this.leftLeftPanelRef.current.getContext("2d");
const roomListCtx = this.leftPanelRef.current.getContext("2d"); const leftPanelContext = this.leftPanelRef.current.getContext("2d");
const { leftLeftPanelWidth, leftPanelWidth, height } = this.sizes; const { leftLeftPanelWidth, leftPanelWidth, height } = this.sizes;
const width = leftLeftPanelWidth + leftPanelWidth; const width = leftLeftPanelWidth + leftPanelWidth;
const { backgroundImage } = this.props; const { backgroundImage } = this.props;
const imageWidth = (backgroundImage as ImageBitmap).width const imageWidth = (backgroundImage as ImageBitmap).width;
|| (backgroundImage as HTMLImageElement).naturalWidth; const imageHeight = (backgroundImage as ImageBitmap).height;
const imageHeight = (backgroundImage as ImageBitmap).height
|| (backgroundImage as HTMLImageElement).naturalHeight;
const contentRatio = imageWidth / imageHeight; const contentRatio = imageWidth / imageHeight;
const containerRatio = width / height; const containerRatio = width / height;
@ -101,7 +99,9 @@ export default class BackdropPanel extends React.PureComponent<IProps, IState> {
resultHeight = width / contentRatio; resultHeight = width / contentRatio;
} }
const x = (width - resultWidth) / 2; // This value has been chosen to be as close with rendering as the css-only
// backdrop-filter: blur effect was, mostly takes effect for vertical pictures.
const x = width * 0.1;
const y = (height - resultHeight) / 2; const y = (height - resultHeight) / 2;
this.leftLeftPanelRef.current.width = leftLeftPanelWidth; this.leftLeftPanelRef.current.width = leftLeftPanelWidth;
@ -110,12 +110,12 @@ export default class BackdropPanel extends React.PureComponent<IProps, IState> {
this.leftPanelRef.current.height = height; this.leftPanelRef.current.height = height;
this.leftPanelRef.current.style.transform = `translateX(${leftLeftPanelWidth}px)`; this.leftPanelRef.current.style.transform = `translateX(${leftLeftPanelWidth}px)`;
const spacesBlur = this.style.getPropertyValue('--roomlist-background-blur-amount'); const spacesBlur = this.style.getPropertyValue('--llp-background-blur');
const roomListBlur = this.style.getPropertyValue('--groupFilterPanel-background-blur-amount'); const roomListBlur = this.style.getPropertyValue('--lp-background-blur');
spacesCtx.filter = `blur(${spacesBlur})`; leftLeftPanelContext.filter = `blur(${spacesBlur})`;
roomListCtx.filter = `blur(${roomListBlur})`; leftPanelContext.filter = `blur(${roomListBlur})`;
spacesCtx.drawImage( leftLeftPanelContext.drawImage(
backgroundImage, backgroundImage,
0, 0, 0, 0,
imageWidth, imageHeight, imageWidth, imageHeight,
@ -124,7 +124,7 @@ export default class BackdropPanel extends React.PureComponent<IProps, IState> {
resultWidth, resultWidth,
resultHeight, resultHeight,
); );
roomListCtx.drawImage( leftPanelContext.drawImage(
backgroundImage, backgroundImage,
0, 0, 0, 0,
imageWidth, imageHeight, imageWidth, imageHeight,
@ -146,13 +146,11 @@ export default class BackdropPanel extends React.PureComponent<IProps, IState> {
<img <img
className="mx_BackdropPanel--canvas" className="mx_BackdropPanel--canvas"
style={{ style={{
opacity: .19,
}} }}
src={this.state.llpImage} /> src={this.state.llpImage} />
<img <img
className="mx_BackdropPanel--canvas" className="mx_BackdropPanel--canvas"
style={{ style={{
opacity: .12,
}} }}
src={this.state.lpImage} /> src={this.state.lpImage} />
<canvas <canvas
@ -161,14 +159,11 @@ export default class BackdropPanel extends React.PureComponent<IProps, IState> {
className="mx_BackdropPanel--canvas" className="mx_BackdropPanel--canvas"
style={{ style={{
display: this.state.lpImage ? 'none' : 'block', display: this.state.lpImage ? 'none' : 'block',
opacity: .19,
}} }}
/> />
<canvas <canvas
style={{ style={{
display: this.state.lpImage ? 'none' : 'block', display: this.state.lpImage ? 'none' : 'block',
transform: `translateX(0)`,
opacity: .12,
}} }}
ref={this.leftPanelRef} ref={this.leftPanelRef}
className="mx_BackdropPanel--canvas" className="mx_BackdropPanel--canvas"