diff options
Diffstat (limited to 'src/glibext/gbuffersegment.c')
-rw-r--r-- | src/glibext/gbuffersegment.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/glibext/gbuffersegment.c b/src/glibext/gbuffersegment.c index 861c7cb..031075c 100644 --- a/src/glibext/gbuffersegment.c +++ b/src/glibext/gbuffersegment.c @@ -478,6 +478,57 @@ gint g_buffer_segment_get_width(const GBufferSegment *segment) /****************************************************************************** * * +* Paramètres : segment = fragment de texte à consulter. * +* x = position horizontale au niveau du segment. * +* * +* Description : Fournit la position idéale pour un marqueur. * +* * +* Retour : Position dans le segment donné. * +* * +* Remarques : - * +* * +******************************************************************************/ + +gint g_buffer_segment_get_caret_position(const GBufferSegment *segment, gint x) +{ + gint result; /* Position à retourner */ + gint width; /* Largeur du segment */ + gint char_width; /* Largeur de police fixe */ + + width = g_buffer_segment_get_width(segment); + + printf("(seg) x=%d width=%d\n", x, width); + + if (x <= 0) + result = 0; + + else if (x >= width) + result = width; + + else + { + if (strlen(segment->text) != segment->glyphs->num_glyphs) + { + + printf("STOP ::: %d vs %d\n", strlen(segment->text), segment->glyphs->num_glyphs); + exit(0); + } + + char_width = width / segment->glyphs->num_glyphs; + + result = (x / char_width) * char_width; + if ((x % char_width) > (char_width / 2)) + result += char_width; + + } + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : segment = fragment de texte à manipuler. * * * * Description : (Re)charge les couleurs à partir de la liste d'attributs. * |