9fans.net/go@v0.0.5/draw/cursor.go (about)

     1  package draw
     2  
     3  // A Cursor describes a single cursor.
     4  //
     5  // The arrays White and Black are arranged in rows, two bytes per row,
     6  // left to right in big-endian order, to give 16 rows of 16 bits each.
     7  // A cursor is displayed on the screen by adding Point to the current
     8  // mouse position, then using White as a mask to draw white at
     9  // the pixels where White is 1, and then drawing black at the pixels
    10  // where Black is 1.
    11  type Cursor struct {
    12  	Point
    13  	White [2 * 16]uint8
    14  	Black [2 * 16]uint8
    15  }
    16  
    17  // A Cursor2 describes a single high-DPI cursor,
    18  // with twice the pixels in each direction as a Cursor
    19  // (32 rows of 32 bits each).
    20  type Cursor2 struct {
    21  	Point
    22  	White [4 * 32]uint8
    23  	Black [4 * 32]uint8
    24  }
    25  
    26  var expand = [16]uint8{
    27  	0x00, 0x03, 0x0c, 0x0f,
    28  	0x30, 0x33, 0x3c, 0x3f,
    29  	0xc0, 0xc3, 0xcc, 0xcf,
    30  	0xf0, 0xf3, 0xfc, 0xff,
    31  }
    32  
    33  // ScaleCursor returns a high-DPI version of c.
    34  func ScaleCursor(c Cursor) Cursor2 {
    35  	var c2 Cursor2
    36  	c2.X = 2 * c.X
    37  	c2.Y = 2 * c.Y
    38  	for y := 0; y < 16; y++ {
    39  		c2.White[8*y+4] = expand[c.White[2*y]>>4]
    40  		c2.White[8*y] = c2.White[8*y+4]
    41  		c2.Black[8*y+4] = expand[c.Black[2*y]>>4]
    42  		c2.Black[8*y] = c2.Black[8*y+4]
    43  		c2.White[8*y+5] = expand[c.White[2*y]&15]
    44  		c2.White[8*y+1] = c2.White[8*y+5]
    45  		c2.Black[8*y+5] = expand[c.Black[2*y]&15]
    46  		c2.Black[8*y+1] = c2.Black[8*y+5]
    47  		c2.White[8*y+6] = expand[c.White[2*y+1]>>4]
    48  		c2.White[8*y+2] = c2.White[8*y+6]
    49  		c2.Black[8*y+6] = expand[c.Black[2*y+1]>>4]
    50  		c2.Black[8*y+2] = c2.Black[8*y+6]
    51  		c2.White[8*y+7] = expand[c.White[2*y+1]&15]
    52  		c2.White[8*y+3] = c2.White[8*y+7]
    53  		c2.Black[8*y+7] = expand[c.Black[2*y+1]&15]
    54  		c2.Black[8*y+3] = c2.Black[8*y+7]
    55  	}
    56  	return c2
    57  }