FLTK logo

[master] 32f926c - Remove use of static global var gl_fontsize inside virtual member Fl_Gl_Window_Driver::alpha_mask_for_string()

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 32f926c - Remove use of static global var gl_fontsize inside virtual member Fl_Gl_Window_Driver::alpha_mask_for_string() "ManoloFLTK" Feb 19, 2021  
 
commit 32f926c360ffad8071cf3a7866907ec2a8153771
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Fri Feb 19 15:03:21 2021 +0100
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Fri Feb 19 15:03:32 2021 +0100

    Remove use of static global var gl_fontsize inside virtual member Fl_Gl_Window_Driver::alpha_mask_for_string()

 src/Fl_Gl_Window_Driver.H                       |  3 ++-
 src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx | 13 +++++++++----
 src/gl_draw.cxx                                 | 10 +++++++---
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git src/Fl_Gl_Window_Driver.H src/Fl_Gl_Window_Driver.H
index ddc52c7..10cd3f1 100644
--- src/Fl_Gl_Window_Driver.H
+++ src/Fl_Gl_Window_Driver.H
@@ -96,7 +96,8 @@ public:
   virtual int overlay_color(Fl_Color i) {return 0;} // support for gl_color() with HAVE_GL_OVERLAY
   static void draw_string_with_texture(const char* str, int n); // cross-platform
   // support for gl_draw(). The cross-platform version may be enough.
-  virtual char *alpha_mask_for_string(const char *str, int n, int w, int h);
+  virtual char *alpha_mask_for_string(const char *str, int n, int w, int h, Fl_Fontsize fs);
+  virtual Fl_Fontsize effective_size();
   virtual int genlistsize() { return 0; } // support for gl_draw()
   virtual Fl_Font_Descriptor** fontnum_to_fontdescriptor(int fnum);
   virtual Fl_RGB_Image* capture_gl_rectangle(int x, int y, int w, int h);
diff --git src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx
index a9df988..84541e0 100644
--- src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx
+++ src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx
@@ -53,7 +53,8 @@ class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver {
   virtual void make_overlay_current();
   virtual void redraw_overlay();
   virtual void gl_start();
-  virtual char *alpha_mask_for_string(const char *str, int n, int w, int h);
+  virtual Fl_Fontsize effective_size();
+  virtual char *alpha_mask_for_string(const char *str, int n, int w, int h, Fl_Fontsize fs);
   virtual Fl_RGB_Image* capture_gl_rectangle(int x, int y, int w, int h);
 };
 
@@ -219,14 +220,18 @@ void Fl_Cocoa_Gl_Window_Driver::resize(int is_a_resize, int w, int h) {
 /* Some old Apple hardware doesn't implement the GL_EXT_texture_rectangle extension.
  For it, draw_string_legacy_glut() is used to draw text. */
 
-char *Fl_Cocoa_Gl_Window_Driver::alpha_mask_for_string(const char *str, int n, int w, int h)
+Fl_Fontsize Fl_Cocoa_Gl_Window_Driver::effective_size() {
+  return (Fl_Fontsize)round(fl_graphics_driver->size() * gl_scale);
+}
+
+char *Fl_Cocoa_Gl_Window_Driver::alpha_mask_for_string(const char *str, int n, int w, int h, Fl_Fontsize fs)
 {
   // write str to a bitmap just big enough
   Fl_Image_Surface *surf = new Fl_Image_Surface(w, h);
-  Fl_Font f=fl_font(); Fl_Fontsize s=fl_size();
+  Fl_Font f=fl_font();
   Fl_Surface_Device::push_current(surf);
   fl_color(FL_WHITE);
-  fl_font(f, s * gl_scale);
+  fl_font(f, fs);
   fl_draw(str, n, 0, fl_height() - fl_descent());
   // get the alpha channel only of the bitmap
   char *alpha_buf = new char[w*h], *r = alpha_buf, *q;
diff --git src/gl_draw.cxx src/gl_draw.cxx
index 234edf2..043d1c1 100644
--- src/gl_draw.cxx
+++ src/gl_draw.cxx
@@ -412,7 +412,8 @@ int gl_texture_fifo::compute_texture(const char* str, int n)
 
   fifo[current].scale = Fl_Gl_Window_Driver::gl_scale;
   fifo[current].fdesc = gl_fontsize;
-  char *alpha_buf = Fl_Gl_Window_Driver::global()->alpha_mask_for_string(str, n, w, h);
+  Fl_Fontsize fs = Fl_Gl_Window_Driver::global()->effective_size();
+  char *alpha_buf = Fl_Gl_Window_Driver::global()->alpha_mask_for_string(str, n, w, h, fs);
 
   // save GL parameters GL_UNPACK_ROW_LENGTH and GL_UNPACK_ALIGNMENT
   GLint row_length, alignment;
@@ -496,8 +497,11 @@ void Fl_Gl_Window_Driver::draw_string_with_texture(const char* str, int n)
   gl_fifo->display_texture(index);
 }
 
+Fl_Fontsize Fl_Gl_Window_Driver::effective_size() {
+  return fl_graphics_driver->font_descriptor()->size;
+}
 
-char *Fl_Gl_Window_Driver::alpha_mask_for_string(const char *str, int n, int w, int h)
+char *Fl_Gl_Window_Driver::alpha_mask_for_string(const char *str, int n, int w, int h, Fl_Fontsize fs)
 {
   // write str to a bitmap that is just big enough
   // create an Fl_Image_Surface object
@@ -511,7 +515,7 @@ char *Fl_Gl_Window_Driver::alpha_mask_for_string(const char *str, int n, int w,
   // set up the text colour as white, which we will interpret as opaque
   fl_color(255,255,255);
   // Fix the font scaling
-  fl_font (fnt, gl_fontsize->size); // resize "fltk" font to current GL view scaling
+  fl_font (fnt, fs); // resize "fltk" font to current GL view scaling
   int desc = fl_descent();
   // Render the text to the buffer
   fl_draw(str, n, 0, h - desc);
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.