Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. public void drawRoundedRect(float x0, float y0, float x1, float y1, float radiusTopLeft, float radiusTopRight, float radiusBottomLeft, float radiusBottomRight, int color)
  2. {
  3. int numberOfArcs = 18;
  4.  
  5. float angleIncrement = 90.0F / numberOfArcs;
  6.  
  7. float a = (color >> 24 & 0xFF) / 255.0F;
  8. float r = (color >> 16 & 0xFF) / 255.0F;
  9. float g = (color >> 8 & 0xFF) / 255.0F;
  10. float b = (color & 0xFF) / 255.0F;
  11.  
  12. GL11.glDisable(2884);
  13. GL11.glDisable(3553);
  14.  
  15. GL11.glEnable(3042);
  16. GL11.glBlendFunc(770, 771);
  17.  
  18. OpenGlHelper.glBlendFunc(770, 771, 1, 0);
  19. GL11.glColor4f(r, g, b, a);
  20.  
  21. GL11.glBegin(5);
  22. GL11.glVertex2f(x0 + radiusTopLeft, y0);
  23. GL11.glVertex2f(x0 + radiusBottomLeft, y1);
  24. GL11.glVertex2f(x1 - radiusTopRight, y0);
  25. GL11.glVertex2f(x1 - radiusBottomRight, y1);
  26. GL11.glEnd();
  27.  
  28. GL11.glBegin(5);
  29. GL11.glVertex2f(x0, y0 + radiusTopLeft);
  30. GL11.glVertex2f(x0 + radiusTopLeft, y0 + radiusTopLeft);
  31. GL11.glVertex2f(x0, y1 - radiusBottomLeft);
  32. GL11.glVertex2f(x0 + radiusBottomLeft, y1 - radiusBottomLeft);
  33. GL11.glEnd();
  34.  
  35. GL11.glBegin(5);
  36. GL11.glVertex2f(x1, y0 + radiusTopRight);
  37. GL11.glVertex2f(x1 - radiusTopRight, y0 + radiusTopRight);
  38. GL11.glVertex2f(x1, y1 - radiusBottomRight);
  39. GL11.glVertex2f(x1 - radiusBottomRight, y1 - radiusBottomRight);
  40. GL11.glEnd();
  41.  
  42. GL11.glBegin(6);
  43. float centerX = x1 - radiusTopRight;
  44. float centerY = y0 + radiusTopRight;
  45. GL11.glVertex2f(centerX, centerY);
  46. for (int i = 0; i <= numberOfArcs; i++)
  47. {
  48. float angle = i * angleIncrement;
  49. GL11.glVertex2f((float)(centerX + radiusTopRight * Math.cos(Math.toRadians(angle))), (float)(centerY - radiusTopRight * Math.sin(Math.toRadians(angle))));
  50. }
  51. GL11.glEnd();
  52.  
  53. GL11.glBegin(6);
  54. centerX = x0 + radiusTopLeft;
  55. centerY = y0 + radiusTopLeft;
  56. GL11.glVertex2f(centerX, centerY);
  57. for (int i = 0; i <= numberOfArcs; i++)
  58. {
  59. float angle = i * angleIncrement;
  60. GL11.glVertex2f((float)(centerX - radiusTopLeft * Math.cos(Math.toRadians(angle))), (float)(centerY - radiusTopLeft * Math.sin(Math.toRadians(angle))));
  61. }
  62. GL11.glEnd();
  63.  
  64. GL11.glBegin(6);
  65. centerX = x0 + radiusBottomLeft;
  66. centerY = y1 - radiusBottomLeft;
  67. GL11.glVertex2f(centerX, centerY);
  68. for (int i = 0; i <= numberOfArcs; i++)
  69. {
  70. float angle = i * angleIncrement;
  71. GL11.glVertex2f((float)(centerX - radiusBottomLeft * Math.cos(Math.toRadians(angle))), (float)(centerY + radiusBottomLeft * Math.sin(Math.toRadians(angle))));
  72. }
  73. GL11.glEnd();
  74.  
  75. GL11.glBegin(6);
  76. centerX = x1 - radiusBottomRight;
  77. centerY = y1 - radiusBottomRight;
  78. GL11.glVertex2f(centerX, centerY);
  79. for (int i = 0; i <= numberOfArcs; i++)
  80. {
  81. float angle = i * angleIncrement;
  82. GL11.glVertex2f((float)(centerX + radiusBottomRight * Math.cos(Math.toRadians(angle))), (float)(centerY + radiusBottomRight * Math.sin(Math.toRadians(angle))));
  83. }
  84. GL11.glEnd();
  85.  
  86. GL11.glEnable(3553);
  87. GL11.glEnable(2884);
  88. GL11.glDisable(3042);
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement