2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 static char ERROR_FLAG[6][20] = {"NONE", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG"};
28 void rectangle::fit(unsigned long to_width, unsigned long to_height)
30 // fit rect within (to_width x to_height)
32 if (to_width <= width()) {
34 set_bottom(top() + (static_cast<long>(to_width) * height() / width()) - 1);
35 set_right(left() + to_width - 1);
37 // scale to fit height
38 set_right(left() + (static_cast<long>(to_height) * width () / height()) - 1);
39 set_bottom(top() + to_height - 1);
43 void rectangle::center(unsigned long outer_w, unsigned long outer_h)
45 long inner_w = width();
46 long inner_h = height();
48 set_left((outer_w - inner_w) / 2);
49 set_right(left() + inner_w - 1);
50 set_top((outer_h - inner_h) / 2);
51 set_bottom(top() + inner_h - 1);
54 void rectangle::set_aspect(double ratio)
56 // aspect ratio is width:height (= width/height)
57 // e.g. Landscape of HD's ratio is 16:9 (= 1.777...)
58 // Portrait of HD's ratio is 9:16 (= 0.5625)
60 // width / height = ratio
61 // width * height = area
63 // width = sqrt(ratio * area)
64 // height = width / ratio
66 long orig_w = width();
67 long orig_h = height();
72 set_right(left() + orig_w - 1);
73 set_bottom(top() + static_cast<long>(orig_w / ratio + 0.5) - 1);
75 set_bottom(top() + orig_h - 1);
76 set_right(left() + static_cast<long>(orig_h * ratio + 0.5) - 1);
80 void _HMI_LOG(enum LOG_LEVEL level, const char* file, const char* func, const int line, const char* prefix, const char* log, ...)
82 const int log_level = (getenv("USE_HMI_DEBUG") == NULL)?LOG_LEVEL_ERROR:atoi(getenv("USE_HMI_DEBUG"));
92 clock_gettime(CLOCK_REALTIME, &tp);
93 time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
97 if (log == NULL || vasprintf(&message, log, args) < 0)
99 fprintf(stderr, "[%10.3f] [%s %s] [%s, %s(), Line:%d] >>> %s \n", time / 1000.0, prefix, ERROR_FLAG[level], file, func, line, message);
104 void _HMI_SEQ_LOG(enum LOG_LEVEL level, const char* file, const char* func, const int line, unsigned seq_num, const char* log, ...){
105 const int log_level = (getenv("USE_HMI_DEBUG") == NULL) ? LOG_LEVEL_ERROR:atoi(getenv("USE_HMI_DEBUG"));
106 if(log_level < level)
115 clock_gettime(CLOCK_REALTIME, &tp);
116 time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
120 if (log == NULL || vasprintf(&message, log, args) < 0)
122 fprintf(stderr, "[%10.3f] [wm %s] [%s, %s(), Line:%d] >>> req %d: %s \n", time / 1000.0, ERROR_FLAG[level], file, func, line, seq_num, message);
127 void _DUMP(enum LOG_LEVEL level, const char *log, ...)
129 const int log_level = (getenv("USE_HMI_DEBUG") == NULL) ? LOG_LEVEL_ERROR : atoi(getenv("USE_HMI_DEBUG"));
130 if (log_level < level)
137 if (log == NULL || vasprintf(&message, log, args) < 0)
139 fprintf(stderr, "%s \n", message);