<commit_before>/** \file
 * \brief GLScrollBox control
 *
 * See Copyright Notice in "iup.h"
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "iup.h"
#include "iupcbs.h"
#include "iupglcontrols.h"

#include "iup_object.h"
#include "iup_register.h"
#include "iup_attrib.h"
#include "iup_str.h"
#include "iup_layout.h"

#include "iup_glcontrols.h"

enum {
  SB_NONE, 
  SB_INC_X, SB_PAGEINC_X, SB_DRAG_X, SB_PAGEDEC_X, SB_DEC_X,
  SB_INC_Y, SB_PAGEINC_Y, SB_DRAG_Y, SB_PAGEDEC_Y, SB_DEC_Y
};

int iupGLScrollbarsGetSize(Ihandle* ih)
{
  return iupAttribGetInt(ih, "SCROLLBARSIZE");
}

int iupGLScrollbarsIsInsideHandlers(Ihandle* ih, int x, int y)
{
  int has_vert_scroll = 0;
  int has_horiz_scroll = 0;
  int sb_size = iupGLScrollbarsGetSize(ih);
  int width = ih->currentwidth,
    height = ih->currentheight;
  int sb_xmin = iupAttribGetInt(ih, "XMIN");
  int sb_xmax = iupAttribGetInt(ih, "XMAX");
  int sb_ymin = iupAttribGetInt(ih, "YMIN");
  int sb_ymax = iupAttribGetInt(ih, "YMAX");
  int sb_dy = iupAttribGetInt(ih, "DY");
  int sb_dx = iupAttribGetInt(ih, "DX");

  if (sb_xmax - sb_xmin > sb_dx)  /* has horizontal scrollbar */
  {
    has_horiz_scroll = 1;
    height -= sb_size;
  }

  if (sb_ymax - sb_ymin > sb_dy)  /* has vertical scrollbar */
  {
    has_vert_scroll = 1;
    width -= sb_size;
  }

  if (has_vert_scroll)
  {
    if (x >= ih->currentwidth - sb_size && x < ih->currentwidth)
    {
      int sb_posy = iupAttribGetInt(ih, "POSY");
      int ymin = 0;
      int ymax = height - 1;
      int dy   =  (sb_dy              * (ymax - ymin - 2 * sb_size)) / (sb_ymax - sb_ymin);
      int posy = ((sb_posy - sb_ymin) * (ymax - ymin - 2 * sb_size)) / (sb_ymax - sb_ymin);
      posy += ymin + sb_size;

      if (y < sb_size)
        return SB_DEC_Y;
      else if (y < posy)
        return SB_PAGEDEC_Y;
      else if (y < posy + dy)
        return SB_DRAG_Y;
      else if (y < height - sb_size)
        return SB_PAGEINC_Y;
      else if (y < height)
        return SB_INC_Y;

      return SB_NONE;
    }
  }

  if (has_horiz_scroll)
  {
    if (y >= ih->currentheight - sb_size && y < ih->currentheight)
    {
      int sb_posx = iupAttribGetInt(ih, "POSX");
      int xmin = 0;
      int xmax = width - 1;
      int dx   =  (sb_dx              * (xmax - xmin - 2 * sb_size)) / (sb_xmax - sb_xmin);
      int posx = ((sb_posx - sb_xmin) * (xmax - xmin - 2 * sb_size)) / (sb_xmax - sb_xmin);
      posx += xmin + sb_size;

      if (x < sb_size)
        return SB_DEC_X;
      else if (x < posx)
        return SB_PAGEDEC_X;
      else if (x < posx + dx)
        return SB_DRAG_X;
      else if (x < width - sb_size)
        return SB_PAGEINC_X;
      else if (x < width)
        return SB_INC_X;

      return SB_NONE;
    }
  }

  return SB_NONE;
}

