libui/common/drawtext.c

51 lines
1.2 KiB
C
Raw Normal View History

// 10 february 2017
#include "../ui.h"
#include "uipriv.h"
void uiDrawCaret(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout, size_t pos, int *line)
{
double xoff;
uiDrawTextLayoutLineMetrics m;
struct caretDrawParams cdp;
uiDrawPath *path;
uiDrawBrush brush;
2017-02-10 18:29:07 -06:00
if (*line < 0)
*line = 0;
if (*line > (uiDrawTextLayoutNumLines(layout) - 1))
*line = (uiDrawTextLayoutNumLines(layout) - 1);
// TODO cap pos
xoff = uiDrawTextLayoutByteLocationInLine(layout, pos, *line);
2017-02-10 18:29:07 -06:00
while (xoff < 0) {
size_t start, end;
2017-02-10 18:29:07 -06:00
uiDrawTextLayoutLineByteRange(layout, *line, &start, &end);
if (end < pos) // too far up
(*line)++;
else
(*line)--;
xoff = uiDrawTextLayoutByteLocationInLine(layout, pos, *line);
}
uiDrawTextLayoutLineGetMetrics(layout, *line, &m);
2017-02-10 15:53:08 -06:00
caretDrawParams(c, m.Height, &cdp);
uiDrawSave(c);
path = uiDrawNewPath(uiDrawFillModeWinding);
uiDrawPathAddRectangle(path,
// TODO add m.X?
2017-02-10 15:53:08 -06:00
x + xoff - cdp.xoff, y + m.Y,
cdp.width, m.Height);
uiDrawPathEnd(path);
brush.Type = uiDrawBrushTypeSolid;
brush.R = cdp.r;
brush.G = cdp.g;
brush.B = cdp.b;
brush.A = cdp.a;
uiDrawFill(c, path, &brush);
uiDrawFreePath(path);
uiDrawRestore(c);
}