static void iGLValGetHandlerSize(Ihandle* ih, int is_horizontal, int *width, int *height) { char *image = iupAttribGet(ih, "IMAGE"); if (image) iupGLImageGetInfo(image, width, height, NULL); else { int handler_size = iupAttribGetInt(ih, "HANDLERSIZE"); if (is_horizontal) { if (handler_size == 0) handler_size = ih->currentheight / 2; *width = handler_size; *height = ih->currentheight; } else { if (handler_size == 0) handler_size = ih->currentwidth / 2; *width = ih->currentwidth; *height = handler_size; } } }
static int iGLExpanderGetBarSize(Ihandle* ih) { int bar_size; if (ih->data->barSize == -1) { iupGLFontGetCharSize(ih, NULL, &bar_size); /* define a minimum size only when estimating one from charsize */ if (bar_size < IEXPAND_HANDLE_SIZE) bar_size = IEXPAND_HANDLE_SIZE; if (ih->data->position == IEXPANDER_TOP) { char* title = iupAttribGetStr(ih, "TITLE"); char* image = iupAttribGetStr(ih, "IMAGE"); if (image) { int image_h = 0; iupGLImageGetInfo(image, NULL, &image_h, NULL); bar_size = iupMAX(bar_size, image_h); } if (title || image || ih->data->extra_buttons != 0) bar_size += 2 * IEXPAND_BACK_MARGIN; } } else bar_size = ih->data->barSize; return bar_size; }
static void iGLExpanderDrawExtraButton(Ihandle* ih, int button, int x, int y, int height) { char* image = iupAttribGetId(ih, "IMAGEEXTRA", button); int active = IupGetInt(ih, "ACTIVE"); int img_height; if (!image) return; if (ih->data->extra_buttons_state[button] == 1) { char* impress = iupAttribGetId(ih, "IMAGEEXTRAPRESS", button); if (impress) image = impress; } else if (ih->data->extra_buttons_state[button] == -1) { char* imhighlight = iupAttribGetId(ih, "IMAGEEXTRAHIGHLIGHT", button); if (imhighlight) image = imhighlight; } iupGLImageGetInfo(image, NULL, &img_height, NULL); if (height > img_height) y += (height - img_height) / 2; iupGLDrawImage(ih, x, y, image, !active); }
static int iGLExpanderIsInsideHandler(Ihandle* ih, int x, int y, int bar_size) { char *image = iupAttribGet(ih, "IMAGE"); char* title = iupAttribGet(ih, "TITLE"); if (ih->data->position == IEXPANDER_TOP && (title || image || ih->data->extra_buttons != 0)) { /* always left aligned */ if (y >= IEXPAND_SPACING + IEXPAND_BACK_MARGIN && y <= bar_size - IEXPAND_SPACING - IEXPAND_BACK_MARGIN) { int icon_width = IEXPAND_HANDLE_SIZE; if (image) { int width; iupGLImageGetInfo(image, &width, NULL, NULL); icon_width = iupMAX(icon_width, width); } if (title) { int width; iupGLFontGetMultiLineStringSize(ih, title, &width, NULL); icon_width += width; } if (x >= IEXPAND_BACK_MARGIN && x < IEXPAND_BACK_MARGIN + icon_width) return 1; } } else { /* always centered */ if (ih->data->position == IEXPANDER_TOP || ih->data->position == IEXPANDER_BOTTOM) { if (y >= IEXPAND_SPACING && y <= bar_size - IEXPAND_SPACING) { int half = ih->currentwidth / 2; if (x >= half - IEXPAND_HANDLE_SIZE / 2 && x <= half + IEXPAND_HANDLE_SIZE/2) return 1; } } else /* IEXPANDER_LEFT or IEXPANDER_RIGHT */ { if (x >= IEXPAND_SPACING && x <= bar_size - IEXPAND_SPACING) { int half = ih->currentheight / 2; if (y >= half - IEXPAND_HANDLE_SIZE / 2 && y <= half + IEXPAND_HANDLE_SIZE / 2) return 1; } } } return 0; }
static void iGLProgressBarComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand) { int natural_w = 0, natural_h = 0; int fit2backimage = iupAttribGetBoolean(ih, "FITTOBACKIMAGE"); char* bgimage = iupAttribGet(ih, "BACKIMAGE"); if (fit2backimage && bgimage) { iupAttribSet(ih, "BORDERWIDTH", "0"); iupGLImageGetInfo(bgimage, &natural_w, &natural_h, NULL); } else { iGLProgressBar* pb = (iGLProgressBar*)iupAttribGet(ih, "_IUP_GLPROGRESSBAR"); int charwidth, charheight; float bwidth = iupAttribGetFloat(ih, "BORDERWIDTH"); int border_width = (int)ceil(bwidth); int is_horizontal = iupStrEqualNoCase(iupAttribGetStr(ih, "ORIENTATION"), "HORIZONTAL"); iupGLFontGetCharSize(ih, &charwidth, &charheight); if (is_horizontal) { natural_h = charheight; if (ih->userwidth <= 0) natural_w = 15 * charwidth; } else { natural_w = charheight; if (ih->userheight <= 0) natural_h = 15 * charwidth; } natural_w += 2 * (pb->horiz_padding + border_width); natural_h += 2 * (pb->vert_padding + border_width); } *w = natural_w; *h = natural_h; (void)children_expand; /* unset if not a container */ }
static void iGLValComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand) { int natural_w = 0, natural_h = 0; int fit2backimage = iupAttribGetBoolean(ih, "FITTOBACKIMAGE"); char* bgimage = iupAttribGet(ih, "BACKIMAGE"); if (fit2backimage && bgimage) { iupAttribSet(ih, "BORDERWIDTH", "0"); iupGLImageGetInfo(bgimage, &natural_w, &natural_h, NULL); } else { int charwidth, charheight; int is_horizontal = iupStrEqualNoCase(iupAttribGetStr(ih, "ORIENTATION"), "HORIZONTAL"); iupGLFontGetCharSize(ih, &charwidth, &charheight); if (is_horizontal) { natural_h = charheight; if (ih->userwidth <= 0) natural_w = 15 * charwidth; } else { natural_w = charheight; if (ih->userheight <= 0) natural_h = 15 * charwidth; } } *w = natural_w; *h = natural_h; (void)children_expand; /* unset if not a container */ }
static void iGLButtonComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand) { int fit2backimage = iupAttribGetBoolean(ih, "FITTOBACKIMAGE"); char* bgimage = iupAttribGet(ih, "BACKIMAGE"); if (fit2backimage && bgimage) { iupAttribSet(ih, "BORDERWIDTH", "0"); iupGLImageGetInfo(bgimage, w, h, NULL); } else { float bwidth = iupAttribGetFloat(ih, "BORDERWIDTH"); int border_width = (int)ceil(bwidth); if (border_width == 0) return; /* add to the label natural size */ *w += 2 * border_width; *h += 2 * border_width; } (void)children_expand; /* unset if not a container */ }
static int iGLValACTION_CB(Ihandle* ih) { iGLVal* val = (iGLVal*)iupAttribGet(ih, "_IUP_GLVAL"); float bwidth = iupAttribGetFloat(ih, "BORDERWIDTH"); char* bordercolor = iupAttribGetStr(ih, "BORDERCOLOR"); int active = iupAttribGetInt(ih, "ACTIVE"); char* bgcolor = iupAttribGetStr(ih, "BGCOLOR"); int slider_size = iupAttribGetInt(ih, "SLIDERSIZE"); int border_width = (int)ceil(bwidth); int is_horizontal = iupStrEqualNoCase(iupAttribGetStr(ih, "ORIENTATION"), "HORIZONTAL"); int handler_width, handler_height; char *image = iupAttribGet(ih, "IMAGE"); char* bgimage = iupAttribGet(ih, "BACKIMAGE"); double percent = (val->value - val->vmin) / (val->vmax - val->vmin); int x1, y1, x2, y2; iGLValGetHandlerSize(ih, is_horizontal, &handler_width, &handler_height); if (is_horizontal) { x1 = handler_width / 2; x2 = ih->currentwidth - 1 - handler_width / 2; y1 = (ih->currentheight - slider_size) / 2; y2 = y1 + slider_size; } else { y1 = handler_height / 2; y2 = ih->currentheight - 1 - handler_height / 2; x1 = (ih->currentwidth - slider_size) / 2; x2 = x1 + slider_size; } /* draw slider background */ if (bgimage) iupGLDrawIconImageZoom(ih, border_width, border_width, border_width, border_width, "BACKIMAGE", bgimage, active); else { iupGLDrawBox(ih, x1 + border_width, x2 - border_width, y1 + border_width, y2 - border_width, bgcolor, 1); /* always active */ /* draw slider border - can be disabled setting bwidth=0 */ iupGLDrawRect(ih, x1, x2, y1, y2, bwidth, bordercolor, active, 0); } if (is_horizontal) { int xmid = x1 + iupRound((x2 - x1) * percent); x1 = xmid - handler_width / 2; if (x1 < 0) x1 = 0; x2 = xmid + handler_width / 2; if (x2 > ih->currentwidth - 1) x2 = ih->currentwidth - 1; y1 = 0; y2 = ih->currentheight - 1; } else { int ymid = y1 + iupRound((y2 - y1) * (1.0 - percent)); y1 = ymid - handler_height / 2; if (y1 < 0) y1 = 0; y2 = ymid + handler_height / 2; if (y2 > ih->currentheight - 1) y2 = ih->currentheight - 1; x1 = 0; x2 = ih->currentwidth - 1; } if (image) { int x, y, width, height; iupGLImageGetInfo(image, &width, &height, NULL); /* always center the image */ x = (x2 - x1 + 1 - width) / 2; y = (y2 - y1 + 1 - height) / 2; if (x1 + x < 0) x = 0; if (y1 + y < 0) y = 0; if (x1 + x + width > ih->currentwidth - 1) x = ih->currentwidth - 1 - width - x1; if (y1 + y + height > ih->currentheight - 1) y = ih->currentheight - 1 - height - y1; iupGLDrawIconImage(ih, x1 + x, y1 + y, "IMAGE", image, active); } else { int pressed = iupAttribGetInt(ih, "PRESSED"); int highlight = iupAttribGetInt(ih, "HIGHLIGHT"); char* fgcolor = iupAttribGetStr(ih, "FGCOLOR"); if (pressed) { char* presscolor = iupAttribGetStr(ih, "PSCOLOR"); if (presscolor) fgcolor = presscolor; } else if (highlight) { char* hlcolor = iupAttribGetStr(ih, "HLCOLOR"); if (hlcolor) fgcolor = hlcolor; } /* draw handler foreground */ iupGLDrawBox(ih, x1 + border_width, x2 - border_width, y1 + border_width, y2 - border_width, fgcolor, active); /* draw handler border - can still be disabled setting bwidth=0 after the background because of the round rect */ iupGLDrawRect(ih, x1, x2, y1, y2, bwidth, bordercolor, active, 1); } return IUP_DEFAULT; }
static void iGLExpanderComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand) { int child_expand = 0, natural_w, natural_h; Ihandle *child = ih->firstchild; int bar_size = iGLExpanderGetBarSize(ih); /* bar */ if (ih->data->position == IEXPANDER_LEFT || ih->data->position == IEXPANDER_RIGHT) { natural_w = bar_size; natural_h = IEXPAND_HANDLE_SIZE; /* just a minimum size */ } else { natural_w = IEXPAND_HANDLE_SIZE; /* just a minimum size */ natural_h = bar_size; if (ih->data->position == IEXPANDER_TOP) { char* title, *image; /* if IMAGE is defined assume that will cover all the canvas area */ image = iupAttribGetStr(ih, "IMAGE"); if (image) { int image_w = 0; iupGLImageGetInfo(image, &image_w, NULL, NULL); natural_w = iupMAX(natural_w, image_w); } /* if TITLE and IMAGE are both defined then IMAGE is only the handle */ title = iupAttribGetStr(ih, "TITLE"); if (title) { int title_size = 0; iupGLFontGetMultiLineStringSize(ih, title, &title_size, NULL); natural_w += title_size; } if (ih->data->extra_buttons != 0) natural_w += ih->data->extra_buttons * (IEXPAND_BUTTON_SIZE + IEXPAND_SPACING); if (image || title || ih->data->extra_buttons != 0) natural_w += 2 * IEXPAND_BACK_MARGIN; } } if (child) { /* update child natural bar_size first */ iupBaseComputeNaturalSize(child); if (ih->data->position == IEXPANDER_LEFT || ih->data->position == IEXPANDER_RIGHT) { if (ih->data->state == IEXPANDER_OPEN) /* only open, not float */ natural_w += child->naturalwidth; natural_h = iupMAX(natural_h, child->naturalheight); } else { natural_w = iupMAX(natural_w, child->naturalwidth); if (ih->data->state == IEXPANDER_OPEN) /* only open, not float */ natural_h += child->naturalheight; } if (ih->data->state == IEXPANDER_OPEN) child_expand = child->expand; else { if (ih->data->position == IEXPANDER_LEFT || ih->data->position == IEXPANDER_RIGHT) child_expand = child->expand & IUP_EXPAND_HEIGHT; /* only vertical allowed */ else child_expand = child->expand & IUP_EXPAND_WIDTH; /* only horizontal allowed */ } } *children_expand = child_expand; *w = natural_w; *h = natural_h; }
static int iGLExpanderACTION_CB(Ihandle* ih) { int x1, y1, x2, y2; char *image = iupAttribGet(ih, "IMAGE"); char* title = iupAttribGet(ih, "TITLE"); int active = iupAttribGetInt(ih, "ACTIVE"); char* fgcolor = iupAttribGetStr(ih, "FORECOLOR"); char* bgcolor = iupAttribGetStr(ih, "BACKCOLOR"); int highlight = iupAttribGetInt(ih, "HIGHLIGHT"); int pressed = iupAttribGetInt(ih, "PRESSED"); int bar_size = iGLExpanderGetBarSize(ih); /* calc bar position */ if (ih->data->position == IEXPANDER_LEFT) { x1 = 0; x2 = bar_size; y1 = 0; y2 = ih->currentheight - 1; } else if (ih->data->position == IEXPANDER_RIGHT) { x1 = ih->currentwidth-1 - bar_size; x2 = ih->currentwidth-1; y1 = 0; y2 = ih->currentheight - 1; } else if (ih->data->position == IEXPANDER_BOTTOM) { x1 = 0; x2 = ih->currentwidth - 1; y1 = ih->currentheight-1 - bar_size; y2 = ih->currentheight-1; } else /* IEXPANDER_TOP */ { x1 = 0; x2 = ih->currentwidth - 1; y1 = 0; y2 = bar_size; } /* draw bar box */ iupGLDrawBox(ih, x1, x2, y1, y2, bgcolor, 1); if (ih->data->position == IEXPANDER_TOP && (title || image || ih->data->extra_buttons != 0)) { /* left align image/handler+title */ int txt_offset = IEXPAND_HANDLE_SIZE; if (image) { int active = IupGetInt(ih, "ACTIVE"); int img_width = 0, img_height = 0; int y_offset = 0; if (ih->data->state != IEXPANDER_CLOSE) { char* imopen = iupAttribGetStr(ih, "IMAGEOPEN"); if (imopen) image = imopen; if (highlight) { char* imhighlight = iupAttribGetStr(ih, "IMAGEOPENHIGHLIGHT"); if (imhighlight) image = imhighlight; } } else if (highlight) { char* imhighlight = iupAttribGetStr(ih, "IMAGEHIGHLIGHT"); if (imhighlight) image = imhighlight; } iupGLImageGetInfo(image, &img_width, &img_height, NULL); if (bar_size > img_height) y_offset = (bar_size - img_height) / 2; iupGLDrawImage(ih, IEXPAND_BACK_MARGIN, y_offset, image, !active); txt_offset = iupMAX(txt_offset, img_width); } else { int y_offset = 0; if (bar_size > IEXPAND_HANDLE_SIZE + 2 * IEXPAND_BACK_MARGIN) y_offset = (bar_size - IEXPAND_HANDLE_SIZE - 2 * IEXPAND_BACK_MARGIN) / 2; if (pressed) { char* presscolor = iupAttribGetStr(ih, "PRESSCOLOR"); if (presscolor) fgcolor = presscolor; } else if (highlight) { char* hlcolor = iupAttribGetStr(ih, "HIGHCOLOR"); if (hlcolor) fgcolor = hlcolor; } if (ih->data->state == IEXPANDER_CLOSE) iGLExpanderDrawSmallArrow(ih, fgcolor, active, IEXPANDER_RIGHT, y_offset); else iGLExpanderDrawSmallArrow(ih, fgcolor, active, IEXPANDER_BOTTOM, y_offset); } if (title) { int height; iupGLFontGetMultiLineStringSize(ih, title, NULL, &height); iupGLDrawText(ih, txt_offset, (bar_size - height) / 2 - 1, title, fgcolor, active); } if (ih->data->extra_buttons != 0) { /* right align extra buttons */ int y = IEXPAND_SPACING + IEXPAND_BACK_MARGIN; int height = bar_size - 2 * (IEXPAND_SPACING + IEXPAND_BACK_MARGIN); iGLExpanderDrawExtraButton(ih, 1, ih->currentwidth - (IEXPAND_BUTTON_SIZE + IEXPAND_SPACING) - IEXPAND_BACK_MARGIN, y, height); if (ih->data->extra_buttons > 1) iGLExpanderDrawExtraButton(ih, 2, ih->currentwidth - 2 * (IEXPAND_BUTTON_SIZE + IEXPAND_SPACING) - IEXPAND_BACK_MARGIN, y, height); if (ih->data->extra_buttons == 3) iGLExpanderDrawExtraButton(ih, 3, ih->currentwidth - 3 * (IEXPAND_BUTTON_SIZE + IEXPAND_SPACING) - IEXPAND_BACK_MARGIN, y, height); } } else { /* center align the handler */ int x = x1, y = y1, width = x2 - x1 + 1, height = y2 - y1 + 1; if (pressed) { char* presscolor = iupAttribGetStr(ih, "PRESSCOLOR"); if (presscolor) fgcolor = presscolor; } else if (highlight) { char* hlcolor = iupAttribGetStr(ih, "HIGHCOLOR"); if (hlcolor) fgcolor = hlcolor; } switch (ih->data->position) { case IEXPANDER_LEFT: x += 0; y += (height - IEXPAND_HANDLE_SIZE) / 2; if (ih->data->state == IEXPANDER_CLOSE) iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_RIGHT); else iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_LEFT); break; case IEXPANDER_RIGHT: x += 0; y += (height - IEXPAND_HANDLE_SIZE) / 2; if (ih->data->state == IEXPANDER_CLOSE) iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_LEFT); else iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_RIGHT); break; case IEXPANDER_TOP: x += (width - IEXPAND_HANDLE_SIZE) / 2; y += 0; if (ih->data->state == IEXPANDER_CLOSE) iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_BOTTOM); else iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_TOP); break; case IEXPANDER_BOTTOM: x += (width - IEXPAND_HANDLE_SIZE) / 2; y += 0; if (ih->data->state == IEXPANDER_CLOSE) iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_TOP); else iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_BOTTOM); break; } } return IUP_DEFAULT; }