Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin_dc - Unable to draw rotated text #15

Open
oplaydo opened this issue May 6, 2024 · 7 comments
Open

plugin_dc - Unable to draw rotated text #15

oplaydo opened this issue May 6, 2024 · 7 comments

Comments

@oplaydo
Copy link

oplaydo commented May 6, 2024

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
Copy link
Collaborator

leamas commented May 6, 2024

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-charts_pi-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 added a commit to Rasbats/opencpn-libs that referenced this issue May 17, 2024
This does not work for OpenGL.
OpenCPN#15 refers
@Rasbats
Copy link
Contributor

Rasbats commented May 17, 2024

Need help with the OpenGL.
#ifdef ocpnUSE_GL as in DrawText()

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

rotate text

@leamas
Copy link
Collaborator

leamas commented May 17, 2024

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 plugin_dc. 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
Copy link
Collaborator

leamas commented May 17, 2024

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
Copy link
Collaborator

leamas commented May 17, 2024

BTW: Looking at leamas/opencpn-libs@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
Copy link
Contributor

Rasbats commented May 17, 2024

@nohal Thoughts please when time allows.

@Rasbats
Copy link
Contributor

Rasbats commented May 21, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants