CCBlueX Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Solved How to draw a gradient rect

    ScriptAPI
    5
    11
    191
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • test test2
      test test2 last edited by

      How to draw a gradient rect?

      Gui.drawGradientRect is 'protected'

      F 1 Reply Last reply Reply Quote 0
      • F
        freerobuxgen2022 @test test2 last edited by freerobuxgen2022

        its protected i cant access it

        reflection

        1 Reply Last reply Reply Quote 0
        • test test2
          test test2 last edited by

                              try {
                                  var method = Gui.class.getDeclaredMethod("drawGradientRect");
                                  method.setAccessible(true);
                                  method.invoke(Gui.class, 10, 10, 10 + 50, 10 + 50, Color.RED.getRGB(), Color.BLUE.getRGB());
                              } catch (ex) {
                                  ex.printStackTrace();
                              }
          

          What's wrong here?

          Ali00035 CzechHek 2 Replies Last reply Reply Quote 0
          • Ali00035
            Ali00035 Banned @test test2 last edited by

            @test-test2 Does it work

            1 Reply Last reply Reply Quote 0
            • CzechHek
              CzechHek @test test2 last edited by CzechHek

              @test-test2 you invoke on instance and you have to put all args into an java array

              the easiest way would be to use Core's Reflector

              RGui = new Reflector(Gui) 
              
              onrender:
              
              RGui.drawGradientRect(10, 10, 10 + 50, 10 + 50, Color.RED.getRGB(), Color.BLUE.getRGB())
              

              also what about looking into logs or https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html

              1 Reply Last reply Reply Quote 0
              • test test2
                test test2 last edited by

                43839bce-eb6a-4978-ba3b-8a9abf949356-image.png
                onRender:
                9f359c9f-e142-49cd-88cb-1606eb8f5543-image.png

                Result:
                f1f8288a-0e63-4439-90a4-f281a3241e1a-image.png

                1 Reply Last reply Reply Quote 0
                • test test2
                  test test2 last edited by

                  oh, how to include Core library?

                  1 Reply Last reply Reply Quote 0
                  • test test2
                    test test2 last edited by test test2

                    6ed25847-0834-41a0-8d26-37086477c011-image.png

                    68088ebc-3425-4c3a-839c-d4e9600681cd-image.png

                    00b5f95f-3034-4f24-b861-2acac9540993-image.png

                    fa95c5f2-bc17-4150-ad14-9fc19ce5016d-image.png

                    render2d:
                    7bed28e2-6388-4476-9403-21ecca44d180-image.png
                    ee626b1d-4312-489c-a8cb-3a545abdc5cc-image.png

                    CzechHek 1 Reply Last reply Reply Quote 0
                    • CzechHek
                      CzechHek @test test2 last edited by

                      @test-test2 You might have to do some more open gl stuff which I have no idea about.

                      1 Reply Last reply Reply Quote 0
                      • test test2
                        test test2 last edited by

                        Solved, handwritten

                        1 Reply Last reply Reply Quote 0
                        • Topic has been marked as solved  test test2 test test2 
                        • T
                          ThrowAway39234 last edited by

                          A better way of not using reflection would be:

                          /**
                           * @param color1 color in hex.
                           * @param color2 color in hex.
                           */
                           function drawSimpleVerticalGradientRect(x, y, x2, y2, color1, color2) {
                              GL11.glBegin(GL11.GL_QUADS);
                              glColor(color1);
                              GL11.glVertex2d(x, y);
                              GL11.glVertex2d(x, y2);
                              glColor(color2);
                              GL11.glVertex2d(x2, y2);
                              GL11.glVertex2d(x2, y);
                              GL11.glEnd();
                          }
                          
                          /**
                           * @param color A color in hex.
                           */
                          function glColor(color) {
                              var a = (color >> 24) & 0xFF;
                              var r = (color >> 16) & 0xFF;
                              var g = (color >> 8) & 0xFF;
                              var b = (color) & 0xFF;
                              GL11.glColor4f(r / 255, g / 255, b / 255, a / 255);
                          }
                          

                          I would like to explain this, but i don't know if i could do it well

                          Example Usage:

                          GlStateManager.disableTexture2D();
                          GlStateManager.enableBlend();
                          GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                          // Tells GL to transition between colors
                          GlStateManager.shadeModel(GL11.GL_SMOOTH);
                          drawSimpleVerticalGradientRect(10, 10, 390, 390, 0xffffffff, 0x00ffffff);
                          // Tells GL to use the ONLY' last color
                          GlStateManager.shadeModel(GL11.GL_FLAT);
                          GlStateManager.disableBlend();
                          
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          About
                          • Terms of Service
                          • Privacy Policy
                          • Status
                          • Contact Us
                          Downloads
                          • Releases
                          • Source code
                          • License
                          Docs
                          • Tutorials
                          • CustomHUD
                          • AutoSettings
                          • ScriptAPI
                          Community
                          • Forum
                          • Guilded
                          • YouTube
                          • Twitter
                          • D.Tube