Added uiAreaHandler.RedrawOnResize() to handle redrawing on resizes.

This commit is contained in:
Pietro Gagliardi 2015-09-10 21:17:00 -04:00
parent aa446a3e51
commit 95e0ca8f49
11 changed files with 42 additions and 1 deletions

View File

@ -113,6 +113,8 @@ static void areaWidget_size_allocate(GtkWidget *w, GtkAllocation *allocation)
ap->clientWidth = allocation->width; ap->clientWidth = allocation->width;
ap->clientHeight = allocation->height; ap->clientHeight = allocation->height;
updateScroll(areaWidget(w)); updateScroll(areaWidget(w));
if ((*(ap->ah->RedrawOnResize))(ap->ah, ap->a))
gtk_widget_queue_resize(w);
} }
static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr) static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr)

View File

@ -99,6 +99,11 @@ static uintmax_t handlerVScrollMax(uiAreaHandler *a, uiArea *area)
return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nvspinb)); return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nvspinb));
} }
static int handlerRedrawOnResize(uiAreaHandler *a, uiArea *area)
{
return 1;
}
static void recalcScroll(GtkSpinButton *sb, gpointer data) static void recalcScroll(GtkSpinButton *sb, gpointer data)
{ {
areaUpdateScroll(area); areaUpdateScroll(area);
@ -124,6 +129,7 @@ int main(void)
h.ah.Draw = handlerDraw; h.ah.Draw = handlerDraw;
h.ah.HScrollMax = handlerHScrollMax; h.ah.HScrollMax = handlerHScrollMax;
h.ah.VScrollMax = handlerVScrollMax; h.ah.VScrollMax = handlerVScrollMax;
h.ah.RedrawOnResize = handlerRedrawOnResize;
gtk_init(NULL, NULL); gtk_init(NULL, NULL);

View File

@ -10,6 +10,7 @@ struct uiAreaHandler {
void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *); void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *);
uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *); uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *);
uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *); uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *);
int (*RedrawOnResize)(uiAreaHandler *, uiArea *);
}; };
struct uiAreaDrawParams { struct uiAreaDrawParams {

View File

@ -287,6 +287,9 @@ struct uiArea {
// and update the scrolling position // and update the scrolling position
[self hscrollTo:self->hscrollpos]; [self hscrollTo:self->hscrollpos];
[self vscrollTo:self->vscrollpos]; [self vscrollTo:self->vscrollpos];
if ((*(self->libui_a->ah->RedrawOnResize))(self->libui_a->ah, self->libui_a))
[self->drawingView setNeedsDisplay:YES];
} }
- (IBAction)hscrollEvent:(id)sender - (IBAction)hscrollEvent:(id)sender

View File

@ -105,6 +105,11 @@ static uintmax_t handlerVScrollMax(uiAreaHandler *a, uiArea *area)
return _wtoi(c); return _wtoi(c);
*/} */}
static int handlerRedrawOnResize(uiAreaHandler *a, uiArea *area)
{
return 1;
}
// areaUpdateScroll(area); // areaUpdateScroll(area);
@interface appDelegate : NSObject<NSApplicationDelegate, NSTextFieldDelegate> @interface appDelegate : NSObject<NSApplicationDelegate, NSTextFieldDelegate>
@ -162,6 +167,7 @@ int main(void)
h.ah.Draw = handlerDraw; h.ah.Draw = handlerDraw;
h.ah.HScrollMax = handlerHScrollMax; h.ah.HScrollMax = handlerHScrollMax;
h.ah.VScrollMax = handlerVScrollMax; h.ah.VScrollMax = handlerVScrollMax;
h.ah.RedrawOnResize = handlerRedrawOnResize;
app = [NSApplication sharedApplication]; app = [NSApplication sharedApplication];
[app setActivationPolicy:NSApplicationActivationPolicyRegular]; [app setActivationPolicy:NSApplicationActivationPolicyRegular];

View File

