ericoporto / ImGi

AGS Script Module for Immediate Gui (based on rxi's Microui)
https://www.adventuregamestudio.co.uk/forums/index.php?topic=58842.0
Other
2 stars 2 forks source link

Improve Button performance #18

Closed ericoporto closed 3 years ago

ericoporto commented 3 years ago
ImGi_Res ImGi_Context::Button(String label, ImGi_Icon icon, ImGi_Opt opt)
{
  ImGi_Res res = eImGi_Res_None;
  ImGi_ID id;
  if(String.IsNullOrEmpty(label)) {
    id = this.GetID(String.Format("%d", icon));
  }
  else
  {
    id = this.GetID(label);
  }
  Rect* r = this.layout_next();
  this.update_control(id, r, opt);
  /* handle click */
  if(this.mouse_pressed == eImGi_Mouse_Left && this.focus == id)
  {
    res |= eImGi_Res_Submit;
  }
  /* draw */
  this.draw_control_frame(id, r, eImGi_Col_Button, opt);
  if(!String.IsNullOrEmpty(label)) this.draw_control_text(label, r, eImGi_Col_Text, opt);
  if(icon) this.draw_icon(icon, r, this.style.colors[eImGi_Col_Text]);
  return res;
}

The button source code is not slow, but could be faster, we want to be able to handle hundreds of buttons. For now around 40 may already slow down things.

ericoporto commented 3 years ago

Apparently the most expensive part is the draw_control_frame which spawns 5 rectangles :/

ericoporto commented 3 years ago

If the size of the button is small enough - say, width smaller than 50px, it may be best to draw two rectangles, one for the border+inner with border color, and then one for the inner part on top, instead of drawing 1 for each line and then the insides.