Existe-t-il une classe textarea standard utilisant Cario (ciblant OpenGL) comme moteur de rendu? Par textarea, je veux dire un champ de texte multiligne avec des contraintes de largeur de wordwrap et de largeur et de hauteur. Le code qui doit utiliser cette classe est écrit en C++.Textarea for Cario: OpenGL
1
A
Répondre
1
Une solution consiste à utiliser les fixations cairo pango. L'utiliser pourrait devenir très déroutant très rapidement, alors voici un essentiel. Vous pouvez créer une classe autour de C++ si vous le souhaitez.
#include <pango/pangocairo.h>
// Pango context
PangoContext* pangoContext = pango_font_map_create_context(
pango_cairo_font_map_get_default());
// Layout and attributes
PangoLayout* pangoLayout = pango_layout_new(pangoContext);
pango_layout_set_wrap(pangoLayout, PANGO_WRAP_WORD_CHAR);
pango_layout_set_width(pangoLayout, maxWidth * PANGO_SCALE);
pango_layout_set_height(pangoLayout, maxHeight * PANGO_SCALE);
// Set font
PangoFontDescription* fontDesc =
pango_font_description_from_string("Verdana 10");
pango_layout_set_font_description(pangoLayout, fontDesc);
pango_font_description_free(fontDesc);
// Set text to render
pango_layout_set_text(pangoLayout, text.data(), text.length());
// Allocate buffer
const cairo_format_t format = CAIRO_FORMAT_A8;
const int stride = cairo_format_stride_for_width(format, maxWidth);
GLubyte* buffer = new GLubyte[stride * maxHeight];
std::fill(buffer, buffer + stride * maxHeight, 0);
// Create cairo surface for buffer
cairo_surface_t* crSurface = cairo_image_surface_create_for_data(
buffer, format, maxWidth, maxHeight, stride);
if (cairo_surface_status(crSurface) != CAIRO_STATUS_SUCCESS) {
// Error
}
// Create cairo context
cairo_t* crContext = cairo_create(crSurface);
if (cairo_status(crContext) != CAIRO_STATUS_SUCCESS) {
// Error
}
// Draw
cairo_set_source_rgb(crContext, 1.0, 1.0, 1.0);
pango_cairo_show_layout(crContext, pangoLayout);
// Cleanup
cairo_destroy(crContext);
cairo_surface_destroy(crSurface);
g_object_unref(pangoLayout);
g_object_unref(pangoContext);
// TODO: you can do whatever you want with buffer now
// copy on the texture maybe?
delete[] buffer;
Dans ce cas, le tampon contiendra uniquement des valeurs de canal alpha de 8 bits. Fiddle avec la variable de format si vous voulez quelque chose d'autre. Compiler ... pkg-config --cflags --libs pangocairo
devrait le faire sur Linux. Je n'ai aucune idée de Windows.
Questions connexes
- 1. OpenGL à OpenGL-ES - glBegin();
- 2. MVC Ajax TextArea tiny_mce_src.js
- 3. comment créer quelque chose comme l'application For All Seasons dans opengl?
- 4. Format <textarea>
- 5. textarea dans un tableau javascript
- 6. textarea, tinyMCE et insérer une image dans textarea
- 7. Raccourci dans textarea
- 8. Textarea css non cliquable
- 9. ASP.NET MVC - Valeurs TextArea
- 10. Agrandir textarea onClick
- 11. Textarea aux paragraphes
- 12. textarea à la liste
- 13. Code Textarea en Javascript
- 14. Html Textarea Placeholder
- 15. Textarea $ .post as undefined
- 16. Textarea maximum en octets
- 17. jquery et textarea
- 18. jquery préfixe textarea text()
- 19. Validation de textarea cachée
- 20. jQuery this() pour textarea?
- 21. Validation des textarea
- 22. Javascript handling textarea
- 23. texte d'entrée/textarea taille
- 24. Autoriser HTML dans TextArea
- 25. textarea et javascript
- 26. ExtJs textarea multiline
- 27. validation jQuery sur textarea
- 28. Comment rendre textarea modifiable?
- 29. javascript textarea scrollTop
- 30. Textarea: elem.val() vs elem.text()