ZenScript main repository
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DComponentContext.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package org.openzen.drawablegui;
  7. import java.util.function.Function;
  8. import org.openzen.drawablegui.draw.DDrawSurface;
  9. import org.openzen.drawablegui.draw.DDrawnRectangle;
  10. import org.openzen.drawablegui.draw.DDrawnShape;
  11. import org.openzen.drawablegui.draw.DDrawnText;
  12. import org.openzen.drawablegui.draw.DSubSurface;
  13. import org.openzen.drawablegui.scroll.DScrollContext;
  14. import org.openzen.drawablegui.style.DShadow;
  15. import org.openzen.drawablegui.style.DStyleClass;
  16. import org.openzen.drawablegui.style.DStyleDefinition;
  17. import org.openzen.drawablegui.style.DStylePath;
  18. /**
  19. *
  20. * @author Hoofdgebruiker
  21. */
  22. public class DComponentContext {
  23. public final DScrollContext scrollContext;
  24. public final DStylePath path;
  25. public final int z;
  26. public final DDrawSurface surface;
  27. public DComponentContext(DScrollContext scrollContext, DStylePath path, int z, DDrawSurface surface) {
  28. this.scrollContext = scrollContext;
  29. this.path = path;
  30. this.z = z;
  31. this.surface = surface;
  32. }
  33. public DComponentContext getChildContext(String component, DStyleClass styleClass) {
  34. return getChildContext(10, component, styleClass);
  35. }
  36. public DComponentContext getChildContext(int deltaz, String component, DStyleClass styleClass) {
  37. return new DComponentContext(scrollContext, path.getChild(component, styleClass), z + deltaz, surface);
  38. }
  39. public DUIContext getUIContext() {
  40. return surface.getContext();
  41. }
  42. public DStyleDefinition getStyle() {
  43. return surface.getStylesheet(path);
  44. }
  45. public <S> S getStyle(Function<DStyleDefinition, S> factory) {
  46. return factory.apply(surface.getStylesheet(path));
  47. }
  48. public DFontMetrics getFontMetrics(DFont font) {
  49. return surface.getFontMetrics(font);
  50. }
  51. public float getScale() {
  52. return surface.getScale();
  53. }
  54. public float getTextScale() {
  55. return surface.getTextScale();
  56. }
  57. public DDrawnText drawText(int deltaz, DFont font, int color, float x, float y, String text) {
  58. return surface.drawText(z + deltaz, font, color, x, y, text);
  59. }
  60. public DDrawnRectangle fillRect(int deltaz, DIRectangle rectangle, int color) {
  61. return surface.fillRect(z + deltaz, rectangle, color);
  62. }
  63. public DDrawnShape strokePath(int deltaz, DPath path, DTransform2D transform, int color, float lineWidth) {
  64. return surface.strokePath(z + deltaz, path, transform, color, lineWidth);
  65. }
  66. public DDrawnShape fillPath(int deltaz, DPath path, DTransform2D transform, int color) {
  67. return surface.fillPath(z + deltaz, path, transform, color);
  68. }
  69. public DDrawnShape shadowPath(int deltaz, DPath path, DTransform2D transform, int color, DShadow shadow) {
  70. return surface.shadowPath(z + deltaz, path, transform, color, shadow);
  71. }
  72. public DSubSurface createSubSurface(int deltaz) {
  73. return surface.createSubSurface(z + deltaz);
  74. }
  75. }