All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.moaxcp.x11client.protocol.xproto.ChangeGC Maven / Gradle / Ivy

There is a newer version: 0.18.2
Show newest version
package com.github.moaxcp.x11client.protocol.xproto;

import com.github.moaxcp.x11client.protocol.OneWayRequest;
import com.github.moaxcp.x11client.protocol.X11Input;
import com.github.moaxcp.x11client.protocol.X11Output;
import java.io.IOException;
import java.lang.Byte;
import java.lang.Override;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;

@Value
@Builder
public class ChangeGC implements OneWayRequest {
  public static final byte OPCODE = 56;

  private int gc;

  private int valueMask;

  private int function;

  private int planeMask;

  private int foreground;

  private int background;

  private int lineWidth;

  private int lineStyle;

  private int capStyle;

  private int joinStyle;

  private int fillStyle;

  private int fillRule;

  private int tile;

  private int stipple;

  private int tileStippleXOrigin;

  private int tileStippleYOrigin;

  private int font;

  private int subwindowMode;

  private int graphicsExposures;

  private int clipXOrigin;

  private int clipYOrigin;

  private int clipMask;

  private int dashOffset;

  private int dashes;

  private int arcMode;

  public byte getOpCode() {
    return OPCODE;
  }

  public static ChangeGC readChangeGC(X11Input in) throws IOException {
    in.readPad(1);
    short length = in.readCard16();
    int gc = in.readCard32();
    int valueMask = in.readCard32();
    ChangeGC.ChangeGCBuilder javaBuilder = ChangeGC.builder();
    javaBuilder.gc(gc);
    javaBuilder.valueMask(valueMask);
    if(javaBuilder.isValueMaskEnabled(Gc.FUNCTION)) {
      javaBuilder.function(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.PLANE_MASK)) {
      javaBuilder.planeMask(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.FOREGROUND)) {
      javaBuilder.foreground(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.BACKGROUND)) {
      javaBuilder.background(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.LINE_WIDTH)) {
      javaBuilder.lineWidth(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.LINE_STYLE)) {
      javaBuilder.lineStyle(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.CAP_STYLE)) {
      javaBuilder.capStyle(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.JOIN_STYLE)) {
      javaBuilder.joinStyle(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.FILL_STYLE)) {
      javaBuilder.fillStyle(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.FILL_RULE)) {
      javaBuilder.fillRule(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.TILE)) {
      javaBuilder.tile(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.STIPPLE)) {
      javaBuilder.stipple(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.TILE_STIPPLE_ORIGIN_X)) {
      javaBuilder.tileStippleXOrigin(in.readInt32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.TILE_STIPPLE_ORIGIN_Y)) {
      javaBuilder.tileStippleYOrigin(in.readInt32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.FONT)) {
      javaBuilder.font(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.SUBWINDOW_MODE)) {
      javaBuilder.subwindowMode(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.GRAPHICS_EXPOSURES)) {
      javaBuilder.graphicsExposures(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.CLIP_ORIGIN_X)) {
      javaBuilder.clipXOrigin(in.readInt32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.CLIP_ORIGIN_Y)) {
      javaBuilder.clipYOrigin(in.readInt32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.CLIP_MASK)) {
      javaBuilder.clipMask(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.DASH_OFFSET)) {
      javaBuilder.dashOffset(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.DASH_LIST)) {
      javaBuilder.dashes(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Gc.ARC_MODE)) {
      javaBuilder.arcMode(in.readCard32());
    }
    in.readPadAlign(javaBuilder.getSize());
    return javaBuilder.build();
  }