static void iGLScrollbarsDrawVertical(Ihandle* ih, int active, const char* fgcolor, const char* bgcolor, int sb_ymin, int sb_ymax, int sb_dy, int has_horiz_scroll)
{
  int sb_size = iupGLScrollbarsGetSize(ih);
  int height = ih->currentheight;
  int xmin, xmax, ymin, ymax, posy, dy;
  int sb_posy = iupAttribGetInt(ih, "POSY");

  if (has_horiz_scroll)
    height -= sb_size;

  xmin = ih->currentwidth - sb_size;
  xmax = ih->currentwidth - 1;
  ymin = 0;
  ymax = height - 1;

  dy   =  (sb_dy              * (ymax - ymin - 2 * sb_size)) / (sb_ymax - sb_ymin);
  posy = ((sb_posy - sb_ymin) * (ymax - ymin - 2 * sb_size)) / (sb_ymax - sb_ymin);
  posy += ymin + sb_size;

  /* draw background */
  iupGLDrawBox(ih, xmin, xmax,
                   ymin, ymax, bgcolor, 1);

  /* draw arrows */
  iupGLDrawArrow(ih, xmin + 2, ymin,           sb_size - 5, fgcolor, active, IUPGL_ARROW_TOP);
  iupGLDrawArrow(ih, xmin + 2, ymax - sb_size, sb_size - 5, fgcolor, active, IUPGL_ARROW_BOTTOM);

  /* draw handler */
  iupGLDrawBox(ih, xmin + 2, xmax - 2,
                   posy, posy + dy, fgcolor, active);
}

static void iGLScrollbarsDrawHorizontal(Ihandle* ih, int active, const char* fgcolor, const char* bgcolor, int sb_xmin, int sb_xmax, int sb_dx, int has_vert_scroll)
{
  int sb_size = iupGLScrollbarsGetSize(ih);
  int width = ih->currentwidth;
  int xmin, xmax, ymin, ymax, posx, dx;
  int sb_posx = iupAttribGetInt(ih, "POSX");

  if (has_vert_scroll)
    width -= sb_size;

  xmin = 0;
  xmax = width - 1;
  ymin = ih->currentheight - sb_size;
  ymax = ih->currentheight - 1;

  dx   =  (sb_dx              * (xmax - xmin - 2 * sb_size)) / (sb_xmax - sb_xmin);
  posx = ((sb_posx - sb_xmin) * (xmax - xmin - 2 * sb_size)) / (sb_xmax - sb_xmin);
  posx += xmin + sb_size;

  /* draw background */
  iupGLDrawBox(ih, xmin, xmax,
                   ymin, ymax, bgcolor, 1);

  /* draw arrows */
  iupGLDrawArrow(ih, xmin,           ymin + 2, sb_size - 5, fgcolor, active, IUPGL_ARROW_LEFT);
  iupGLDrawArrow(ih, xmax - sb_size, ymin + 2, sb_size - 5, fgcolor, active, IUPGL_ARROW_RIGHT);

  /* draw handler */
  iupGLDrawBox(ih, posx, posx + dx,
                   ymin + 2, ymax - 2, fgcolor, active);
}

