• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2019, The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include <stddef.h>
21 
22 #include <teeui/label.h>
23 
24 namespace teeui {
25 namespace example {
26 
27 /*
28  * AOSP color scheme constants.
29  */
30 constexpr static const Color kShieldColor = Color(0xff778500);
31 constexpr static const Color kShieldColorInv = Color(0xffc4cb80);
32 constexpr static const Color kTextColor = Color(0xff212121);
33 constexpr static const Color kTextColorInv = Color(0xffdedede);
34 constexpr static const Color kBackGroundColor = Color(0xffffffff);
35 constexpr static const Color kBackGroundColorInv = Color(0xff212121);
36 
37 uint32_t alfaCombineChannel(uint32_t shift, double alfa, uint32_t a, uint32_t b);
38 
renderPixel(uint32_t x,uint32_t y,const T & e)39 template <typename T> uint32_t renderPixel(uint32_t x, uint32_t y, const T& e) {
40     return e.bounds_.drawPoint(Point<pxs>(x, y));
41 }
42 
43 struct FrameBuffer {
44     uint32_t left_;
45     uint32_t top_;
46     uint32_t width_;
47     uint32_t height_;
48     uint32_t* buffer_;
49     size_t size_in_elements_;
50     uint32_t lineStride_;
51 
52     Error drawPixel(uint32_t x, uint32_t y, uint32_t color) const;
53 };
54 
55 template <typename... Elements>
drawElements(std::tuple<Elements...> & layout,const PixelDrawer & drawPixel)56 Error drawElements(std::tuple<Elements...>& layout, const PixelDrawer& drawPixel) {
57     // Error::operator|| is overloaded, so we don't get short circuit evaluation.
58     // But we get the first error that occurs. We will still try and draw the remaining
59     // elements in the order they appear in the layout tuple.
60     return (std::get<Elements>(layout).draw(drawPixel) || ...);
61 }
62 
63 template <typename... Elements>
handleAllEvent(std::tuple<Elements...> & layout,const Event & event)64 Error handleAllEvent(std::tuple<Elements...>& layout, const Event& event) {
65     return (std::get<Elements>(layout).hit(event) || ...);
66 }
67 
68 void translate(LabelImpl* label);
69 
translateLabel(Layout * layout)70 template <typename T, typename Layout> void translateLabel(Layout* layout) {
71     translate(&std::get<T>(*layout));
72 }
73 }  // namespace example
74 }  // namespace teeui