  @Override
  public void write(byte offset, X11Output out) throws IOException {
    out.writeCard8((byte)(Byte.toUnsignedInt(OPCODE) + Byte.toUnsignedInt(offset)));
    out.writePad(1);
    out.writeCard16((short) getLength());
    out.writeCard32(gc);
    out.writeCard32(valueMask);
    if(isValueMaskEnabled(Gc.FUNCTION)) {
      out.writeCard32(function);
    }
    if(isValueMaskEnabled(Gc.PLANE_MASK)) {
      out.writeCard32(planeMask);
    }
    if(isValueMaskEnabled(Gc.FOREGROUND)) {
      out.writeCard32(foreground);
    }
    if(isValueMaskEnabled(Gc.BACKGROUND)) {
      out.writeCard32(background);
    }
    if(isValueMaskEnabled(Gc.LINE_WIDTH)) {
      out.writeCard32(lineWidth);
    }
    if(isValueMaskEnabled(Gc.LINE_STYLE)) {
      out.writeCard32(lineStyle);
    }
    if(isValueMaskEnabled(Gc.CAP_STYLE)) {
      out.writeCard32(capStyle);
    }
    if(isValueMaskEnabled(Gc.JOIN_STYLE)) {
      out.writeCard32(joinStyle);
    }
    if(isValueMaskEnabled(Gc.FILL_STYLE)) {
      out.writeCard32(fillStyle);
    }
    if(isValueMaskEnabled(Gc.FILL_RULE)) {
      out.writeCard32(fillRule);
    }
    if(isValueMaskEnabled(Gc.TILE)) {
      out.writeCard32(tile);
    }
    if(isValueMaskEnabled(Gc.STIPPLE)) {
      out.writeCard32(stipple);
    }
    if(isValueMaskEnabled(Gc.TILE_STIPPLE_ORIGIN_X)) {
      out.writeInt32(tileStippleXOrigin);
    }
    if(isValueMaskEnabled(Gc.TILE_STIPPLE_ORIGIN_Y)) {
      out.writeInt32(tileStippleYOrigin);
    }
    if(isValueMaskEnabled(Gc.FONT)) {
      out.writeCard32(font);
    }
    if(isValueMaskEnabled(Gc.SUBWINDOW_MODE)) {
      out.writeCard32(subwindowMode);
    }
    if(isValueMaskEnabled(Gc.GRAPHICS_EXPOSURES)) {
      out.writeCard32(graphicsExposures);
    }
    if(isValueMaskEnabled(Gc.CLIP_ORIGIN_X)) {
      out.writeInt32(clipXOrigin);
    }
    if(isValueMaskEnabled(Gc.CLIP_ORIGIN_Y)) {
      out.writeInt32(clipYOrigin);
    }
    if(isValueMaskEnabled(Gc.CLIP_MASK)) {
      out.writeCard32(clipMask);
    }
    if(isValueMaskEnabled(Gc.DASH_OFFSET)) {
      out.writeCard32(dashOffset);
    }
    if(isValueMaskEnabled(Gc.DASH_LIST)) {
      out.writeCard32(dashes);
    }
    if(isValueMaskEnabled(Gc.ARC_MODE)) {
      out.writeCard32(arcMode);
    }
    out.writePadAlign(getSize());
  }

  public boolean isValueMaskEnabled(@NonNull Gc... maskEnums) {
    for(Gc m : maskEnums) {
      if(!m.isEnabled(valueMask)) {
        return false;
      }
    }
    return true;
  }

  @Override
  public int getSize() {
    return 12 + (isValueMaskEnabled(Gc.FUNCTION) ? 4 : 0) + (isValueMaskEnabled(Gc.PLANE_MASK) ? 4 : 0) + (isValueMaskEnabled(Gc.FOREGROUND) ? 4 : 0) + (isValueMaskEnabled(Gc.BACKGROUND) ? 4 : 0) + (isValueMaskEnabled(Gc.LINE_WIDTH) ? 4 : 0) + (isValueMaskEnabled(Gc.LINE_STYLE) ? 4 : 0) + (isValueMaskEnabled(Gc.CAP_STYLE) ? 4 : 0) + (isValueMaskEnabled(Gc.JOIN_STYLE) ? 4 : 0) + (isValueMaskEnabled(Gc.FILL_STYLE) ? 4 : 0) + (isValueMaskEnabled(Gc.FILL_RULE) ? 4 : 0) + (isValueMaskEnabled(Gc.TILE) ? 4 : 0) + (isValueMaskEnabled(Gc.STIPPLE) ? 4 : 0) + (isValueMaskEnabled(Gc.TILE_STIPPLE_ORIGIN_X) ? 4 : 0) + (isValueMaskEnabled(Gc.TILE_STIPPLE_ORIGIN_Y) ? 4 : 0) + (isValueMaskEnabled(Gc.FONT) ? 4 : 0) + (isValueMaskEnabled(Gc.SUBWINDOW_MODE) ? 4 : 0) + (isValueMaskEnabled(Gc.GRAPHICS_EXPOSURES) ? 4 : 0) + (isValueMaskEnabled(Gc.CLIP_ORIGIN_X) ? 4 : 0) + (isValueMaskEnabled(Gc.CLIP_ORIGIN_Y) ? 4 : 0) + (isValueMaskEnabled(Gc.CLIP_MASK) ? 4 : 0) + (isValueMaskEnabled(Gc.DASH_OFFSET) ? 4 : 0) + (isValueMaskEnabled(Gc.DASH_LIST) ? 4 : 0) + (isValueMaskEnabled(Gc.ARC_MODE) ? 4 : 0);
  }

