LCOV - code coverage report
Current view: top level - xenolith/resources/icons - XLIconImage.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 107 137 78.1 %
Date: 2024-05-12 00:16:13 Functions: 17 22 77.3 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #include "XLIcons.h"
      24             : 
      25             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      26             : 
      27         200 : static void drawIcon_Dynamic_Loader(vg::VectorImage &image, float pr) {
      28         200 :         float p = pr;
      29             : 
      30         200 :         float arcLen = 20.0_to_rad;
      31         200 :         float arcStart = -100.0_to_rad;
      32         200 :         if (p < 0.5) {
      33         200 :                 arcStart = arcStart + progress(0_to_rad, 75_to_rad, p * 2.0f);
      34         200 :                 arcLen = progress(20_to_rad, 230_to_rad, p * 2.0f);
      35             :         } else {
      36           0 :                 arcStart = arcStart + progress(75_to_rad, 360_to_rad, (p - 0.5f) * 2.0f);
      37           0 :                 arcLen = progress(230_to_rad, 20_to_rad, (p - 0.5f) * 2.0f);
      38             :         }
      39             : 
      40         400 :         image.addPath("")->openForWriting([&] (vg::PathWriter &writer) {
      41         200 :                 writer.addArc(Rect(4, 4, 16, 16), arcStart, arcLen);
      42         400 :         }).setStyle(vg::DrawStyle::Stroke).setStrokeWidth(2.0f);
      43         200 : }
      44             : 
      45         175 : static void drawIcon_Dynamic_Nav(vg::VectorImage &image, float pr) {
      46         175 :         auto t = Mat4::IDENTITY;
      47         175 :         t.translate(12, 12, 0);
      48             : 
      49         175 :         float p = pr;
      50             : 
      51         175 :         if (p <= 1.0f) {
      52         175 :                 t.rotateZ(pr * numbers::pi);
      53         175 :                 t.translate(-12, -12, 0);
      54             : 
      55         350 :                 image.addPath("")->openForWriting([&] (vg::PathWriter &writer) {
      56         175 :                         writer.moveTo( progress(2.0f, 13.0f, p),                                                progress(5.0f, 3.0f, p) )
      57         175 :                                         .lineTo( progress(2.0f, 13.0f - float(M_SQRT2), p),             progress(7.0f, 3.0f + float(M_SQRT2), p) )
      58         175 :                                         .lineTo( progress(22.0f, 22.0f - float(M_SQRT2), p),    progress(7.0f, 12.0f + float(M_SQRT2), p) )
      59         175 :                                         .lineTo( progress(22.0f, 22.0f, p),                                             progress(5.0f, 12.0f, p) )
      60         175 :                                         .closePath();
      61         350 :                 }).setTransform(t);
      62             : 
      63         350 :                 image.addPath("")->openForWriting([&] (vg::PathWriter &writer) {
      64         175 :                         writer.moveTo( progress(2.0f, 3.0f, p), 11 )
      65         175 :                                 .lineTo( progress(22.0f, 20.0f, p), 11 )
      66         175 :                                 .lineTo( progress(22.0f, 20.0f, p), 13 )
      67         175 :                                 .lineTo( progress(2.0f, 3.0f, p),       13 )
      68         175 :                                 .closePath();
      69         350 :                 }).setTransform(t);
      70             : 
      71         350 :                 image.addPath("")->openForWriting([&] (vg::PathWriter &writer) {
      72         175 :                         writer.moveTo( progress(2.0f, 13.0f - float(M_SQRT2), p),               progress(17.0f, 21.0f - float(M_SQRT2), p) )
      73         175 :                                         .lineTo( progress(22.0f, 22.0f - float(M_SQRT2), p),    progress(17.0f, 12.0f - float(M_SQRT2), p) )
      74         175 :                                         .lineTo( progress(22.0f, 22.0f, p),                                             progress(19.0f, 12.0f, p) )
      75         175 :                                         .lineTo( progress(2.0f, 13.0f, p),                                              progress(19.0f, 21.0f, p) )
      76         175 :                                 .closePath();
      77         350 :                 }).setTransform(t);
      78             :         } else {
      79           0 :                 p = p - 1.0f;
      80             : 
      81           0 :                 t.rotateZ((1.0f + 0.25f * p) * numbers::pi);
      82           0 :                 t.translate(-12, -12, 0);
      83             : 
      84           0 :                 image.addPath("")->openForWriting([&] (vg::PathWriter &writer) {
      85           0 :                         writer.moveTo( 13.0f, progress(3.0f, 4.0f, p) )
      86           0 :                                 .lineTo( progress(13.0f - float(M_SQRT2), 11.0f, p), progress(3.0f + float(M_SQRT2), 4.0f, p) )
      87           0 :                                 .lineTo( progress(22.0f - float(M_SQRT2), 11.0f, p), progress(12.0f + float(M_SQRT2), 12.0f, p) )
      88           0 :                                 .lineTo( progress(22.0f, 13.0f, p), 12.0f )
      89           0 :                                 .closePath();
      90           0 :                 }).setTransform(t);
      91             : 
      92           0 :                 image.addPath("")->openForWriting([&] (vg::PathWriter &writer) {
      93           0 :                         writer.moveTo( progress(3.0f, 4.0f, p), 11 )
      94           0 :                                 .lineTo( progress(20.0f, 20.0f, p), 11 )
      95           0 :                                 .lineTo( progress(20.0f, 20.0f, p), 13 )
      96           0 :                                 .lineTo( progress(3.0f, 4.0f, p), 13 )
      97           0 :                                 .closePath();
      98           0 :                 }).setTransform(t);
      99             : 
     100           0 :                 image.addPath("")->openForWriting([&] (vg::PathWriter &writer) {
     101           0 :                         writer.moveTo( progress(13.0f - float(M_SQRT2), 11.0f, p), progress(21.0f - float(M_SQRT2), 20.0f, p) )
     102           0 :                                 .lineTo( progress(22.0f - float(M_SQRT2), 11.0f, p), progress(12.0f - float(M_SQRT2), 12.0f, p) )
     103           0 :                                 .lineTo( progress(22.0f, 13.0f, p), 12.0f )
     104           0 :                                 .lineTo( 13.0f, progress(21.0f, 20.0f, p) )
     105           0 :                                 .closePath();
     106           0 :                 }).setTransform(t);
     107             :         }
     108         175 : }
     109             : 
     110         175 : static void drawIcon_Dynamic_DownloadProgress(vg::VectorImage &image, float pr) {
     111         175 :         auto t = Mat4::IDENTITY;
     112         175 :         t.scale(-1, 1, 1);
     113         175 :         t.translate(-24, 0, 0);
     114         175 :         if (pr >= 1.0f) {
     115           0 :                 image.addPath("")->openForWriting([&] (vg::PathWriter &writer) { writer.addOval(Rect(3, 3, 18, 18)); })
     116           0 :                                 .setStyle(vg::DrawStyle::Stroke).setStrokeWidth(2.0f);
     117         175 :         } else if (pr <= 0.0f) {
     118         525 :                 image.addPath("")->openForWriting([&] (vg::PathWriter &writer) { writer.addArc(Rect(3, 3, 18, 18), 90.0_to_rad, 1_to_rad); })
     119         175 :                                 .setStyle(vg::DrawStyle::Stroke).setStrokeWidth(2.0f);
     120             :         } else {
     121           0 :                 image.addPath("")->openForWriting([&] (vg::PathWriter &writer) { writer.addArc(Rect(3, 3, 18, 18), 90.0_to_rad, 360_to_rad * pr); })
     122           0 :                                 .setStyle(vg::DrawStyle::Stroke).setStrokeWidth(2.0f).setTransform(t);
     123             :         }
     124             : 
     125         350 :         image.addPath("")->openForWriting([] (vg::PathWriter &writer) { writer.addRect(Rect(9, 9, 6, 6)); });
     126         175 : }
     127             : 
     128          25 : static void drawIcon_Stappler_CursorIcon(vg::VectorImage &image, float pr) {
     129          25 :         image.addPath()->openForWriting([] (vg::PathWriter &writer) {
     130          25 :                 writer.moveTo(12.0f, 24.0f)
     131          25 :                         .lineTo(5.0f, 17.0f)
     132          25 :                         .arcTo(7.0f * sqrt(2.0f), 7.0f * sqrt(2.0f), 0.0f, true, true, 19.0f, 17.0f)
     133          25 :                         .closePath();
     134          25 :         });
     135          25 : }
     136             : 
     137          25 : static void drawIcon_Stappler_SelectioinStartIcon(vg::VectorImage &image, float pr) {
     138          25 :         image.addPath()->openForWriting([] (vg::PathWriter &writer) {
     139          25 :                 writer.moveTo(24, 24)
     140          25 :                         .lineTo(12, 24)
     141          25 :                         .arcTo(12, 12, 0, true, true, 24, 12)
     142          25 :                         .closePath();
     143          25 :         });
     144          25 : }
     145             : 
     146          25 : static void drawIcon_Stappler_SelectioinEndIcon(vg::VectorImage &image, float pr) {
     147          25 :         image.addPath()->openForWriting([] (vg::PathWriter &writer) {
     148          25 :                 writer.moveTo(0, 24)
     149          25 :                         .lineTo(0, 12)
     150          25 :                         .arcTo(12, 12, 0, true, true, 12, 24)
     151          25 :                         .closePath();
     152          25 :         });
     153          25 : }
     154             : 
     155      496835 : void drawIcon(vg::VectorImage &image, IconName name, float pr) {
     156      496835 :         switch (name) {
     157          25 :         case IconName::None:
     158             :         case IconName::Empty:
     159          25 :                 break;
     160          25 :         case IconName::Stappler_CursorIcon:
     161          25 :                 drawIcon_Stappler_CursorIcon(image, pr);
     162          25 :                 break;
     163          25 :         case IconName::Stappler_SelectioinStartIcon:
     164          25 :                 drawIcon_Stappler_SelectioinStartIcon(image, pr);
     165          25 :                 break;
     166          25 :         case IconName::Stappler_SelectioinEndIcon:
     167          25 :                 drawIcon_Stappler_SelectioinEndIcon(image, pr);
     168          25 :                 break;
     169         200 :         case IconName::Dynamic_Loader:
     170         200 :                 drawIcon_Dynamic_Loader(image, pr);
     171         200 :                 break;
     172         175 :         case IconName::Dynamic_Nav:
     173         175 :                 drawIcon_Dynamic_Nav(image, pr);
     174         175 :                 break;
     175         175 :         case IconName::Dynamic_DownloadProgress:
     176         175 :                 drawIcon_Dynamic_DownloadProgress(image, pr);
     177         175 :                 break;
     178      496185 :         default:
     179      496185 :                 getIconData(name, [&] (BytesView bytes) {
     180      496185 :                         auto t = Mat4::IDENTITY;
     181      496185 :                         t.scale(1, -1, 1);
     182      496185 :                         t.translate(0, -24, 0);
     183             :                         // adding icon to tesselator cache with name org.stappler.xenolith.icon.*
     184      992370 :                         auto path = image.addPath("", toString("org.stappler.xenolith.icon.", xenolith::getIconName(name)))
     185      496185 :                                         ->getPath();
     186      496185 :                         path->init(bytes);
     187      496185 :                         path->setTransform(t);
     188      496185 :                 });
     189             :         }
     190      496835 : }
     191             : 
     192             : }

Generated by: LCOV version 1.14