LCOV - code coverage report
Current view: top level - xenolith/renderer/material2d/base - MaterialStyleContainer.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 36 65 55.4 %
Date: 2024-05-12 00:16:13 Functions: 8 13 61.5 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2022 Roman Katuntsev <sbkarr@stappler.org>
       3             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       4             : 
       5             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       6             :  of this software and associated documentation files (the "Software"), to deal
       7             :  in the Software without restriction, including without limitation the rights
       8             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       9             :  copies of the Software, and to permit persons to whom the Software is
      10             :  furnished to do so, subject to the following conditions:
      11             : 
      12             :  The above copyright notice and this permission notice shall be included in
      13             :  all copies or substantial portions of the Software.
      14             : 
      15             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      18             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      19             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      20             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      21             :  THE SOFTWARE.
      22             :  **/
      23             : 
      24             : #include "MaterialStyleContainer.h"
      25             : #include "XLScene.h"
      26             : 
      27             : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d {
      28             : 
      29             : XL_DECLARE_EVENT_CLASS(StyleContainer, onColorSchemeUpdate)
      30             : 
      31             : uint64_t StyleContainer::ComponentFrameTag = Component::GetNextComponentId();
      32             : 
      33          20 : bool StyleContainer::init() {
      34          20 :         if (!Component::init()) {
      35           0 :                 return false;
      36             :         }
      37             : 
      38          20 :         setFrameTag(ComponentFrameTag);
      39             : 
      40          20 :         _schemes.emplace(PrimarySchemeTag, ColorScheme(ThemeType::LightTheme, ColorHCT(292, 100, 50, 1.0f), false));
      41             : 
      42          20 :         return true;
      43             : }
      44             : 
      45          20 : void StyleContainer::onEnter(Scene *scene) {
      46          20 :         Component::onEnter(scene);
      47          20 :         _scene = scene;
      48          20 : }
      49             : 
      50          20 : void StyleContainer::onExit() {
      51          20 :         _scene = nullptr;
      52          20 :         Component::onExit();
      53          20 : }
      54             : 
      55           0 : void StyleContainer::setPrimaryScheme(ColorScheme &&scheme) {
      56           0 :         setScheme(PrimarySchemeTag, move(scheme));
      57           0 : }
      58             : 
      59           0 : void StyleContainer::setPrimaryScheme(ThemeType type, const CorePalette &palette) {
      60           0 :         setScheme(PrimarySchemeTag, type, palette);
      61           0 : }
      62             : 
      63          10 : void StyleContainer::setPrimaryScheme(ThemeType type, const Color4F &color, bool isContent) {
      64          10 :         setScheme(PrimarySchemeTag, type, color, isContent);
      65          10 : }
      66             : 
      67        1500 : void StyleContainer::setPrimaryScheme(ThemeType type, const ColorHCT &color, bool isContent) {
      68        1500 :         setScheme(PrimarySchemeTag, type, color, isContent);
      69        1500 : }
      70             : 
      71           0 : const ColorScheme &StyleContainer::getPrimaryScheme() const {
      72           0 :         return *getScheme(PrimarySchemeTag);
      73             : }
      74             : 
      75           0 : const ColorScheme *StyleContainer::setScheme(uint32_t tag, ColorScheme &&scheme) {
      76           0 :         auto it = _schemes.find(tag);
      77           0 :         if (it != _schemes.end()) {
      78           0 :                 it->second = move(scheme);
      79             :         } else {
      80           0 :                 it = _schemes.emplace(tag, move(scheme)).first;
      81             :         }
      82           0 :         if (_running) {
      83           0 :                 onColorSchemeUpdate(this, int64_t(tag));
      84             :         }
      85           0 :         return &it->second;
      86             : }
      87             : 
      88           0 : const ColorScheme *StyleContainer::setScheme(uint32_t tag, ThemeType type, const CorePalette &palette) {
      89           0 :         auto it = _schemes.find(tag);
      90           0 :         if (it != _schemes.end()) {
      91           0 :                 it->second.set(type, palette);
      92             :         } else {
      93           0 :                 it = _schemes.emplace(tag, ColorScheme(type, palette)).first;
      94             :         }
      95           0 :         if (_running) {
      96           0 :                 onColorSchemeUpdate(this, int64_t(tag));
      97             :         }
      98           0 :         return &it->second;
      99             : }
     100             : 
     101          10 : const ColorScheme *StyleContainer::setScheme(uint32_t tag, ThemeType type, const Color4F &color, bool isContent) {
     102          10 :         auto it = _schemes.find(tag);
     103          10 :         if (it != _schemes.end()) {
     104          10 :                 it->second.set(type, color, isContent);
     105             :         } else {
     106           0 :                 it = _schemes.emplace(tag, ColorScheme(type, color, isContent)).first;
     107             :         }
     108          10 :         if (_running) {
     109           0 :                 onColorSchemeUpdate(this, int64_t(tag));
     110             :         }
     111          10 :         return &it->second;
     112             : }
     113             : 
     114        1500 : const ColorScheme *StyleContainer::setScheme(uint32_t tag, ThemeType type, const ColorHCT &color, bool isContent) {
     115        1500 :         auto it = _schemes.find(tag);
     116        1500 :         if (it != _schemes.end()) {
     117        1500 :                 it->second.set(type, color, isContent);
     118             :         } else {
     119           0 :                 it = _schemes.emplace(tag, ColorScheme(type, color, isContent)).first;
     120             :         }
     121        1500 :         if (_running) {
     122        1480 :                 onColorSchemeUpdate(this, int64_t(tag));
     123             :         }
     124        1500 :         return &it->second;
     125             : }
     126             : 
     127       48491 : const ColorScheme *StyleContainer::getScheme(uint32_t tag) const {
     128       48491 :         auto it = _schemes.find(tag);
     129       48491 :         if (it != _schemes.end()) {
     130       48491 :                 return &it->second;
     131             :         }
     132           0 :         return nullptr;
     133             : }
     134             : 
     135             : }

Generated by: LCOV version 1.14