libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
widget.h
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license in the file COPYING
10 * or http://www.opensource.org/licenses/CDDL-1.0.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file COPYING.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2021 Saso Kiselkov. All rights reserved.
24 */
25
26#ifndef _ACFUTILS_WIDGET_H_
27#define _ACFUTILS_WIDGET_H_
28
29#include <XPLMDisplay.h>
30#include <XPWidgets.h>
31
32#include "delay_line.h"
33#include "mt_cairo_render.h"
34#include "types.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40typedef struct tooltip_set tooltip_set_t;
41
42typedef struct {
43 XPLMWindowID win;
44 unsigned norm_w;
45 unsigned norm_h;
46 double w_h_ratio;
47 int left;
48 int top;
49 int right;
50 int bottom;
51 delay_line_t snap_hold_delay;
53
54typedef struct {
55 int left;
56 int top;
57 int right;
58 int bottom;
59} monitor_t;
60
61#define create_widget_rel ACFSYM(create_widget_rel)
62API_EXPORT XPWidgetID create_widget_rel(int x, int y, bool_t y_from_bottom,
63 int width, int height, int visible, const char *descr, int root,
64 XPWidgetID container, XPWidgetClass cls);
65
66#define create_widget_rel2 ACFSYM(create_widget_rel2)
67API_EXPORT XPWidgetID create_widget_rel2(int x, int y, bool_t y_from_bottom,
68 int width, int height, int visible, const char *descr, int root,
69 XPWidgetID container, XPWidgetID coord_ref, XPWidgetClass cls);
70
71#define widget_win_center ACFSYM(widget_win_center)
72API_EXPORT void widget_win_center(XPWidgetID window);
73#define classic_win_center ACFSYM(classic_win_center)
74API_EXPORT void classic_win_center(XPLMWindowID window);
75API_EXPORT monitor_t lacf_get_first_monitor_bounds(void);
76
77API_EXPORT void tooltip_init(void);
78API_EXPORT void tooltip_fini(void);
79
80API_EXPORT tooltip_set_t *tooltip_set_new(XPWidgetID window);
81API_EXPORT tooltip_set_t *tooltip_set_new_native(XPLMWindowID window);
82API_EXPORT void tooltip_set_orig_win_size(tooltip_set_t *tts,
83 unsigned orig_w, unsigned orig_h);
84API_EXPORT void tooltip_set_delay(tooltip_set_t *set, double secs);
85API_EXPORT void tooltip_set_destroy(tooltip_set_t *tts);
86API_EXPORT void tooltip_set_opaque(tooltip_set_t *tts, bool_t opaque);
87
88API_EXPORT void tooltip_new(tooltip_set_t *tts, int x, int y, int w, int h,
89 const char *text);
90
91API_EXPORT void tooltip_set_font_face(tooltip_set_t *tts,
92 cairo_font_face_t *font);
93API_EXPORT cairo_font_face_t *tooltip_get_font_face(const tooltip_set_t *tts);
94
95API_EXPORT void tooltip_set_font_size(tooltip_set_t *tts, double size);
96API_EXPORT double tooltip_get_font_size(const tooltip_set_t *tts);
97
98#define window_follow_VR ACFSYM(window_follow_VR)
99API_EXPORT bool_t window_follow_VR(XPLMWindowID win);
100
101#define widget_follow_VR ACFSYM(widget_follow_VR)
102API_EXPORT bool_t widget_follow_VR(XPWidgetID win);
103
104#define window_is_on_screen ACFSYM(window_is_on_screen)
105API_EXPORT bool_t window_is_on_screen(XPLMWindowID win);
106
107/*
108 * These define an automatic window resizing controller that keeps the
109 * aspect ratio of the window constant. This is useful for windows where
110 * the contents might get squashed in undesirable ways.
111 *
112 * Use win_resize_ctl_init to initialize the controller, passing the
113 * window handle and the window's "normal" width and height in boxels.
114 * The controller will store the aspect ratio of these two numbers, as
115 * well as the normal sizes (providing automatic snapping to normal size
116 * when the user resizes the window to nearly its normal size).
117 *
118 * The normal size values MUST be greater than 10 boxels. Please note
119 * that the controller automatically sets the window resizing limits to
120 * between 10% and 1000% of its normal size. If this isn't desired,
121 * change the window's resizing limits after calling win_resize_ctl_init.
122 * Do NOT, however, allow the window to resize down to zero size, or
123 * a divide-by-zero will occur.
124 */
125#define win_resize_ctl_init ACFSYM(win_resize_ctl_init)
126API_EXPORT void win_resize_ctl_init(win_resize_ctl_t *ctl, XPLMWindowID win,
127 unsigned norm_w, unsigned norm_h);
128/*
129 * Call win_resize_ctl_update in your window drawing function.
130 * The controller will check the window for proper aspect ratio
131 * and/or snapping to its normal size and performs window
132 * geometry changes as necessary.
133 */
134#define win_resize_ctl_update ACFSYM(win_resize_ctl_update)
135API_EXPORT void win_resize_ctl_update(win_resize_ctl_t *ctl);
136
137#ifdef __cplusplus
138}
139#endif
140
141#endif /* _ACFUTILS_WIDGET_H_ */