@ -10,6 +10,7 @@ struct uiAreaHandler {
void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *); void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *);
uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *); uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *);
uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *); uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *);
int (*RedrawOnResize)(uiAreaHandler *, uiArea *);
}; };
struct uiAreaDrawParams { struct uiAreaDrawParams {

View File

@ -105,6 +105,11 @@ static uintmax_t handlerVScrollMax(uiAreaHandler *a, uiArea *area)
return _wtoi(c); return _wtoi(c);
*/} */}
static int handlerRedrawOnResize(uiAreaHandler *a, uiArea *area)
{
return 1;
}
// areaUpdateScroll(area); // areaUpdateScroll(area);
@interface appDelegate : NSObject<NSApplicationDelegate, NSTextFieldDelegate> @interface appDelegate : NSObject<NSApplicationDelegate, NSTextFieldDelegate>
@ -162,6 +167,7 @@ int main(void)
h.ah.Draw = handlerDraw; h.ah.Draw = handlerDraw;
h.ah.HScrollMax = handlerHScrollMax; h.ah.HScrollMax = handlerHScrollMax;
h.ah.VScrollMax = handlerVScrollMax; h.ah.VScrollMax = handlerVScrollMax;
h.ah.RedrawOnResize = handlerRedrawOnResize;
app = [NSApplication sharedApplication]; app = [NSApplication sharedApplication];
[app setActivationPolicy:NSApplicationActivationPolicyRegular]; [app setActivationPolicy:NSApplicationActivationPolicyRegular];

View File

@ -10,6 +10,7 @@ struct uiAreaHandler {
void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *); void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *);
uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *); uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *);
uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *); uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *);
int (*RedrawOnResize)(uiAreaHandler *, uiArea *);
}; };
struct uiAreaDrawParams { struct uiAreaDrawParams {

View File

@ -257,6 +257,7 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
HDC dc; HDC dc;
PAINTSTRUCT ps; PAINTSTRUCT ps;
RECT client; RECT client;
WINDOWPOS *wp = (WINDOWPOS *) lParam;
a = (uiArea *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); a = (uiArea *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
if (a == NULL) { if (a == NULL) {
@ -281,6 +282,13 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
logLastError("error getting client rect in WM_PRINTCLIENT in areaWndProc()"); logLastError("error getting client rect in WM_PRINTCLIENT in areaWndProc()");
doPaint(a, (HDC) wParam, &client, &client); doPaint(a, (HDC) wParam, &client, &client);
return 0; return 0;
case WM_WINDOWPOSCHANGED:
if ((wp->flags & SWP_NOSIZE) != 0)
break;
if ((*(a->ah->RedrawOnResize))(a->ah, a))
if (InvalidateRect(a->hwnd, NULL, TRUE) == 0)
logLastError("error redrawing area on resize in areaWndProc()");
return 0;
case WM_HSCROLL: case WM_HSCROLL:
hscroll(a, wParam, lParam); hscroll(a, wParam, lParam);
return 0; return 0;
@ -312,7 +320,7 @@ ATOM registerAreaClass(void)
//TODO wc.hIcon = hDefaultIcon; //TODO wc.hIcon = hDefaultIcon;
//TODO wc.hCursor = hDefaultCursor; //TODO wc.hCursor = hDefaultCursor;
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
wc.style = CS_HREDRAW | CS_VREDRAW; // don't specify CS_HREDRAW or CS_VREDRAW; that's decided by the uiAreaHandler in RedrawOnResize()
return RegisterClassW(&wc); return RegisterClassW(&wc);
} }

View File

@ -105,6 +105,11 @@ static uintmax_t handlerVScrollMax(uiAreaHandler *a, uiArea *area)
return _wtoi(c); return _wtoi(c);
} }
static int handlerRedrawOnResize(uiAreaHandler *a, uiArea *area)
{
return 1;
}
static void repos(HWND hwnd) static void repos(HWND hwnd)
{ {
RECT r; RECT r;
@ -155,6 +160,7 @@ int main(void)
h.ah.Draw = handlerDraw; h.ah.Draw = handlerDraw;
h.ah.HScrollMax = handlerHScrollMax; h.ah.HScrollMax = handlerHScrollMax;
h.ah.VScrollMax = handlerVScrollMax; h.ah.VScrollMax = handlerVScrollMax;
h.ah.RedrawOnResize = handlerRedrawOnResize;
registerAreaClass(); registerAreaClass();

View File

@ -10,6 +10,7 @@ struct uiAreaHandler {
void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *); void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *);
uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *); uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *);
uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *); uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *);
int (*RedrawOnResize)(uiAreaHandler *, uiArea *);
}; };
struct uiAreaDrawParams { struct uiAreaDrawParams {