  public static class ChangeGCBuilder {
    private ChangeGC.ChangeGCBuilder valueMask(int valueMask) {
      this.valueMask = valueMask;
      return this;
    }

    public boolean isValueMaskEnabled(@NonNull Gc... maskEnums) {
      for(Gc m : maskEnums) {
        if(!m.isEnabled(valueMask)) {
          return false;
        }
      }
      return true;
    }

    private ChangeGC.ChangeGCBuilder valueMaskEnable(Gc... maskEnums) {
      for(Gc m : maskEnums) {
        valueMask((int) m.enableFor(valueMask));
      }
      return this;
    }

    private ChangeGC.ChangeGCBuilder valueMaskDisable(Gc... maskEnums) {
      for(Gc m : maskEnums) {
        valueMask((int) m.disableFor(valueMask));
      }
      return this;
    }

    public ChangeGC.ChangeGCBuilder function(int function) {
      this.function = function;
      valueMaskEnable(Gc.FUNCTION);
      return this;
    }

    public ChangeGC.ChangeGCBuilder function(Gx function) {
      this.function = (int) function.getValue();
      valueMaskEnable(Gc.FUNCTION);
      return this;
    }

    public ChangeGC.ChangeGCBuilder planeMask(int planeMask) {
      this.planeMask = planeMask;
      valueMaskEnable(Gc.PLANE_MASK);
      return this;
    }

    public ChangeGC.ChangeGCBuilder foreground(int foreground) {
      this.foreground = foreground;
      valueMaskEnable(Gc.FOREGROUND);
      return this;
    }

    public ChangeGC.ChangeGCBuilder background(int background) {
      this.background = background;
      valueMaskEnable(Gc.BACKGROUND);
      return this;
    }

    public ChangeGC.ChangeGCBuilder lineWidth(int lineWidth) {
      this.lineWidth = lineWidth;
      valueMaskEnable(Gc.LINE_WIDTH);
      return this;
    }