void iupGLScrollbarsDraw(Ihandle* ih, int active, const char* fgcolor, const char* bgcolor)
{
  int has_vert_scroll = 0;
  int has_horiz_scroll = 0;
  int sb_xmin = iupAttribGetInt(ih, "XMIN");
  int sb_xmax = iupAttribGetInt(ih, "XMAX");
  int sb_ymin = iupAttribGetInt(ih, "YMIN");
  int sb_ymax = iupAttribGetInt(ih, "YMAX");
  int sb_dx = iupAttribGetInt(ih, "DX");
  int sb_dy = iupAttribGetInt(ih, "DY");

  if (sb_xmax - sb_xmin > sb_dx)  /* has horizontal scrollbar */
    has_horiz_scroll = 1;

  if (sb_ymax - sb_ymin > sb_dy)  /* has vertical scrollbar */
    has_vert_scroll = 1;

  if (has_vert_scroll)
    iGLScrollbarsDrawVertical(ih, active, fgcolor, bgcolor, sb_ymin, sb_ymax, sb_dy, has_horiz_scroll);

  if (has_horiz_scroll)
    iGLScrollbarsDrawHorizontal(ih, active, fgcolor, bgcolor, sb_xmin, sb_xmax, sb_dx, has_vert_scroll);
}
<commit_msg>*** empty log message ***<commit_after>/** \file
 * \brief GLScrollBox control
 *
 * See Copyright Notice in "iup.h"
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "iup.h"
#include "iupcbs.h"
#include "iupglcontrols.h"

#include "iup_object.h"
#include "iup_register.h"
#include "iup_attrib.h"
#include "iup_str.h"
#include "iup_layout.h"

#include "iup_glcontrols.h"

enum {
  SB_NONE, 
  SB_INC_X, SB_PAGEINC_X, SB_DRAG_X, SB_PAGEDEC_X, SB_DEC_X,
  SB_INC_Y, SB_PAGEINC_Y, SB_DRAG_Y, SB_PAGEDEC_Y, SB_DEC_Y
};

int iupGLScrollbarsGetSize(Ihandle* ih)
{
  return iupAttribGetInt(ih, "SCROLLBARSIZE");
}

int iupGLScrollbarsIsInsideHandlers(Ihandle* ih, int x, int y)
{
  int has_vert_scroll = 0;
  int has_horiz_scroll = 0;
  int sb_size = iupGLScrollbarsGetSize(ih);
  int width = ih->currentwidth,
    height = ih->currentheight;
  int sb_xmin = iupAttribGetInt(ih, "XMIN");
  int sb_xmax = iupAttribGetInt(ih, "XMAX");
  int sb_ymin = iupAttribGetInt(ih, "YMIN");
  int sb_ymax = iupAttribGetInt(ih, "YMAX");
  int sb_dy = iupAttribGetInt(ih, "DY");
  int sb_dx = iupAttribGetInt(ih, "DX");

  if (sb_xmax - sb_xmin > sb_dx)  /* has horizontal scrollbar */
  {
    has_horiz_scroll = 1;
    height -= sb_size;
  }

  if (sb_ymax - sb_ymin > sb_dy)  /* has vertical scrollbar */
  {
    has_vert_scroll = 1;
    width -= sb_size;
  }

  if (has_vert_scroll)
  {
    if (x >= ih->currentwidth - sb_size && x < ih->currentwidth)
    {
      int sb_posy = iupAttribGetInt(ih, "POSY");
      int ymin = 0;
      int ymax = height - 1;
      int dy   =  (sb_dy              * (ymax - ymin - 2 * sb_size)) / (sb_ymax - sb_ymin);
      int posy = ((sb_posy - sb_ymin) * (ymax - ymin - 2 * sb_size)) / (sb_ymax - sb_ymin);
      posy += ymin + sb_size;

      if (y < sb_size)
        return SB_DEC_Y;
      else if (y < posy)
        return SB_PAGEDEC_Y;
      else if (y < posy + dy)
        return SB_DRAG_Y;
      else if (y < height - sb_size)
        return SB_PAGEINC_Y;
      else if (y < height)
        return SB_INC_Y;

      return SB_NONE;
    }
  }

  if (has_horiz_scroll)
  {
    if (y >= ih->currentheight - sb_size && y < ih->currentheight)
    {
      int sb_posx = iupAttribGetInt(ih, "POSX");
      int xmin = 0;
      int xmax = width - 1;
      int dx   =  (sb_dx              * (xmax - xmin - 2 * sb_size)) / (sb_xmax - sb_xmin);
      int posx = ((sb_posx - sb_xmin) * (xmax - xmin - 2 * sb_size)) / (sb_xmax - sb_xmin);
      posx += xmin + sb_size;

      if (x < sb_size)
        return SB_DEC_X;
      else if (x < posx)
        return SB_PAGEDEC_X;
      else if (x < posx + dx)
        return SB_DRAG_X;
      else if (x < width - sb_size)
        return SB_PAGEINC_X;
      else if (x < width)
        return SB_INC_X;

      return SB_NONE;
    }
  }

  return SB_NONE;
}

