Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

LiquidBounce Forum

  1. Home
  2. ScriptAPI
  3. How to draw a gradient rect

How to draw a gradient rect

Scheduled Pinned Locked Moved Solved ScriptAPI
11 Posts 5 Posters 881 Views
  • 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 test2T Offline
    test test2T Offline
    test test2
    wrote on last edited by
    #1

    How to draw a gradient rect?

    Gui.drawGradientRect is 'protected'

    F 1 Reply Last reply
    0
    • test test2T test test2

      How to draw a gradient rect?

      Gui.drawGradientRect is 'protected'

      F Offline
      F Offline
      freerobuxgen2022
      wrote on last edited by freerobuxgen2022
      #2

      its protected i cant access it

      reflection

      1 Reply Last reply
      0
      • test test2T Offline
        test test2T Offline
        test test2
        wrote on last edited by
        #3
                            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?

        Ali00035A CzechHekC 2 Replies Last reply
        0
        • test test2T test test2
                              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?

          Ali00035A Offline
          Ali00035A Offline
          Ali00035
          wrote on last edited by
          #4

          @test-test2 Does it work

          1 Reply Last reply
          0
          • test test2T test test2
                                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?

            CzechHekC Offline
            CzechHekC Offline
            CzechHek
            wrote on last edited by CzechHek
            #5

            @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
            0
            • test test2T Offline
              test test2T Offline
              test test2
              wrote on last edited by
              #6

              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
              0
              • test test2T Offline
                test test2T Offline
                test test2
                wrote on last edited by
                #7

                oh, how to include Core library?

                1 Reply Last reply
                0
                • test test2T Offline
                  test test2T Offline
                  test test2
                  wrote on last edited by test test2
                  #8

                  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

                  CzechHekC 1 Reply Last reply
                  0
                  • test test2T 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

                    CzechHekC Offline
                    CzechHekC Offline
                    CzechHek
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • test test2T Offline
                      test test2T Offline
                      test test2
                      wrote on last edited by
                      #10

                      Solved, handwritten

                      1 Reply Last reply
                      0
                      • test test2T test test2 has marked this topic as solved on
                      • T Offline
                        T Offline
                        ThrowAway39234
                        wrote on last edited by
                        #11

                        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
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        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
                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups