BUG REPORT: Improper display of the same color between different objects

 

Video demonstration: https://i.imgur.com/ee1JSo8.gif

Issue: the color C'34,34,34' (and similar dark colors within that range) display differently on OBJ_BUTTON compared to other object types.

In the video, the OBJ_EDIT is also using C'34,34,34' as the background color that the OBJ_BUTTON uses in the on state. However, they don't look the same.

I left a note in the code below stating that, if you comment out the line that changes the color in the off state, the color displays properly, but not in the correct state.

Code below to test for yourself.

#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
  createButton();
  createEdit();

  return(INIT_SUCCEEDED);
}

void createButton() {
  string name = "TEST BUTTON";
  color clr   = clrWhite;
  color bgClr = clrBlack;
  int x       = 100;
  int y       = 5;
  int width   = 200;
  int height  = 100;
  
  bool wasCreated = ObjectCreate(0, name, OBJ_BUTTON, 0, 0, 0);
  
  if (wasCreated) {
    ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
    ObjectSetInteger(0, name, OBJPROP_BGCOLOR, bgClr);
    ObjectSetInteger(0, name, OBJPROP_XSIZE, width);
    ObjectSetInteger(0, name, OBJPROP_YSIZE, height);
    ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
    ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);    
  }
}

void createEdit() {
  string name = "TEST EDIT";
  color clr   = clrWhite;
  color bgClr = C'34,34,34';
  int x       = 100;
  int y       = 100 + 5 + 5;
  int width   = 200;
  int height  = 100;
  
  bool wasCreated = ObjectCreate(0, name, OBJ_EDIT, 0, 0, 0);
  
  if (wasCreated) {
    ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
    ObjectSetInteger(0, name, OBJPROP_BGCOLOR, bgClr);
    ObjectSetInteger(0, name, OBJPROP_XSIZE, width);
    ObjectSetInteger(0, name, OBJPROP_YSIZE, height);
    ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
    ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y); 
  }
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) {
  return(rates_total);
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
  switch (id) {
    case CHARTEVENT_OBJECT_CLICK: {
      bool isButton = sparam == "TEST BUTTON";
      
      if (isButton) {
        bool isState  = ObjectGetInteger(0, sparam, OBJPROP_STATE);
        
        if (isState) {
          color bgClr = C'34,34,34';
          string message = StringConcatenate("State: ", isState, "\n", "Color: ", bgClr);
          
          Comment(message);
          
          ObjectSetInteger(0, sparam, OBJPROP_BGCOLOR, bgClr);
        } else {
          color bgClr = clrBlack;
          string message = StringConcatenate("State: ", isState, "\n", "Color: ", bgClr);
          
          Comment(message);
          //--- NOTE: If you comment out this line, the color displays properly, but only when
          //--- the button state is false, rather than true (when the color is supposed to be applied)
          ObjectSetInteger(0, sparam, OBJPROP_BGCOLOR, bgClr);
        }
      }
      break;
    }
  }
}