-
Notifications
You must be signed in to change notification settings - Fork 2
/
progress.c
110 lines (93 loc) · 2.54 KB
/
progress.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "stdafx.h"
#include "LoftyCAD.h"
#include <CommCtrl.h>
#include <CommDlg.h>
#include <stdio.h>
// Status bar and progress bar routines.
// One megabyte.
#define MB (1024 * 1024)
// File progress statics.
int file_size;
int file_prog;
int file_read;
// Show status in the status bar. Set to blank strings to clear it.
void show_status(char* heading, char* string)
{
char buf[256];
strcpy_s(buf, 256, heading);
strcat_s(buf, 256, string);
SendMessage(hwndStatus, SB_SETTEXT, 0, (LPARAM)buf);
}
// Set the progress bar range (0-n) and its step to 1.
void set_progress_range(int n)
{
SendMessage(hwndProg, PBM_SETRANGE, 0, MAKELPARAM(0, n));
SendMessage(hwndProg, PBM_SETSTEP, 1, 0);
}
// Set the progress bar value
void set_progress(int n)
{
SendMessage(hwndProg, PBM_SETPOS, n, 0);
}
// Increment the progress bar value
void bump_progress(void)
{
SendMessage(hwndProg, PBM_STEPIT, 0, 0);
}
// Blank everything in the status bar
void clear_status_and_progress(void)
{
SendMessage(hwndStatus, SB_SETTEXT, 0, (LPARAM)"");
SendMessage(hwndProg, PBM_SETPOS, 0, 0);
}
// Accumulate the volume count for the given group for rendering, including those
// below it (but leave out counts for groups with an operation not NONE and having
// valid meshes).
int accum_render_count(Group* tree)
{
int count = 0;
Object* obj;
Volume* vol;
Group* group;
for (obj = tree->obj_list.head; obj != NULL; obj = obj->next)
{
switch (obj->type)
{
case OBJ_VOLUME:
vol = (Volume*)obj;
if (materials[vol->material].hidden)
break;
count++;
break;
case OBJ_GROUP:
group = (Group*)obj;
if (group->op != OP_NONE && group->mesh_valid)
break;
count += accum_render_count(group);
break;
}
}
return count;
}
// How big is this file? Set up the progress bar for reading, in case it's a big one.
void start_file_progress(FILE *f, char *header, char *filename)
{
fseek(f, 0, SEEK_END);
file_size = ftell(f);
file_prog = 0;
file_read = 0;
fseek(f, 0, SEEK_SET);
show_status(header, filename); // TODO: Strip directory (just show the filename) so it fits in bar
// Count in MB.
set_progress_range(file_size / MB);
}
// Step the progress when file size grows by 1MB.
void step_file_progress(int read)
{
file_read += read;
if (file_read / MB > file_prog)
{
file_prog = file_read / MB;
set_progress(file_prog);
}
}