Fixed up the progressbar changes.
This commit is contained in:
parent
e1a5d140db
commit
99545e8775
|
@ -23,6 +23,7 @@ This README is being written.<br>
|
||||||
* Added `uiWindowFullscreen()` and `uiWindowSetFullscreen()` to allow making fullscreen uiWindows, taking advantage of OS facilities for fullscreen and without changing the screen resolution (!).
|
* Added `uiWindowFullscreen()` and `uiWindowSetFullscreen()` to allow making fullscreen uiWindows, taking advantage of OS facilities for fullscreen and without changing the screen resolution (!).
|
||||||
* Added `uiWindowBorderless()` and `uiWindowSetBorderless()` for allowing borderless uiWindows.
|
* Added `uiWindowBorderless()` and `uiWindowSetBorderless()` for allowing borderless uiWindows.
|
||||||
* Added `uiMainSteps()`. You call this instead of `uiMain()` if you want to run the main loop yourself. You pass in a function that will be called; within that function, you call `uiMainStep()` repeatedly until it returns 0, doing whatever you need to do in the meantime. (This was needed because just having `uiMainStep()` by itself only worked on some systems.)
|
* Added `uiMainSteps()`. You call this instead of `uiMain()` if you want to run the main loop yourself. You pass in a function that will be called; within that function, you call `uiMainStep()` repeatedly until it returns 0, doing whatever you need to do in the meantime. (This was needed because just having `uiMainStep()` by itself only worked on some systems.)
|
||||||
|
* Added `uiProgressBarValue()` and allowed passing -1 to `uiProgressBarSetValue()` to make an indeterminate progress bar. Thanks to @emersion.
|
||||||
|
|
||||||
* **15 June 2016**
|
* **15 June 2016**
|
||||||
* Added `uiFormDelete()`; thanks to @emersion.
|
* Added `uiFormDelete()`; thanks to @emersion.
|
||||||
|
|
|
@ -29,11 +29,9 @@ uiDarwinControlAllDefaults(uiProgressBar, pi)
|
||||||
|
|
||||||
int uiProgressBarValue(uiProgressBar *p)
|
int uiProgressBarValue(uiProgressBar *p)
|
||||||
{
|
{
|
||||||
if ([p->pi getIndeterminate]) {
|
if ([p->pi isIndeterminate])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
return [p->pi doubleValue];
|
||||||
|
|
||||||
return (int) [p->pi getDoubleValue];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiProgressBarSetValue(uiProgressBar *p, int value)
|
void uiProgressBarSetValue(uiProgressBar *p, int value)
|
||||||
|
@ -44,7 +42,7 @@ void uiProgressBarSetValue(uiProgressBar *p, int value)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([p->pi getIndeterminate]) {
|
if ([p->pi isIndeterminate]) {
|
||||||
[p->pi setIndeterminate:NO];
|
[p->pi setIndeterminate:NO];
|
||||||
[p->pi stopAnimation:p->pi];
|
[p->pi stopAnimation:p->pi];
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,14 +78,13 @@ static void showHide(uiButton *b, void *data)
|
||||||
static void setIndeterminate(uiButton *b, void *data)
|
static void setIndeterminate(uiButton *b, void *data)
|
||||||
{
|
{
|
||||||
uiProgressBar *p = uiProgressBar(data);
|
uiProgressBar *p = uiProgressBar(data);
|
||||||
|
int value;
|
||||||
|
|
||||||
int value = uiProgressBarValue(p);
|
value = uiProgressBarValue(p);
|
||||||
if (value == -1) {
|
if (value == -1)
|
||||||
value = 0;
|
value = 50;
|
||||||
} else {
|
else
|
||||||
value = -1;
|
value = -1;
|
||||||
}
|
|
||||||
|
|
||||||
uiProgressBarSetValue(p, value);
|
uiProgressBarSetValue(p, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +138,9 @@ uiBox *makePage13(void)
|
||||||
uiFormAppend(f, "MLE", uiControl(uiNewMultilineEntry()), 1);
|
uiFormAppend(f, "MLE", uiControl(uiNewMultilineEntry()), 1);
|
||||||
|
|
||||||
p = uiNewProgressBar();
|
p = uiNewProgressBar();
|
||||||
|
uiProgressBarSetValue(p, 50);
|
||||||
uiBoxAppend(page13, uiControl(p), 0);
|
uiBoxAppend(page13, uiControl(p), 0);
|
||||||
b = uiNewButton("Toggle indeterminate");
|
b = uiNewButton("Toggle Indeterminate");
|
||||||
uiButtonOnClicked(b, setIndeterminate, p);
|
uiButtonOnClicked(b, setIndeterminate, p);
|
||||||
uiBoxAppend(page13, uiControl(b), 0);
|
uiBoxAppend(page13, uiControl(b), 0);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ struct uiProgressBar {
|
||||||
uiUnixControl c;
|
uiUnixControl c;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkProgressBar *pbar;
|
GtkProgressBar *pbar;
|
||||||
int indeterminate;
|
gboolean indeterminate;
|
||||||
|
guint pulser;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiUnixControlAllDefaults(uiProgressBar)
|
uiUnixControlAllDefaults(uiProgressBar)
|
||||||
|
@ -14,35 +15,35 @@ int uiProgressBarValue(uiProgressBar *p)
|
||||||
{
|
{
|
||||||
if (p->indeterminate)
|
if (p->indeterminate)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return (int) (gtk_progress_bar_get_fraction(p->pbar) * 100);
|
return (int) (gtk_progress_bar_get_fraction(p->pbar) * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean uiProgressBarPulse(void* data)
|
static gboolean pulse(void* data)
|
||||||
{
|
{
|
||||||
uiProgressBar *p = (uiProgressBar*) data;
|
uiProgressBar *p = uiProgressBar(data);
|
||||||
|
|
||||||
if (!GTK_IS_WIDGET(p->pbar) || !p->indeterminate)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
gtk_progress_bar_pulse(p->pbar);
|
gtk_progress_bar_pulse(p->pbar);
|
||||||
return 1;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiProgressBarSetValue(uiProgressBar *p, int value)
|
void uiProgressBarSetValue(uiProgressBar *p, int value)
|
||||||
{
|
{
|
||||||
if (value == -1) {
|
if (value == -1) {
|
||||||
if (!p->indeterminate) {
|
if (!p->indeterminate) {
|
||||||
p->indeterminate = 1;
|
p->indeterminate = TRUE;
|
||||||
g_timeout_add(100, uiProgressBarPulse, p);
|
// TODO verify the timeout
|
||||||
|
p->pulser = g_timeout_add(100, pulse, p);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (p->indeterminate) {
|
||||||
|
p->indeterminate = FALSE;
|
||||||
|
g_source_remove(p->pulser);
|
||||||
|
}
|
||||||
|
|
||||||
if (value < 0 || value > 100)
|
if (value < 0 || value > 100)
|
||||||
userbug("Value %d is out of range for a uiProgressBar.", value);
|
userbug("Value %d is out of range for a uiProgressBar.", value);
|
||||||
|
|
||||||
p->indeterminate = 0;
|
|
||||||
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
|
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,14 +26,13 @@ static void uiProgressBarMinimumSize(uiWindowsControl *c, int *width, int *heigh
|
||||||
*height = y;
|
*height = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define indeterminate(p) ((getStyle(p->hwnd) & PBS_MARQUEE) != 0)
|
||||||
|
|
||||||
int uiProgressBarValue(uiProgressBar *p)
|
int uiProgressBarValue(uiProgressBar *p)
|
||||||
{
|
{
|
||||||
LONG_PTR style = GetWindowLongPtr(p->hwnd, GWL_STYLE);
|
if (indeterminate(p))
|
||||||
if ((style & PBS_MARQUEE) != 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
return SendMessage(p->hwnd, PBM_GETPOS, 0, 0);
|
||||||
|
|
||||||
return (int) SendMessage(p->hwnd, PBM_GETPOS, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// unfortunately, as of Vista progress bars have a forced animation on increase
|
// unfortunately, as of Vista progress bars have a forced animation on increase
|
||||||
|
@ -42,19 +41,16 @@ int uiProgressBarValue(uiProgressBar *p)
|
||||||
// it's not ideal/perfect, but it will have to do
|
// it's not ideal/perfect, but it will have to do
|
||||||
void uiProgressBarSetValue(uiProgressBar *p, int value)
|
void uiProgressBarSetValue(uiProgressBar *p, int value)
|
||||||
{
|
{
|
||||||
LONG_PTR style = GetWindowLongPtr(p->hwnd, GWL_STYLE);
|
|
||||||
|
|
||||||
if (value == -1) {
|
if (value == -1) {
|
||||||
if ((style & PBS_MARQUEE) == 0) {
|
if (!indeterminate(p)) {
|
||||||
SetWindowLongPtr(p->hwnd, GWL_STYLE, style | PBS_MARQUEE);
|
setStyle(p->hwnd, getStyle(p->hwnd) | PBS_MARQUEE);
|
||||||
SendMessage(p->hwnd, PBM_SETMARQUEE, 1, 0);
|
SendMessageW(p->hwnd, PBM_SETMARQUEE, (WPARAM) TRUE, 0);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (indeterminate(p)) {
|
||||||
if ((style & PBS_MARQUEE) != 0) {
|
SendMessageW(p->hwnd, PBM_SETMARQUEE, (WPARAM) FALSE, 0);
|
||||||
SetWindowLongPtr(p->hwnd, GWL_STYLE, style ^ PBS_MARQUEE);
|
setStyle(p->hwnd, getStyle(p->hwnd) & ~PBS_MARQUEE);
|
||||||
SendMessage(p->hwnd, PBM_SETMARQUEE, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value < 0 || value > 100)
|
if (value < 0 || value > 100)
|
||||||
|
|
Loading…
Reference in New Issue