How to use createDashedStroke

Home Forums General Programming How to use createDashedStroke

Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • #27051
    dasfaker
    Keymaster
      • Topics: 80
      • Replies: 793
      • Total: 873
      • ★★★

      Hi

      I’m trying to create a dashed path, but I don’t know how to use it, I’ve tried several ways but all fail.

      This is what I have:

      pathRing3 = Path()
      strokeRing3 = PathStrokeType(2, PathStrokeType.square, PathStrokeType.square)
      transformRing3 = AffineTransform()

      This is the function I’m trying to use:

      void createDashedStroke(PathStrokeType const&,Path&,Path const&,custom [float] const*,int,AffineTransform const&,custom [float])

      #27054
      atom
      Keymaster
        • Topics: 159
        • Replies: 2945
        • Total: 3104
        • ★★★★★

        This seems impossible at the moment, i have no idea how to pass a const float * type in Lua, i’ll write a wrapper to simplify this process asap and post an example. To draw a path that’s a line:

        drawPanel = function(canvas,g)
        	p = Path()
        	p:startNewSubPath (0.0, 0.0);
        	p:lineTo (100, 100);
        	
        	stroke = PathStrokeType (5.0, PathStrokeType.mitered, PathStrokeType.butt)
        	
        	trans = AffineTransform()
        	g:strokePath (p, stroke, trans)
        end
        #27055
        dasfaker
        Keymaster
          • Topics: 80
          • Replies: 793
          • Total: 873
          • ★★★

          Ok, thanks.

          #27056
          atom
          Keymaster
            • Topics: 159
            • Replies: 2945
            • Total: 3104
            • ★★★★★

            This should look something like that, it will be in the next build.

            Attachments:
            You must be logged in to view attached files.
            #27058
            dasfaker
            Keymaster
              • Topics: 80
              • Replies: 793
              • Total: 873
              • ★★★

              Yeah, that’s cool. Thx!

              #27155
              dasfaker
              Keymaster
                • Topics: 80
                • Replies: 793
                • Total: 873
                • ★★★

                More graphics issues, it seems drawEllipse () function is not registered.

                #27156
                atom
                Keymaster
                  • Topics: 159
                  • Replies: 2945
                  • Total: 3104
                  • ★★★★★

                  yes i can see i removed it for some reason, i’ve put it back now.

                  #27193
                  atom
                  Keymaster
                    • Topics: 159
                    • Replies: 2945
                    • Total: 3104
                    • ★★★★★

                    Should be fixed in all builds now.

                    #27198
                    dasfaker
                    Keymaster
                      • Topics: 80
                      • Replies: 793
                      • Total: 873
                      • ★★★

                      Yep, all working good.

                      #27241
                      dasfaker
                      Keymaster
                        • Topics: 80
                        • Replies: 793
                        • Total: 873
                        • ★★★

                        Atom, I see there are built-in fonts in Ctrlr, but I don’t know how to access them in Lua, if I use this it doesn’t work.
                        font = Font("LCD",16,0)

                        #27243
                        atom
                        Keymaster
                          • Topics: 159
                          • Replies: 2945
                          • Total: 3104
                          • ★★★★★

                          Yeah i didn’t get the chance to add embedded fonts as resources to Lua, but you access them as resources, i’ll add the needed methods now and post builds today, you can use that like so (in any paint callback) assuming your font is a resource named “MyCustomFontName”

                          	f = resources:getResourceAsFont ("MyCustomFontName")
                          	g:setFont (f)
                          	j = Justification (Justification.centred)
                          	g:drawText ("Bleh Meh 0123", 0, 0, 100, 100, j, false)
                          #27245
                          dasfaker
                          Keymaster
                            • Topics: 80
                            • Replies: 793
                            • Total: 873
                            • ★★★

                            Cool, thanks

                            #27389
                            atom
                            Keymaster
                              • Topics: 159
                              • Replies: 2945
                              • Total: 3104
                              • ★★★★★

                              the fix is in.

                              #27410
                              dasfaker
                              Keymaster
                                • Topics: 80
                                • Replies: 793
                                • Total: 873
                                • ★★★

                                It works with fonts imported as resources, but not with embedded fonts inside Ctrlr, I don’t know how to import embedded fonts as a resource.

                                #27411
                                atom
                                Keymaster
                                  • Topics: 159
                                  • Replies: 2945
                                  • Total: 3104
                                  • ★★★★★

                                  It won’t work, those embedded fonts inside Ctrlr are in a special crappy format (old Font implementation), i hope to drop them soon. Use any TTF/OTF fonts instead and don’t base anything on those old fonts inside CTRLR.

                                  #27412
                                  dasfaker
                                  Keymaster
                                    • Topics: 80
                                    • Replies: 793
                                    • Total: 873
                                    • ★★★

                                    Ok, thanks

                                    #27413
                                    dasfaker
                                    Keymaster
                                      • Topics: 80
                                      • Replies: 793
                                      • Total: 873
                                      • ★★★

                                      I get an assertion failure when drawing text centred. Not too problematic as it works fine with horizontallyCentred:

                                      JUCE Assertion failure in contexts/juce_GraphicsContext.cpp:238

                                      g:drawSingleLineText(string.format(“%s”, “TEXT”), 10 , 10, Justification (Justification.centred))

                                      #27414
                                      atom
                                      Keymaster
                                        • Topics: 159
                                        • Replies: 2945
                                        • Total: 3104
                                        • ★★★★★

                                        That might be due to some OS specific stuff, i get that a lot, for example on Windows when using JUCE i can’t center vertically anything because i get assertion from JUCE, since i bound those JUCE methods directly you might be getting those too.

                                        #27415
                                        atom
                                        Keymaster
                                          • Topics: 159
                                          • Replies: 2945
                                          • Total: 3104
                                          • ★★★★★

                                          Here is the comment from Jules that’s inside the library code:

                                          //==============================================================================
                                          void Graphics::drawSingleLineText (const String& text, const int startX, const int baselineY,
                                                                             Justification justification) const
                                          {
                                              if (text.isNotEmpty())
                                              {
                                                  // Don't pass any vertical placement flags to this method - they'll be ignored.
                                                  jassert (justification.getOnlyVerticalFlags() == 0);
                                          
                                                  const int flags = justification.getOnlyHorizontalFlags();
                                        Viewing 19 posts - 1 through 19 (of 19 total)
                                        • The forum ‘Programming’ is closed to new topics and replies.
                                        There is currently 0 users and 61 guests online
                                        No users are currently active
                                        Forum Statistics
                                        Threads: 2,495, Posts: 17,374, Members: 77,605
                                        Most users ever online was 12 on January 22, 2019 3:47 pm
                                        Ctrlr