    public ChangeGC.ChangeGCBuilder lineStyle(int lineStyle) {
      this.lineStyle = lineStyle;
      valueMaskEnable(Gc.LINE_STYLE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder lineStyle(LineStyle lineStyle) {
      this.lineStyle = (int) lineStyle.getValue();
      valueMaskEnable(Gc.LINE_STYLE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder capStyle(int capStyle) {
      this.capStyle = capStyle;
      valueMaskEnable(Gc.CAP_STYLE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder capStyle(CapStyle capStyle) {
      this.capStyle = (int) capStyle.getValue();
      valueMaskEnable(Gc.CAP_STYLE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder joinStyle(int joinStyle) {
      this.joinStyle = joinStyle;
      valueMaskEnable(Gc.JOIN_STYLE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder joinStyle(JoinStyle joinStyle) {
      this.joinStyle = (int) joinStyle.getValue();
      valueMaskEnable(Gc.JOIN_STYLE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder fillStyle(int fillStyle) {
      this.fillStyle = fillStyle;
      valueMaskEnable(Gc.FILL_STYLE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder fillStyle(FillStyle fillStyle) {
      this.fillStyle = (int) fillStyle.getValue();
      valueMaskEnable(Gc.FILL_STYLE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder fillRule(int fillRule) {
      this.fillRule = fillRule;
      valueMaskEnable(Gc.FILL_RULE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder fillRule(FillRule fillRule) {
      this.fillRule = (int) fillRule.getValue();
      valueMaskEnable(Gc.FILL_RULE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder tile(int tile) {
      this.tile = tile;
      valueMaskEnable(Gc.TILE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder stipple(int stipple) {
      this.stipple = stipple;
      valueMaskEnable(Gc.STIPPLE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder tileStippleXOrigin(int tileStippleXOrigin) {
      this.tileStippleXOrigin = tileStippleXOrigin;
      valueMaskEnable(Gc.TILE_STIPPLE_ORIGIN_X);
      return this;
    }

    public ChangeGC.ChangeGCBuilder tileStippleYOrigin(int tileStippleYOrigin) {
      this.tileStippleYOrigin = tileStippleYOrigin;
      valueMaskEnable(Gc.TILE_STIPPLE_ORIGIN_Y);
      return this;
    }

    public ChangeGC.ChangeGCBuilder font(int font) {
      this.font = font;
      valueMaskEnable(Gc.FONT);
      return this;
    }

    public ChangeGC.ChangeGCBuilder subwindowMode(int subwindowMode) {
      this.subwindowMode = subwindowMode;
      valueMaskEnable(Gc.SUBWINDOW_MODE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder subwindowMode(SubwindowMode subwindowMode) {
      this.subwindowMode = (int) subwindowMode.getValue();
      valueMaskEnable(Gc.SUBWINDOW_MODE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder graphicsExposures(int graphicsExposures) {
      this.graphicsExposures = graphicsExposures;
      valueMaskEnable(Gc.GRAPHICS_EXPOSURES);
      return this;
    }

    public ChangeGC.ChangeGCBuilder clipXOrigin(int clipXOrigin) {
      this.clipXOrigin = clipXOrigin;
      valueMaskEnable(Gc.CLIP_ORIGIN_X);
      return this;
    }

    public ChangeGC.ChangeGCBuilder clipYOrigin(int clipYOrigin) {
      this.clipYOrigin = clipYOrigin;
      valueMaskEnable(Gc.CLIP_ORIGIN_Y);
      return this;
    }

    public ChangeGC.ChangeGCBuilder clipMask(int clipMask) {
      this.clipMask = clipMask;
      valueMaskEnable(Gc.CLIP_MASK);
      return this;
    }

    public ChangeGC.ChangeGCBuilder dashOffset(int dashOffset) {
      this.dashOffset = dashOffset;
      valueMaskEnable(Gc.DASH_OFFSET);
      return this;
    }

    public ChangeGC.ChangeGCBuilder dashes(int dashes) {
      this.dashes = dashes;
      valueMaskEnable(Gc.DASH_LIST);
      return this;
    }

    public ChangeGC.ChangeGCBuilder arcMode(int arcMode) {
      this.arcMode = arcMode;
      valueMaskEnable(Gc.ARC_MODE);
      return this;
    }

    public ChangeGC.ChangeGCBuilder arcMode(ArcMode arcMode) {
      this.arcMode = (int) arcMode.getValue();
      valueMaskEnable(Gc.ARC_MODE);
      return this;
    }

    public int getSize() {
      return 12 + (isValueMaskEnabled(Gc.FUNCTION) ? 4 : 0) + (isValueMaskEnabled(Gc.PLANE_MASK) ? 4 : 0) + (isValueMaskEnabled(Gc.FOREGROUND) ? 4 : 0) + (isValueMaskEnabled(Gc.BACKGROUND) ? 4 : 0) + (isValueMaskEnabled(Gc.LINE_WIDTH) ? 4 : 0) + (isValueMaskEnabled(Gc.LINE_STYLE) ? 4 : 0) + (isValueMaskEnabled(Gc.CAP_STYLE) ? 4 : 0) + (isValueMaskEnabled(Gc.JOIN_STYLE) ? 4 : 0) + (isValueMaskEnabled(Gc.FILL_STYLE) ? 4 : 0) + (isValueMaskEnabled(Gc.FILL_RULE) ? 4 : 0) + (isValueMaskEnabled(Gc.TILE) ? 4 : 0) + (isValueMaskEnabled(Gc.STIPPLE) ? 4 : 0) + (isValueMaskEnabled(Gc.TILE_STIPPLE_ORIGIN_X) ? 4 : 0) + (isValueMaskEnabled(Gc.TILE_STIPPLE_ORIGIN_Y) ? 4 : 0) + (isValueMaskEnabled(Gc.FONT) ? 4 : 0) + (isValueMaskEnabled(Gc.SUBWINDOW_MODE) ? 4 : 0) + (isValueMaskEnabled(Gc.GRAPHICS_EXPOSURES) ? 4 : 0) + (isValueMaskEnabled(Gc.CLIP_ORIGIN_X) ? 4 : 0) + (isValueMaskEnabled(Gc.CLIP_ORIGIN_Y) ? 4 : 0) + (isValueMaskEnabled(Gc.CLIP_MASK) ? 4 : 0) + (isValueMaskEnabled(Gc.DASH_OFFSET) ? 4 : 0) + (isValueMaskEnabled(Gc.DASH_LIST) ? 4 : 0) + (isValueMaskEnabled(Gc.ARC_MODE) ? 4 : 0);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy