60 lines
2.3 KiB
Java
60 lines
2.3 KiB
Java
package org.lib3270j.graphics;
|
|
|
|
/**
|
|
* Builds the 56-byte IBM 3179G / 3270G Graphic Input Structured Field.
|
|
* Used for light-pen and graphics cursor interactive input per IBM HOD / GDDM specifications.
|
|
*/
|
|
public class GraphicInputBuilder {
|
|
|
|
// 56-byte template mask from IBM Host On-Demand (HODInput.java)
|
|
private static final byte[] MASK = new byte[] {
|
|
0x00, 0x34, 0x0F, 0x0F, 0x00, (byte) 0xC0, 0x00, 0x40,
|
|
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x23, 0x00, 0x23, 0x00, 0x00, 0x00, 0x1F, 0x01,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
|
|
0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x80, 0x00
|
|
};
|
|
|
|
/**
|
|
* Builds the 56-byte Graphic Input Structured Field.
|
|
*
|
|
* @param gocaX GOCA signed X coordinate (-xMax..+xMax)
|
|
* @param gocaY GOCA signed Y coordinate (-yMax..+yMax)
|
|
* @param aidCode The 3270 AID code (e.g. 0x7D for ENTER, 0xF3 for PF3)
|
|
* @param isMouseAction true if triggered directly by mouse button press, false for keyboard AID
|
|
* @param isShift true if shift key was down
|
|
* @param isCtrl true if ctrl key was down
|
|
* @return 56-byte payload
|
|
*/
|
|
public static byte[] buildGraphicInput(int gocaX, int gocaY, int aidCode,
|
|
boolean isMouseAction, boolean isShift, boolean isCtrl) {
|
|
byte[] sf = new byte[MASK.length];
|
|
System.arraycopy(MASK, 0, sf, 0, MASK.length);
|
|
|
|
// Byte 24-25: GOCA X coordinate (signed 16-bit big-endian)
|
|
sf[24] = (byte) ((gocaX >> 8) & 0xFF);
|
|
sf[25] = (byte) (gocaX & 0xFF);
|
|
|
|
// Byte 26-27: GOCA Y coordinate (signed 16-bit big-endian)
|
|
sf[26] = (byte) ((gocaY >> 8) & 0xFF);
|
|
sf[27] = (byte) (gocaY & 0xFF);
|
|
|
|
if (isMouseAction) {
|
|
sf[31] = 0x04;
|
|
sf[33] = 0x04;
|
|
sf[34] = isShift ? (byte) 0x80 : (isCtrl ? (byte) 0x40 : 0x00);
|
|
sf[35] = (byte) (aidCode == 2 ? 0x02 : 0x01); // Button 1 = Pick
|
|
} else {
|
|
// Keyboard AID (Enter, PF keys)
|
|
sf[31] = 0x07;
|
|
sf[33] = 0x07;
|
|
sf[34] = (byte) 0xFF;
|
|
sf[35] = (byte) (aidCode & 0xFF);
|
|
}
|
|
|
|
return sf;
|
|
}
|
|
}
|