2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3 * Copyright (c) 2018 Konsulko Group
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
29 #include "hmi-debug.h"
32 thread_local int ScopeTrace::indent = 0;
33 ScopeTrace::ScopeTrace(char const *func) : f(func)
35 fprintf(stderr, "%lu %*s%s -->\n", pthread_self(), 2 * indent++, "", this->f);
37 ScopeTrace::~ScopeTrace() { fprintf(stderr, "%lu %*s%s <--\n", pthread_self(), 2 * --indent, "", this->f); }
40 unique_fd::~unique_fd()
48 void rectangle::fit(unsigned long to_width, unsigned long to_height)
50 // fit rect within (to_width x to_height)
52 if (to_width <= width()) {
54 set_bottom(top() + (static_cast<long>(to_width) * height() / width()) - 1);
55 set_right(left() + to_width - 1);
57 // scale to fit height
58 set_right(left() + (static_cast<long>(to_height) * width () / height()) - 1);
59 set_bottom(top() + to_height - 1);
63 void rectangle::center(unsigned long outer_w, unsigned long outer_h)
65 long inner_w = width();
66 long inner_h = height();
68 set_left((outer_w - inner_w) / 2);
69 set_right(left() + inner_w - 1);
70 set_top((outer_h - inner_h) / 2);
71 set_bottom(top() + inner_h - 1);
74 void rectangle::set_aspect(double ratio)
76 // aspect ratio is width:height (= width/height)
77 // e.g. Landscape of HD's ratio is 16:9 (= 1.777...)
78 // Portrait of HD's ratio is 9:16 (= 0.5625)
80 // width / height = ratio
81 // width * height = area
83 // width = sqrt(ratio * area)
84 // height = width / ratio
86 long orig_w = width();
87 long orig_h = height();
92 set_right(left() + orig_w - 1);
93 set_bottom(top() + static_cast<long>(orig_w / ratio + 0.5) - 1);
95 set_bottom(top() + orig_h - 1);
96 set_right(left() + static_cast<long>(orig_h * ratio + 0.5) - 1);
100 std::string get_file_path(const char *file_name, const char *log_category)
102 char const *default_base_path = getenv("AFM_APP_INSTALL_DIR");
103 std::string path("");
109 if (!default_base_path)
111 HMI_ERROR(log_category, "AFM_APP_INSTALL_DIR is not defined");
115 path = default_base_path;
116 path.append("/etc/");
117 path.append(file_name);
120 // Check for over-ride in /etc/xdg/windowmanager
121 std::string override_path("/etc/xdg/windowmanager/");
122 override_path.append(file_name);
123 std::ifstream i(override_path);
126 path = override_path;
130 HMI_INFO(log_category, "Using %s", path.c_str());