arduino-libraries/ArduinoGraphics

Separate color from position in beginText/endText

sandeepmistry opened this issue · 5 comments

From @tigoe.

We need a setTextColor(r, g, b) API.

Could you please explain what kind of API you are talking about?
Do you need to setup a web server to do this?
Also please elaborate on the setTextColor(r, g, b) function please.

explain what kind of API you are talking about?

The API of this library:
https://github.com/arduino-libraries/ArduinoGraphics/blob/master/src/ArduinoGraphics.h#L38-L89

The proposal is to add a new function to the library named setTextColor.

Do you need to setup a web server to do this?

No. See the Arduino_MKRRGB library for an example of how the ArduinoGraphics library is used:
https://github.com/arduino-libraries/Arduino_MKRRGB

elaborate on the setTextColor(r, g, b) function

Currently, the library uses the color set by stroke() for the text color. Apparently, the proposal is to add an equivalent function that is specifically for setting the text color.

The text function doesn't actually contain any code to set the color. That is done in the bitmap function. We wouldn't want to always use the text color in the bitmap function, so you would need to do something like this at the start of the text function:

// save the stroke color
strokeR = _strokeR;
strokeG = _strokeG;
strokeB = _strokeB;

// set the stroke color to the text color
_strokeR = _textR;
_strokeG = _textG;
_strokeB = _textB;

Then something like this at the end:

// reset the stroke color
_strokeR = strokeR;
_strokeG = strokeG;
_strokeB = strokeB;

It's not at all clear to me why we need this function. If we're going to do that, we might as well add setPointColor, setLineColor, and setRectColor functions as well.

Perhaps @tigoe could verify if I explained the proposal correctly and explain the reasoning for adding this function.

I see now that beginText has color parameters. Since we already have established that there is a special text color setting, that topic is decided and there's no point in discussing whether that makes sense. I see that endText() already has the equivalent of the code I described in my previous reply. So it's a matter of moving that code to the text function so that setTextColor() will apply to text as well as endText().

@per1234 , thanks for verifying the problem, I made this pull request #15 , where I attempted to make text color completely independent of stroke color. I think that this is a more efficient way to go about this issue since stroke is used for geometric shapes and text color can be used for the text. I also made a clone bitmap function using the text color because I was not sure where else the bitmap function was being used, since other libraries depend on this one.