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
48 unsigned int threads;
49};
50
63 unsigned int val, unsigned int max,
64 unsigned int mul __attribute__((unused)))
65{
66 if (!callback)
67 return 0;
68
69 if (val % 100)
70 return 0;
71
72 callback->percentage = 100.00 * val / max;
73 return callback->callback(callback);
74}
75
76static inline void gp_progress_cb_done(gp_progress_cb *callback)
77{
78 if (!callback)
79 return;
80
81 callback->percentage = 100;
82 callback->callback(callback);
83}
84
85#define GP_PROGRESS_CALLBACK(name, pcallback, ppriv) \
86 gp_progress_cb name = { \
87 .callback = pcallback, \
88 .priv = ppriv, \
89 };
90
91#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.
void * priv
User private pointer.