OpenCPN / opencpn-libs

Common libraries submodule, primarily for use in plugins
1 stars 5 forks source link

plugin_dc - Unable to draw rotated text #15

Open oplaydo opened 6 months ago

oplaydo commented 6 months ago

dc.h has DrawRotatedText ... but this is not available from plugin_dc.

Rotated text is needed for a Finnish SAR project under review. The text is applied to route direction arrows:

pi_dc

leamas commented 6 months ago

hm... I'm on very,very thin ice here. Please bear with me.

As I understand it you should be able to construct and use a local wxPaintDC object which supports DrawRotadedText. This is about handling EVT_PAINT.

There is some example code in o-charts_pi. If you look into _src/o-chartspi-cpp there is first an event binding:

BEGIN_EVENT_TABLE(InfoWin, wxWindow)
EVT_PAINT ( InfoWin::OnPaint )
[...]
END_EVENT_TABLE()

and the OnPaint definition:

void InfoWin::OnPaint( wxPaintEvent& event )
{
    int width, height;
    GetClientSize( &width, &height );
    wxPaintDC dc( this );

    wxColour c;

    GetGlobalColor( _T ( "UIBCK" ), &c );
    dc.SetBrush( wxBrush( c ) );

    GetGlobalColor( _T ( "UITX1" ), &c );
    dc.SetPen( wxPen( c ) );

    dc.DrawRectangle( 0, 0, width-1, height-1 );
}

Using something like this could perhaps work? (I would certainly use Bind() instead of the EVENT_TABLE, but that's a nit-pick.)

Rasbats commented 6 months ago

Need help with the OpenGL.

ifdef ocpnUSE_GL as in DrawText()

This is non-OpenGL (Sorry about the reverse route):

rotate text

leamas commented 6 months ago

hm... A bit hard to read your diff. Next time, please first run clang-format and commit those changes before going forward with actual changes. Mixing formatting and "real" changes in a single commit makes for hard to read patches.

I'm very, very unsure about the things in plugin_dc, and we might need to involve Dave before final conclusions. That said, my example above was not an idea how to add AddRotadedText() to _plugindc. The idea is rather to override OnPaint() in a very limited object, in this case whatever widget which draws the route direction arrows similar to the example InfoWin.

That is, IIUC we cannot really do this within the overall dc context since that would mean overriding OnPaint() for the complete dc. And that is something we definitely don't want to do.

Which then would boil down to that this is application code rather than things added to opencpn-libs.

EDIT: typos

leamas commented 6 months ago

Created a new branch https://github.com/leamas/opencpn-libs/commits/mike/main/ which is the result of splitting your single commit into two, one for formatting and one for the "real" changes". The net result is the same as here, but far easier to read. Please use this instead if we should continue to work with these changes, but see above

leamas commented 6 months ago

BTW: Looking at https://github.com/leamas/opencpn-libs/commit/c4d922acbd2:

diff --git a/plugin_dc/dc_utils/src/pidc.cpp b/plugin_dc/dc_utils/src/pidc.cpp
index f79d3e3..8553163 100644
--- a/plugin_dc/dc_utils/src/pidc.cpp
+++ b/plugin_dc/dc_utils/src/pidc.cpp
@@ -206,15 +206,12 @@ void piDC::Init() {

   g_textureId = -1;
   m_tobj = NULL;
-#ifdef ocpnUSE_GL
-  if (glcanvas) {
-    GLint parms[2];
-    glGetIntegerv(GL_SMOOTH_LINE_WIDTH_RANGE, &parms[0]);
-    GLMinSymbolLineWidth = wxMax(parms[0], 1);

-    pi_loadShaders();
-  }
-#endif
+  GLint parms[2];
+  glGetIntegerv(GL_SMOOTH_LINE_WIDTH_RANGE, &parms[0]);
+  GLMinSymbolLineWidth = wxMax(parms[0], 1);
+
+  pi_loadShaders();
 }

This will definitely not fly. It means referencing GLint, glGetIntegerv, GLMinSymbolLineWidth etc. even if ocpnUSE_GL is not defined. A sure compilation error.

Why are these changes done?

Rasbats commented 6 months ago

@nohal Thoughts please when time allows.

Rasbats commented 5 months ago

Closed my PR for the Windows fix. Now using a duplicate of _plugindc in a private libs folder. It would be good to get this working for openGL.