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

com.github.moaxcp.x11client.protocol.render.ChangePicture Maven / Gradle / Ivy

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

import com.github.moaxcp.x11client.protocol.OneWayRequest;
import com.github.moaxcp.x11client.protocol.X11Input;
import com.github.moaxcp.x11client.protocol.X11Output;
import com.github.moaxcp.x11client.protocol.xproto.SubwindowMode;
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 ChangePicture implements OneWayRequest {
  public static final byte OPCODE = 5;

  private int picture;

  private int valueMask;

  private int repeat;

  private int alphamap;

  private int alphaxorigin;

  private int alphayorigin;

  private int clipxorigin;

  private int clipyorigin;

  private int clipmask;

  private int graphicsexposure;

  private int subwindowmode;

  private int polyedge;

  private int polymode;

  private int dither;

  private int componentalpha;

  public byte getOpCode() {
    return OPCODE;
  }

  public static ChangePicture readChangePicture(X11Input in) throws IOException {
    in.readPad(1);
    short length = in.readCard16();
    int picture = in.readCard32();
    int valueMask = in.readCard32();
    ChangePicture.ChangePictureBuilder javaBuilder = ChangePicture.builder();
    javaBuilder.picture(picture);
    javaBuilder.valueMask(valueMask);
    if(javaBuilder.isValueMaskEnabled(Cp.REPEAT)) {
      javaBuilder.repeat(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.ALPHA_MAP)) {
      javaBuilder.alphamap(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.ALPHA_X_ORIGIN)) {
      javaBuilder.alphaxorigin(in.readInt32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.ALPHA_Y_ORIGIN)) {
      javaBuilder.alphayorigin(in.readInt32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.CLIP_X_ORIGIN)) {
      javaBuilder.clipxorigin(in.readInt32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.CLIP_Y_ORIGIN)) {
      javaBuilder.clipyorigin(in.readInt32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.CLIP_MASK)) {
      javaBuilder.clipmask(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.GRAPHICS_EXPOSURE)) {
      javaBuilder.graphicsexposure(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.SUBWINDOW_MODE)) {
      javaBuilder.subwindowmode(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.POLY_EDGE)) {
      javaBuilder.polyedge(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.POLY_MODE)) {
      javaBuilder.polymode(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.DITHER)) {
      javaBuilder.dither(in.readCard32());
    }
    if(javaBuilder.isValueMaskEnabled(Cp.COMPONENT_ALPHA)) {
      javaBuilder.componentalpha(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(picture);
    out.writeCard32(valueMask);
    if(isValueMaskEnabled(Cp.REPEAT)) {
      out.writeCard32(repeat);
    }
    if(isValueMaskEnabled(Cp.ALPHA_MAP)) {
      out.writeCard32(alphamap);
    }
    if(isValueMaskEnabled(Cp.ALPHA_X_ORIGIN)) {
      out.writeInt32(alphaxorigin);
    }
    if(isValueMaskEnabled(Cp.ALPHA_Y_ORIGIN)) {
      out.writeInt32(alphayorigin);
    }
    if(isValueMaskEnabled(Cp.CLIP_X_ORIGIN)) {
      out.writeInt32(clipxorigin);
    }
    if(isValueMaskEnabled(Cp.CLIP_Y_ORIGIN)) {
      out.writeInt32(clipyorigin);
    }
    if(isValueMaskEnabled(Cp.CLIP_MASK)) {
      out.writeCard32(clipmask);
    }
    if(isValueMaskEnabled(Cp.GRAPHICS_EXPOSURE)) {
      out.writeCard32(graphicsexposure);
    }
    if(isValueMaskEnabled(Cp.SUBWINDOW_MODE)) {
      out.writeCard32(subwindowmode);
    }
    if(isValueMaskEnabled(Cp.POLY_EDGE)) {
      out.writeCard32(polyedge);
    }
    if(isValueMaskEnabled(Cp.POLY_MODE)) {
      out.writeCard32(polymode);
    }
    if(isValueMaskEnabled(Cp.DITHER)) {
      out.writeCard32(dither);
    }
    if(isValueMaskEnabled(Cp.COMPONENT_ALPHA)) {
      out.writeCard32(componentalpha);
    }
    out.writePadAlign(getSize());
  }

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

  @Override
  public int getSize() {
    return 12 + (isValueMaskEnabled(Cp.REPEAT) ? 4 : 0) + (isValueMaskEnabled(Cp.ALPHA_MAP) ? 4 : 0) + (isValueMaskEnabled(Cp.ALPHA_X_ORIGIN) ? 4 : 0) + (isValueMaskEnabled(Cp.ALPHA_Y_ORIGIN) ? 4 : 0) + (isValueMaskEnabled(Cp.CLIP_X_ORIGIN) ? 4 : 0) + (isValueMaskEnabled(Cp.CLIP_Y_ORIGIN) ? 4 : 0) + (isValueMaskEnabled(Cp.CLIP_MASK) ? 4 : 0) + (isValueMaskEnabled(Cp.GRAPHICS_EXPOSURE) ? 4 : 0) + (isValueMaskEnabled(Cp.SUBWINDOW_MODE) ? 4 : 0) + (isValueMaskEnabled(Cp.POLY_EDGE) ? 4 : 0) + (isValueMaskEnabled(Cp.POLY_MODE) ? 4 : 0) + (isValueMaskEnabled(Cp.DITHER) ? 4 : 0) + (isValueMaskEnabled(Cp.COMPONENT_ALPHA) ? 4 : 0);
  }

  public static class ChangePictureBuilder {
    private ChangePicture.ChangePictureBuilder valueMask(int valueMask) {
      this.valueMask = valueMask;
      return this;
    }

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

    private ChangePicture.ChangePictureBuilder valueMaskEnable(Cp... maskEnums) {
      for(Cp m : maskEnums) {
        valueMask((int) m.enableFor(valueMask));
      }
      return this;
    }

    private ChangePicture.ChangePictureBuilder valueMaskDisable(Cp... maskEnums) {
      for(Cp m : maskEnums) {
        valueMask((int) m.disableFor(valueMask));
      }
      return this;
    }

    public ChangePicture.ChangePictureBuilder repeat(int repeat) {
      this.repeat = repeat;
      valueMaskEnable(Cp.REPEAT);
      return this;
    }

    public ChangePicture.ChangePictureBuilder repeat(Repeat repeat) {
      this.repeat = (int) repeat.getValue();
      valueMaskEnable(Cp.REPEAT);
      return this;
    }

    public ChangePicture.ChangePictureBuilder alphamap(int alphamap) {
      this.alphamap = alphamap;
      valueMaskEnable(Cp.ALPHA_MAP);
      return this;
    }

    public ChangePicture.ChangePictureBuilder alphaxorigin(int alphaxorigin) {
      this.alphaxorigin = alphaxorigin;
      valueMaskEnable(Cp.ALPHA_X_ORIGIN);
      return this;
    }

    public ChangePicture.ChangePictureBuilder alphayorigin(int alphayorigin) {
      this.alphayorigin = alphayorigin;
      valueMaskEnable(Cp.ALPHA_Y_ORIGIN);
      return this;
    }

    public ChangePicture.ChangePictureBuilder clipxorigin(int clipxorigin) {
      this.clipxorigin = clipxorigin;
      valueMaskEnable(Cp.CLIP_X_ORIGIN);
      return this;
    }

    public ChangePicture.ChangePictureBuilder clipyorigin(int clipyorigin) {
      this.clipyorigin = clipyorigin;
      valueMaskEnable(Cp.CLIP_Y_ORIGIN);
      return this;
    }

    public ChangePicture.ChangePictureBuilder clipmask(int clipmask) {
      this.clipmask = clipmask;
      valueMaskEnable(Cp.CLIP_MASK);
      return this;
    }

    public ChangePicture.ChangePictureBuilder graphicsexposure(int graphicsexposure) {
      this.graphicsexposure = graphicsexposure;
      valueMaskEnable(Cp.GRAPHICS_EXPOSURE);
      return this;
    }

    public ChangePicture.ChangePictureBuilder subwindowmode(int subwindowmode) {
      this.subwindowmode = subwindowmode;
      valueMaskEnable(Cp.SUBWINDOW_MODE);
      return this;
    }

    public ChangePicture.ChangePictureBuilder subwindowmode(SubwindowMode subwindowmode) {
      this.subwindowmode = (int) subwindowmode.getValue();
      valueMaskEnable(Cp.SUBWINDOW_MODE);
      return this;
    }

    public ChangePicture.ChangePictureBuilder polyedge(int polyedge) {
      this.polyedge = polyedge;
      valueMaskEnable(Cp.POLY_EDGE);
      return this;
    }

    public ChangePicture.ChangePictureBuilder polyedge(PolyEdge polyedge) {
      this.polyedge = (int) polyedge.getValue();
      valueMaskEnable(Cp.POLY_EDGE);
      return this;
    }

    public ChangePicture.ChangePictureBuilder polymode(int polymode) {
      this.polymode = polymode;
      valueMaskEnable(Cp.POLY_MODE);
      return this;
    }

    public ChangePicture.ChangePictureBuilder polymode(PolyMode polymode) {
      this.polymode = (int) polymode.getValue();
      valueMaskEnable(Cp.POLY_MODE);
      return this;
    }

    public ChangePicture.ChangePictureBuilder dither(int dither) {
      this.dither = dither;
      valueMaskEnable(Cp.DITHER);
      return this;
    }

    public ChangePicture.ChangePictureBuilder componentalpha(int componentalpha) {
      this.componentalpha = componentalpha;
      valueMaskEnable(Cp.COMPONENT_ALPHA);
      return this;
    }

    public int getSize() {
      return 12 + (isValueMaskEnabled(Cp.REPEAT) ? 4 : 0) + (isValueMaskEnabled(Cp.ALPHA_MAP) ? 4 : 0) + (isValueMaskEnabled(Cp.ALPHA_X_ORIGIN) ? 4 : 0) + (isValueMaskEnabled(Cp.ALPHA_Y_ORIGIN) ? 4 : 0) + (isValueMaskEnabled(Cp.CLIP_X_ORIGIN) ? 4 : 0) + (isValueMaskEnabled(Cp.CLIP_Y_ORIGIN) ? 4 : 0) + (isValueMaskEnabled(Cp.CLIP_MASK) ? 4 : 0) + (isValueMaskEnabled(Cp.GRAPHICS_EXPOSURE) ? 4 : 0) + (isValueMaskEnabled(Cp.SUBWINDOW_MODE) ? 4 : 0) + (isValueMaskEnabled(Cp.POLY_EDGE) ? 4 : 0) + (isValueMaskEnabled(Cp.POLY_MODE) ? 4 : 0) + (isValueMaskEnabled(Cp.DITHER) ? 4 : 0) + (isValueMaskEnabled(Cp.COMPONENT_ALPHA) ? 4 : 0);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy