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

com.github.moaxcp.x11client.protocol.render.CreatePicture 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 CreatePicture implements OneWayRequest {
  public static final byte OPCODE = 4;

  private int pid;

  private int drawable;

  private int format;

  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 CreatePicture readCreatePicture(X11Input in) throws IOException {
    in.readPad(1);
    short length = in.readCard16();
    int pid = in.readCard32();
    int drawable = in.readCard32();
    int format = in.readCard32();
    int valueMask = in.readCard32();
    CreatePicture.CreatePictureBuilder javaBuilder = CreatePicture.builder();
    javaBuilder.pid(pid);
    javaBuilder.drawable(drawable);
    javaBuilder.format(format);
    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(pid);
    out.writeCard32(drawable);
    out.writeCard32(format);
    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 20 + (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 CreatePictureBuilder {
    private CreatePicture.CreatePictureBuilder 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 CreatePicture.CreatePictureBuilder valueMaskEnable(Cp... maskEnums) {
      for(Cp m : maskEnums) {
        valueMask((int) m.enableFor(valueMask));
      }
      return this;
    }

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

    public CreatePicture.CreatePictureBuilder repeat(int repeat) {
      this.repeat = repeat;
      valueMaskEnable(Cp.REPEAT);
      return this;
    }

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

    public CreatePicture.CreatePictureBuilder alphamap(int alphamap) {
      this.alphamap = alphamap;
      valueMaskEnable(Cp.ALPHA_MAP);
      return this;
    }

    public CreatePicture.CreatePictureBuilder alphaxorigin(int alphaxorigin) {
      this.alphaxorigin = alphaxorigin;
      valueMaskEnable(Cp.ALPHA_X_ORIGIN);
      return this;
    }

    public CreatePicture.CreatePictureBuilder alphayorigin(int alphayorigin) {
      this.alphayorigin = alphayorigin;
      valueMaskEnable(Cp.ALPHA_Y_ORIGIN);
      return this;
    }

    public CreatePicture.CreatePictureBuilder clipxorigin(int clipxorigin) {
      this.clipxorigin = clipxorigin;
      valueMaskEnable(Cp.CLIP_X_ORIGIN);
      return this;
    }

    public CreatePicture.CreatePictureBuilder clipyorigin(int clipyorigin) {
      this.clipyorigin = clipyorigin;
      valueMaskEnable(Cp.CLIP_Y_ORIGIN);
      return this;
    }

    public CreatePicture.CreatePictureBuilder clipmask(int clipmask) {
      this.clipmask = clipmask;
      valueMaskEnable(Cp.CLIP_MASK);
      return this;
    }

    public CreatePicture.CreatePictureBuilder graphicsexposure(int graphicsexposure) {
      this.graphicsexposure = graphicsexposure;
      valueMaskEnable(Cp.GRAPHICS_EXPOSURE);
      return this;
    }

    public CreatePicture.CreatePictureBuilder subwindowmode(int subwindowmode) {
      this.subwindowmode = subwindowmode;
      valueMaskEnable(Cp.SUBWINDOW_MODE);
      return this;
    }

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

    public CreatePicture.CreatePictureBuilder polyedge(int polyedge) {
      this.polyedge = polyedge;
      valueMaskEnable(Cp.POLY_EDGE);
      return this;
    }

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

    public CreatePicture.CreatePictureBuilder polymode(int polymode) {
      this.polymode = polymode;
      valueMaskEnable(Cp.POLY_MODE);
      return this;
    }

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

    public CreatePicture.CreatePictureBuilder dither(int dither) {
      this.dither = dither;
      valueMaskEnable(Cp.DITHER);
      return this;
    }

    public CreatePicture.CreatePictureBuilder componentalpha(int componentalpha) {
      this.componentalpha = componentalpha;
      valueMaskEnable(Cp.COMPONENT_ALPHA);
      return this;
    }

    public int getSize() {
      return 20 + (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