GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_progress_callback.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2024 Cyril Hrubis <metan@ucw.cz>
4 */
5
17#ifndef CORE_GP_PROGRESS_CALLBACK_H
18#define CORE_GP_PROGRESS_CALLBACK_H
19
20#include <core/gp_types.h>
21
31
33 int (*callback)(struct gp_progress_cb *self);
35 void *priv;
36
38 int flags;
39
51 unsigned int threads;
52};
53
66 unsigned int val, unsigned int max,
67 unsigned int mul __attribute__((unused)))
68{
69 if (!callback)
70 return 0;
71
72 if (val % 100)
73 return 0;
74
75 callback->percentage = 100.00 * val / max;
76 return callback->callback(callback);
77}
78
79static inline void gp_progress_cb_done(gp_progress_cb *callback)
80{
81 if (!callback)
82 return;
83
84 callback->percentage = 100;
85 callback->callback(callback);
86}
87
88#define GP_PROGRESS_CALLBACK(name, pcallback, ppriv) \
89 gp_progress_cb name = { \
90 .callback = pcallback, \
91 .priv = ppriv, \
92 };
93
94#endif /* CORE_GP_PROGRESS_CALBACK_H */
A common types.
static int gp_progress_cb_report(gp_progress_cb *callback, unsigned int val, unsigned int max, unsigned int mul __attribute__((unused)))
Reports progress.
Progress callback.
int(* callback)(struct gp_progress_cb *self)
A progress callback handler.
float percentage
Current progress.
unsigned int threads
A number of threads.
int flags
Flags to be used by the loaders. Do not touch!
void * priv
User private pointer.