static void iGLScrollbarsDrawVertical(Ihandle* ih, int active, const char* fgcolor, const char* bgcolor, int sb_ymin, int sb_ymax, int sb_dy, int has_horiz_scroll)
{
  int sb_size = iupGLScrollbarsGetSize(ih);
  int height = ih->currentheight;
  int xmin, xmax, ymin, ymax, posy, dy;
  int sb_posy = iupAttribGetInt(ih, "POSY");

  if (has_horiz_scroll)
    height -= sb_size;

  xmin = ih->currentwidth - sb_size;
  xmax = ih->currentwidth - 1;
  ymin = 0;
  ymax = height - 1;

  dy   =  (sb_dy              * (ymax - ymin - 2 * sb_size)) / (sb_ymax - sb_ymin);
  posy = ((sb_posy - sb_ymin) * (ymax - ymin - 2 * sb_size)) / (sb_ymax - sb_ymin);
  posy += ymin + sb_size;

  /* draw background */
  iupGLDrawBox(ih, xmin, xmax,
                   ymin, ymax, bgcolor, 1);

  /* draw arrows */
  iupGLDrawArrow(ih, xmin + 2, ymin + 2,           sb_size - 5, fgcolor, active, IUPGL_ARROW_TOP);
  iupGLDrawArrow(ih, xmin + 2, ymax - sb_size + 3, sb_size - 5, fgcolor, active, IUPGL_ARROW_BOTTOM);

  /* draw handler */
  iupGLDrawBox(ih, xmin + 2, xmax - 2,
                   posy, posy + dy, fgcolor, active);
}

static void iGLScrollbarsDrawHorizontal(Ihandle* ih, int active, const char* fgcolor, const char* bgcolor, int sb_xmin, int sb_xmax, int sb_dx, int has_vert_scroll)
{
  int sb_size = iupGLScrollbarsGetSize(ih);
  int width = ih->currentwidth;
  int xmin, xmax, ymin, ymax, posx, dx;
  int sb_posx = iupAttribGetInt(ih, "POSX");

  if (has_vert_scroll)
    width -= sb_size;

  xmin = 0;
  xmax = width - 1;
  ymin = ih->currentheight - sb_size;
  ymax = ih->currentheight - 1;

  dx   =  (sb_dx              * (xmax - xmin - 2 * sb_size)) / (sb_xmax - sb_xmin);
  posx = ((sb_posx - sb_xmin) * (xmax - xmin - 2 * sb_size)) / (sb_xmax - sb_xmin);
  posx += xmin + sb_size;

  /* draw background */
  iupGLDrawBox(ih, xmin, xmax,
                   ymin, ymax, bgcolor, 1);

  /* draw arrows */
  iupGLDrawArrow(ih, xmin + 2,           ymin + 2, sb_size - 5, fgcolor, active, IUPGL_ARROW_LEFT);
  iupGLDrawArrow(ih, xmax - sb_size + 3, ymin + 2, sb_size - 5, fgcolor, active, IUPGL_ARROW_RIGHT);

  /* draw handler */
  iupGLDrawBox(ih, posx, posx + dx,
                   ymin + 2, ymax - 2, fgcolor, active);
}

void iupGLScrollbarsDraw(Ihandle* ih, int active, const char* fgcolor, const char* bgcolor)
{
  int has_vert_scroll = 0;
  int has_horiz_scroll = 0;
  int sb_xmin = iupAttribGetInt(ih, "XMIN");
  int sb_xmax = iupAttribGetInt(ih, "XMAX");
  int sb_ymin = iupAttribGetInt(ih, "YMIN");
  int sb_ymax = iupAttribGetInt(ih, "YMAX");
  int sb_dx = iupAttribGetInt(ih, "DX");
  int sb_dy = iupAttribGetInt(ih, "DY");

  if (sb_xmax - sb_xmin > sb_dx)  /* has horizontal scrollbar */
    has_horiz_scroll = 1;

  if (sb_ymax - sb_ymin > sb_dy)  /* has vertical scrollbar */
    has_vert_scroll = 1;

  if (has_vert_scroll)
    iGLScrollbarsDrawVertical(ih, active, fgcolor, bgcolor, sb_ymin, sb_ymax, sb_dy, has_horiz_scroll);

  if (has_horiz_scroll)
    iGLScrollbarsDrawHorizontal(ih, active, fgcolor, bgcolor, sb_xmin, sb_xmax, sb_dx, has_vert_scroll);
}

{'fraction_non_alphanumeric': 0.1287648054145516, 'fraction_numerical': 0.007106598984771574, 'mean_word_length': 2.7754710954966466, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4915844', 'n_tokens_mistral': 5007, 'n_tokens_neox': 4870, 'n_words': 1164}