コード例 #1
0
void eol_font_draw_text_justify(
    char   * text,
    eolInt   x,
    eolInt   y,
    eolVec3D color,
    eolFloat alpha,
    eolUint  size,
    eolUint  justify
  )
{
  eolRect r;
  eolInt dx;
  if (!eol_font_initialized())return;
  r = eol_font_get_bounds(text,size);
  switch (justify)
  {
    case eolJustifyLeft:
      dx = x;
      break;
    case eolJustifyCenter:
      dx = (x - (r.w/2));
      break;
    case eolJustifyRight:
      dx = (x - r.w);
      break;
  }
  eol_font_draw_text(
    text,
    dx,
    y,
    color,
    alpha,
    size
  );
}
コード例 #2
0
eolUint eol_font_get_text_height_average(eolUint fontsize)
{
  eolRect r;
  r = eol_font_get_bounds(
    "gL",
    fontsize
  );
  return r.h;
}
コード例 #3
0
ファイル: eol_component.c プロジェクト: RabTom/EngineOfLies
void eol_component_make_button(
    eolComponent * component,
    char         * buttonText,
    eolUint        buttonType,
    eolInt         buttonHotkey,
    eolLine        buttonUpFile,
    eolLine        buttonHighFile,
    eolLine        buttonDownFile
  )
{
  eolRect r;
  eolComponentButton * button = NULL;
  if (!component)return;
  eol_component_button_new(component);

  button = eol_component_get_button_data(component);
  if (button == NULL)
  {
    return;
  }
  button->alpha = 1;
  button->fontSize = 3;
  button->input = buttonHotkey;
  strncpy(button->buttonText,buttonText,EOLLINELEN);
  button->buttonType = buttonType;
  switch(buttonType)
  {
    case eolButtonCustom:
      button->button[eolButtonIdle] = eol_sprite_load(buttonUpFile,-1,-1);
      button->button[eolButtonHighlight] = eol_sprite_load(buttonHighFile,-1,-1);
      button->button[eolButtonPressed] = eol_sprite_load(buttonDownFile,-1,-1);
      button->justify = eolJustifyCenter;
      component->bounds.w = button->button[eolButtonIdle]->frameWidth;
      component->bounds.h = button->button[eolButtonIdle]->frameHeight;
      break;
    case eolButtonText:
      button->button[eolButtonIdle] = NULL;
      button->button[eolButtonHighlight] = NULL;
      button->button[eolButtonPressed] = NULL;
      r = eol_font_get_bounds(buttonText,button->fontSize);
      component->bounds.w = r.w;
      component->bounds.h = r.h;
      button->justify = eolJustifyLeft;
      break;
    case eolButtonStock:
      button->button[eolButtonIdle] = _eol_component_stock_button[eolButtonIdle];
      button->button[eolButtonHighlight] = _eol_component_stock_button[eolButtonHighlight];
      button->button[eolButtonPressed] = _eol_component_stock_button[eolButtonPressed];
      button->justify = eolJustifyCenter;
      component->bounds.w = button->button[eolButtonIdle]->frameWidth;
      component->bounds.h = button->button[eolButtonIdle]->frameHeight;
      break;
  }
  component->data_update = eol_component_button_update;
  component->data_free = eol_component_button_free;
  component->data_draw = eol_component_button_draw;
}
コード例 #4
0
ファイル: eol_component.c プロジェクト: RabTom/EngineOfLies
void eol_component_make_label(
    eolComponent * component,
    char         * text,
    eolUint        justify,
    eolInt         fontSize,
    eolBool        wordWrap,
    char         * fontName,
    eolVec3D       color,
    eolFloat       alpha
  )
{
  eolRect r;
  eolComponentLabel * label = NULL;
  if (!component)return;
  eol_component_label_new(component);
  
  label = eol_component_get_label_data(component);
  if (label == NULL)
  {
    return;
  }

  label->buffer = g_string_new(text);
  if (label->buffer == NULL)
  {
    eol_logger_message(
      EOL_LOG_ERROR,
      "eol_component:Failed to duplicate string for new label\n");
    eol_component_label_free(component);
    return;
  }
  
  if ((fontName != NULL)&&(strlen(fontName) > 0))
  {
    label->font = eol_font_load(fontName,fontSize);
    r = eol_font_get_bounds_custom(text,label->font);
  }
  else
  {
    r = eol_font_get_bounds(text,fontSize);
  }
  component->bounds.w = r.w;
  component->bounds.h = r.h;
  label->justify = justify;
  label->fontSize = fontSize;
  label->alpha = alpha;
  label->wordWrap = wordWrap;
  eol_vec3d_copy(label->color,color);
  component->data_free = eol_component_label_free;
  component->data_draw = eol_component_label_draw;
}
コード例 #5
0
ファイル: eol_component.c プロジェクト: RabTom/EngineOfLies
void eol_component_button_draw(eolComponent *component,eolRect bounds)
{
  eolRect r;
  eolComponentButton *button = NULL;
  eolSprite *img = NULL;
  eolInt x,y;
  button = eol_component_get_button_data(component);
  x = bounds.x;
  y = bounds.y;
  if (button == NULL)return;
  if ((component->state >= 0) &&
    (component->state < eolButtonStateMax))
  {
    img = button->button[component->state];

    if (img != NULL)
    {
      r = eol_font_get_bounds(
        button->buttonText,
        button->fontSize
      );
      eol_sprite_draw(img,
                      0,
                      bounds.x,
                      bounds.y);
      x = bounds.x + (img->frameWidth/2);
      y = bounds.y + (img->frameHeight/2) - (r.h*0.7);
    }
    eol_font_draw_text_justify(
      button->buttonText,
      x,
      y,
      _eol_component_button_color[component->state],
      button->alpha,
      button->fontSize,
      button->justify
    );
  }
}
コード例 #6
0
ファイル: eol_dialog.c プロジェクト: j-schoch/EngineOfLies
void eol_dialog_text_block(eolLine title,
                           eolText text,
                           eolWord okText,
                           void    *data,
                           eolWindowCallback onOK)
{
  eolRect trect;  /*title dimensions*/
  eolRect brect;
  eolUint ww,wh;  /*window dimensions*/
  eolUint bw,bh;  /*button dimensions*/
  eolFloat bx,by;
  eolUint sw,sh;  /*screen dimensions*/
  eolWindow *win = eol_window_new();
  eolComponent *comp = NULL;
  if (!win)
  {
    eol_logger_message(
      EOL_LOG_ERROR,
      "eol_dialog:failed to make text block dialog.");
    return;
  }
  strncpy(win->name,"text_block",EOLLINELEN);

  eol_graphics_get_size(&sw, &sh);
  eol_button_get_stock_size(&bw, &bh);
  trect = eol_font_get_bounds(title,4);
  brect = eol_font_get_block_bounds(
    text,
    3,
    480,
    0
  );

  ww = MAX(trect.w + 10, brect.w + 8);
  wh = trect.h + brect.h + bh + 22;

  eol_rect_copy(&win->rect,eol_rect((sw/2) - (ww/2),(sh/2) - (wh/2),ww,wh));
  win->canHasFocus = eolTrue;
  win->drawGeneric = eolTrue;
  win->update = eol_dialog_text_block_update;

  by = eol_window_get_relative_position(2,win->rect.h);
  comp = eol_label_new(
    0,
    "text_title",
    eol_rectf(0.5,by,1,1),
    win->rect,
    eolTrue,
    title,
    eolJustifyCenter,
    eolFalse,
    4,
    NULL,
    eol_vec3d(1,1,1),
    1);
  eol_window_add_component(win,comp);

  
  bx = eol_window_get_relative_position(brect.w,win->rect.w);
  by = eol_window_get_relative_position(4 +trect.h,win->rect.h);
  comp = eol_label_new(
    1,
    "text_block",
    eol_rectf(0.5-(bx/2),by,1,1),
    win->rect,
    eolTrue,
    text,
    eolJustifyLeft,
    eolTrue,
    3,
    NULL,
    eol_vec3d(1,1,1),
    1);
  eol_window_add_component(win,comp);

  bx = eol_window_get_relative_position(win->rect.w - bw,win->rect.w);
  by = eol_window_get_relative_position(win->rect.h - bh,win->rect.h);
  comp = eol_button_stock_new(2,
                              "ok_button",
                              eol_rectf(bx,by,1,1),
                              win->rect,
                              okText,
                              -1,
                              SDLK_RETURN,
                              0,
                              eolFalse);
  eol_window_add_component(win,comp);

  win->customData = data;

  if (onOK != NULL)
  {
    eol_window_allocat_callbacks(win,1);
    if ((win->callbacks != NULL) && (win->callbackCount == 1))
    {
      win->callbacks[0] = onOK;
    }
  }
}
コード例 #7
0
ファイル: eol_dialog.c プロジェクト: j-schoch/EngineOfLies
eolWindow *eol_dialog_text_prompt(char *output,
                                  eolUint bufferSize,
                                  eolUint lineWidth,  /*0 means no limit*/
                                  eolLine question,
                                  void * customData,
                                  eolWindowCallback onOk,
                                  eolWindowCallback onCancel)
{
  eolRect trect;  /*text dimensions*/
  eolRect brect;  /*buffer dimentions*/
  eolUint ww,wh;  /*window dimensions*/
  eolUint bw,bh;  /*button dimensions*/
  eolUint sw,sh;  /*screen dimensions*/
  eolBool wordWrap = eolFalse;
  eolEntryData *entryData;
  eolWindow *win = eol_window_new();
  eolComponent *comp = NULL;
  if (!output)
  {
    eol_logger_message(
      EOL_LOG_ERROR,
      "eol_dialog_text_prompt:no out parameter provided.");
    return NULL;
  }
  if (!win)
  {
    eol_logger_message(
      EOL_LOG_ERROR,
      "eol_dialog_text_prompt:failed to make test prompt dialog.");
    return NULL;
  }

  win->customData = malloc(sizeof(eolEntryData));
  if (!win->customData)
  {
    eol_logger_message(
      EOL_LOG_ERROR,
      "eol_dialog_text_prompt:failed to allocate window data");
    eol_window_free(&win);
    return NULL;
  }
  memset(win->customData,0,sizeof(eolEntryData));
  entryData = (eolEntryData*)win->customData;
  entryData->customData = customData;
  entryData->output = output;
  
  wordWrap = eolFalse;
  
  strncpy(win->name,"gettext",EOLLINELEN);
  eol_graphics_get_size(&sw, &sh);
  eol_button_get_stock_size(&bw, &bh);
  trect = eol_font_get_bounds(question,3);
  brect = eol_font_get_bounds("W",3);
  brect.w *= bufferSize;
  if (MAX(trect.w,brect.w) > ((bw*2) + 6))
  {
    ww = MAX(trect.w,brect.w) + 10;
  }
  else
  {
    ww = (bw*2) + 16;
  }
  if (ww > sw - 20)ww = sw - 20;
  wh = trect.h + brect.h + bh + 30;
  eol_rect_copy(&win->rect,eol_rect((sw/2) - (ww/2),(sh/2) - (wh/2),ww,wh));
  win->canHasFocus = eolTrue;
  win->drawGeneric = eolTrue;
  win->update = eol_dialog_text_prompt_update;
  win->custom_delete = eol_dialog_text_prompt_delete;
  
  comp = eol_label_new(0,"text_prompt_title",eol_rectf(0.5,0.1,1,1),win->rect,eolTrue,
                       question,eolJustifyCenter,eolFalse,3,NULL,eol_vec3d(1,1,1),1);
  eol_window_add_component(win,comp);
  
  comp = eol_button_stock_new(1,
                              "ok_button",
                              eol_rectf(0.25,0.7,1,1),
                              win->rect,
                              "OK",
                              -1,
                              SDLK_RETURN,
                              0,
                              eolTrue);
  eol_window_add_component(win,comp);
  
  comp = eol_button_stock_new(2,
                              "cancel_button",
                              eol_rectf(0.75,0.7,1,1),
                              win->rect,
                              "CANCEL",
                              -1,
                              SDLK_ESCAPE,
                              0,
                              eolTrue);
  eol_window_add_component(win,comp);
  
  comp = eol_entry_new(3,
                       "text_entry",
                       eol_rectf(0.025,0.25,0.95,0.25),
                       win->rect,
                       output,
                       bufferSize,
                       eolJustifyLeft,
                       wordWrap,
                       3,
                       "",
                       eolFalse,
                       eol_vec3d(1,1,1),
                       1,
                       eol_vec3d(0.2,0.2,0.2));
  comp->hasFocus = eolTrue;
  comp->canHasFocus = eolTrue;
  eol_window_add_component(win,comp);

  eol_window_allocat_callbacks(win,2);
  if ((win->callbacks != NULL) && (win->callbackCount == 2))
  {
    win->callbacks[0] = onOk;
    win->callbacks[1] = onCancel;
  }
  return win;
}
コード例 #8
0
ファイル: eol_dialog.c プロジェクト: j-schoch/EngineOfLies
void eol_dialog_yes_no(eolLine question,
                       void * customData,
                       eolWindowCallback onYes,
                       eolWindowCallback onNo)
{
  eolRect trect;  /*text dimensions*/
  eolUint ww,wh;  /*window dimensions*/
  eolUint bw,bh;  /*button dimensions*/
  eolUint sw,sh;  /*screen dimensions*/
  eolWindow *win = eol_window_new();
  eolComponent *comp = NULL;
  if (!win)
  {
    eol_logger_message(
      EOL_LOG_ERROR,
      "eol_dialog:failed to make yes/no dialog.");
    return;
  }
  strncpy(win->name,"yesno",EOLLINELEN);
  eol_graphics_get_size(&sw, &sh);
  eol_button_get_stock_size(&bw, &bh);
  trect = eol_font_get_bounds(question,3);
  if (trect.w > ((bw*2) + 6))
  {
    ww = trect.w + 10;
  }
  else
  {
    ww = (bw*2) + 16;
  }
  wh = trect.h + bh + 16;
  eol_rect_copy(&win->rect,eol_rect((sw/2) - (ww/2),(sh/2) - (wh/2),ww,wh));
  win->canHasFocus = eolTrue;
  win->drawGeneric = eolTrue;
  win->update = eol_dialog_yes_no_update;
  comp = eol_label_new(0,"yes_title",eol_rectf(0.5,0.1,1,1),win->rect,eolTrue,
                       question,eolJustifyCenter,eolFalse,3,NULL,eol_vec3d(1,1,1),1);
  eol_window_add_component(win,comp);
  comp = eol_button_stock_new(1,
                              "yes_button",
                              eol_rectf(0.25,0.65,1,1),
                              win->rect,
                              "YES",
                              -1,
                              SDLK_y,
                              0,
                              eolTrue);
  eol_window_add_component(win,comp);
  comp = eol_button_stock_new(2,
                              "no_button",
                              eol_rectf(0.75,0.65,1,1),
                              win->rect,
                              "NO",
                              -1,
                              SDLK_n,
                              0,
                              eolTrue);
  eol_window_add_component(win,comp);
  win->customData = customData;
  eol_window_allocat_callbacks(win,2);
  if ((win->callbacks != NULL) && (win->callbackCount == 2))
  {
    win->callbacks[0] = onYes;
    win->callbacks[1] = onNo;
  }
}