[analog-clock] Allow themes to define hand shadow offset & hand rot center
ClosedPublic

Authored by kossebau on Mar 29 2019, 11:34 AM.

Details

Summary

Currently the shadow offset of the hands as well as the rotation center of
the hands is hard-coded to match the light model and the hands shape of the
Breeze theme. As well did some older change to move the rotation center to
width/2 in y direction break older themes which relied on the y=0 offset.

This patch adds the option for themes to control the shadow offset as well
as define the rotation offset for each hand (to avoid the need to create
large pixmaps as workaround with empty space to match the assumption of
the center to be at (width/2, width/2), by these new hints:

One shadow offset for all hands, as the simulated physical model can be
assumed to have all hands almost on same layer (also matching that we have
only one shadow for stacked objects, like windows, elsewhere):

  • hint-hands-shadow-offset-to-west/hint-hands-shadows-offset-to-east
  • hint-hands-shadow-offset-to-north/hint-hands-shadow-offset-to-south

(west vs. east & north vs. south as negative rect size is not possible).
If no hint is set, defaults to 0.
The default of 0 is a small breakage, but almost all themes from
store.kde.org do not use a shadow, also was the hour shadow broken/not shown
until recently and only fixed for upcoming Plasma 5.16, where the offset of
the shadows was tuned as well, so any themes with hand shadows will need
some tuning for Plasma 5.16 in any case.

Separate rotation offsets for all hands & their shadows, so pixmaps can be
as small as needed, with no transparent area padding needed:

  • hint-hourhand-rotation-center-offset
  • hint-hourhandshadow-rotation-center-offset
  • hint-minutehand-rotation-center-offset
  • hint-minutehandshadow-rotation-center-offset
  • hint-secondhand-rotation-center-offset
  • hint-secondhandshadow-rotation-center-offset

The offset is taken from the center of the hint element, relative
to the position of the hand element, so visually in the SVG file
the hint element directly marks the rotation center for the hand.
If no hint is set, defaults to (width/2, width/2).

Test Plan

Clocks of unmodified themes from store.kde.org still look as before.
Themes with hints added have shadows at proper place as well as rotation
center of hands at the expected offset.

Diff Detail

Repository
R120 Plasma Workspace
Branch
fixclockshadowhandcenter
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 10636
Build 10654: arc lint + arc unit
kossebau created this revision.Mar 29 2019, 11:34 AM
Restricted Application added a project: Plasma. · View Herald TranscriptMar 29 2019, 11:34 AM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
kossebau requested review of this revision.Mar 29 2019, 11:34 AM
kossebau added a comment.EditedMar 29 2019, 11:37 AM

To test, you can download the Unicorn theme from store.kde.org, then edit the .local/share/plasma/desktoptheme/unicorn/widgets/clock.svg and append this before the final </svg>:

  <rect
       style="opacity:0.875;fill:#008000;fill-opacity:1;stroke:none"
       id="hint-hands-shadow-offset-to-west"
       width="20"
       height="4"
       x="100"
       y="60" />
  <rect
       style="opacity:0.875;fill:#008000;fill-opacity:1;stroke:none"
       id="hint-hands-shadow-offset-to-south"
       width="4"
       height="10"
       x="110"
       y="60" />
<!-- Updated: initial code variant
  <rect
       style="opacity:0.875;fill:#008000;fill-opacity:1;stroke:none"
       id="hint-hourhand-rotation-center-offset"
       width="7.4285"
       height="2.5"
       x="93.071"
       y="70" />
  <rect
       style="opacity:0.875;fill:#008000;fill-opacity:1;stroke:none"
       id="hint-minutehand-rotation-center-offset"
       width="37.835"
       height="2.5"
       x="62.576"
       y="80" />
  <rect
       style="opacity:0.875;fill:#008000;fill-opacity:1;stroke:none"
       id="hint-secondhand-rotation-center-offset"
       width="11,772"
       height="0.5"
       x="88.616"
       y="90" />
-->
  <circle
       style="opacity:0.875;fill:#008000;fill-opacity:1;stroke:none"
       id="hint-hourhand-rotation-center-offset"
       r="2"
       cx="100"
       cy="100" />
  <circle
       style="opacity:0.875;fill:#008000;fill-opacity:1;stroke:none"
       id="hint-minutehand-rotation-center-offset"
       r="2"
       cx="100"
       cy="100" />
  <circle
       style="opacity:0.875;fill:#008000;fill-opacity:1;stroke:none"
       id="hint-secondhand-rotation-center-offset"
       r="2"
       cx="100"
       cy="100" />

Reloading the theme will then fix the clock to look like this (extreme shadow offset just done for demo purpose)

mart accepted this revision.Apr 1 2019, 10:44 AM
This revision is now accepted and ready to land.Apr 1 2019, 10:44 AM
ngraham accepted this revision.Apr 1 2019, 1:01 PM
kossebau updated this revision to Diff 55777.Apr 8 2019, 8:14 PM

Instead of using the size of a hint to define the rotation center of a hand
shape, use the relative position of the (center of) hint.
This allows to define rotation centers outside of the hand element, like
useful for all those themes which use hands shapes that do not cover the
clock center.
It also is visually for the designer more logically to place e.g. a circle
as rotation center hint exactly where the center of rotation is for a hand,
instead of the abstract offset shape hint.
And the relative positioning also solves the issue of having the rotation
center directly at the border, where before the offset hint was not possibly
due to a size of 0 in one dimension resulting in the hint not being visual
and thus not propagated by QSvgRenderer/Plasma::Svg.

Looking around on store.kde.org, I saw quite some clocks of (old) themes which have hands that are e.g. only indicators directly at the border. Or are ghost-like pointers floating disconnected from the center.
They usually compensate by having an empty region until the center (or beyond, to make up for the currently hardcoded (width/2, width/2) rotation center offset).
With some old themes, it appears even that in early Plasma times the vertical offset from the middle of the hand shape was used (cmp. e.g. clock of Spoons lite: https://store.kde.org/p/998821/)

To test the new variant to define the rotation offset, please get the current working version of Spoons dark:

cd some/test/dir
git clone git://anongit.kde.org/scratch/ivan/plasma-theme-spoons-dark.git
cd .local/share/plasma/desktoptheme
ln -s some/test/dir/plasma-theme-spoons-dark spoons-dark-work

Open widgets/clock.svg and add this before the final `</svg>:

<circle
     style="opacity:0.875;fill:#008000;fill-opacity:1;stroke:none"
     id="hint-hourhand-rotation-center-offset"
     r="2"
     cx="71.566"
     cy="62.5" />
<circle
     style="opacity:0.875;fill:#008000;fill-opacity:1;stroke:none"
     id="hint-minutehand-rotation-center-offset"
     r="2"
     cx="63.908"
     cy="62.5" />
<circle
     style="opacity:0.875;fill:#008000;fill-opacity:1;stroke:none"
     id="hint-secondhand-rotation-center-offset"
     r="2"
     cx="56.250"
     cy="62.5" />

The result would look like this in Inkscape:


And this patch then results in this at runtime:

kossebau edited the summary of this revision. (Show Details)Apr 9 2019, 10:51 AM
mart accepted this revision.Apr 12 2019, 9:07 AM
This revision was automatically updated to reflect the committed changes.