diff options
-rw-r--r-- | src/ui/util.c | 13 | ||||
-rw-r--r-- | src/ui/util.h | 12 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 9aa634bc..0af33138 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -62,6 +62,19 @@ int keyMods_Sym(int kmods) { | |||
62 | return kmods; | 62 | return kmods; |
63 | } | 63 | } |
64 | 64 | ||
65 | iRangei intersect_Rangei(iRangei a, iRangei b) { | ||
66 | if (a.end < b.start || a.start > b.end) { | ||
67 | return (iRangei){ 0, 0 }; | ||
68 | } | ||
69 | return (iRangei){ iMax(a.start, b.start), iMin(a.end, b.end) }; | ||
70 | } | ||
71 | |||
72 | iRangei union_Rangei(iRangei a, iRangei b) { | ||
73 | if (isEmpty_Rangei(a)) return b; | ||
74 | if (isEmpty_Rangei(b)) return a; | ||
75 | return (iRangei){ iMin(a.start, b.start), iMax(a.end, b.end) }; | ||
76 | } | ||
77 | |||
65 | /*-----------------------------------------------------------------------------------------------*/ | 78 | /*-----------------------------------------------------------------------------------------------*/ |
66 | 79 | ||
67 | void init_Click(iClick *d, iAnyObject *widget, int button) { | 80 | void init_Click(iClick *d, iAnyObject *widget, int button) { |
diff --git a/src/ui/util.h b/src/ui/util.h index ae3742b5..468f2057 100644 --- a/src/ui/util.h +++ b/src/ui/util.h | |||
@@ -48,7 +48,17 @@ iLocalDef iBool isResize_UserEvent(const SDL_Event *d) { | |||
48 | # define KMOD_SECONDARY KMOD_GUI | 48 | # define KMOD_SECONDARY KMOD_GUI |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | int keyMods_Sym (int kmods); /* shift, alt, control, or gui */ | 51 | int keyMods_Sym (int kmods); /* shift, alt, control, or gui */ |
52 | |||
53 | iRangei intersect_Rangei (iRangei a, iRangei b); | ||
54 | iRangei union_Rangei (iRangei a, iRangei b); | ||
55 | |||
56 | iLocalDef iBool equal_Rangei(iRangei a, iRangei b) { | ||
57 | return a.start == b.start && a.end == b.end; | ||
58 | } | ||
59 | iLocalDef iBool isEmpty_Rangei(iRangei d) { | ||
60 | return size_Range(&d) == 0; | ||
61 | } | ||
52 | 62 | ||
53 | /*-----------------------------------------------------------------------------------------------*/ | 63 | /*-----------------------------------------------------------------------------------------------*/ |
54 | 64 | ||