9fans.net/go@v0.0.7/cmd/acme/internal/adraw/draw.go (about)

     1  package adraw
     2  
     3  import (
     4  	"9fans.net/go/draw"
     5  	"9fans.net/go/draw/frame"
     6  )
     7  
     8  var Display *draw.Display
     9  
    10  var TagCols [frame.NCOL]*draw.Image
    11  
    12  var TextCols [frame.NCOL]*draw.Image
    13  
    14  var Button *draw.Image
    15  
    16  var ColButton *draw.Image
    17  
    18  var ModButton *draw.Image
    19  
    20  var Button2Color *draw.Image
    21  
    22  var Button3Color *draw.Image
    23  
    24  func Init() {
    25  	if TagCols[frame.BACK] == nil {
    26  		// Blue
    27  		TagCols[frame.BACK] = Display.AllocImageMix(draw.PaleBlueGreen, draw.White)
    28  		TagCols[frame.HIGH], _ = Display.AllocImage(draw.Rect(0, 0, 1, 1), Display.ScreenImage.Pix, true, draw.PaleGreyGreen)
    29  		TagCols[frame.BORD], _ = Display.AllocImage(draw.Rect(0, 0, 1, 1), Display.ScreenImage.Pix, true, draw.PurpleBlue)
    30  		TagCols[frame.TEXT] = Display.Black
    31  		TagCols[frame.HTEXT] = Display.Black
    32  
    33  		// Yellow
    34  		TextCols[frame.BACK] = Display.AllocImageMix(draw.PaleYellow, draw.White)
    35  		TextCols[frame.HIGH], _ = Display.AllocImage(draw.Rect(0, 0, 1, 1), Display.ScreenImage.Pix, true, draw.DarkYellow)
    36  		TextCols[frame.BORD], _ = Display.AllocImage(draw.Rect(0, 0, 1, 1), Display.ScreenImage.Pix, true, draw.YellowGreen)
    37  		TextCols[frame.TEXT] = Display.Black
    38  		TextCols[frame.HTEXT] = Display.Black
    39  	}
    40  
    41  	r := draw.Rect(0, 0, Scrollwid()+ButtonBorder(), Font.Height+1)
    42  	if Button != nil && r == Button.R {
    43  		return
    44  	}
    45  
    46  	if Button != nil {
    47  		Button.Free()
    48  		ModButton.Free()
    49  		ColButton.Free()
    50  	}
    51  
    52  	Button, _ = Display.AllocImage(r, Display.ScreenImage.Pix, false, draw.NoFill)
    53  	Button.Draw(r, TagCols[frame.BACK], nil, r.Min)
    54  	r.Max.X -= ButtonBorder()
    55  	Button.Border(r, ButtonBorder(), TagCols[frame.BORD], draw.ZP)
    56  
    57  	r = Button.R
    58  	ModButton, _ = Display.AllocImage(r, Display.ScreenImage.Pix, false, draw.NoFill)
    59  	ModButton.Draw(r, TagCols[frame.BACK], nil, r.Min)
    60  	r.Max.X -= ButtonBorder()
    61  	ModButton.Border(r, ButtonBorder(), TagCols[frame.BORD], draw.ZP)
    62  	r = r.Inset(ButtonBorder())
    63  	tmp, _ := Display.AllocImage(draw.Rect(0, 0, 1, 1), Display.ScreenImage.Pix, true, draw.MedBlue)
    64  	ModButton.Draw(r, tmp, nil, draw.ZP)
    65  	tmp.Free()
    66  
    67  	r = Button.R
    68  	ColButton, _ = Display.AllocImage(r, Display.ScreenImage.Pix, false, draw.PurpleBlue)
    69  
    70  	Button2Color, _ = Display.AllocImage(r, Display.ScreenImage.Pix, true, 0xAA0000FF)
    71  	Button3Color, _ = Display.AllocImage(r, Display.ScreenImage.Pix, true, 0x006600FF)
    72  }
    73  
    74  var BoxCursor = draw.Cursor{
    75  	Point: draw.Point{-7, -7},
    76  	White: [...]uint8{
    77  		0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    78  		0xFF, 0xFF, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F,
    79  		0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xFF, 0xFF,
    80  		0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    81  	},
    82  	Black: [...]uint8{
    83  		0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE,
    84  		0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E,
    85  		0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E,
    86  		0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x00, 0x00,
    87  	},
    88  }
    89  
    90  var BoxCursor2 = draw.Cursor2{
    91  	Point: draw.Point{-15, -15},
    92  	White: [...]uint8{
    93  		0xFF, 0xFF, 0xFF, 0xFF,
    94  		0xFF, 0xFF, 0xFF, 0xFF,
    95  		0xFF, 0xFF, 0xFF, 0xFF,
    96  		0xFF, 0xFF, 0xFF, 0xFF,
    97  		0xFF, 0xFF, 0xFF, 0xFF,
    98  		0xFF, 0xFF, 0xFF, 0xFF,
    99  		0xFF, 0xFF, 0xFF, 0xFF,
   100  		0xFF, 0xFF, 0xFF, 0xFF,
   101  		0xFF, 0xFF, 0xFF, 0xFF,
   102  		0xFF, 0xFF, 0xFF, 0xFF,
   103  		0xFF, 0xC0, 0x03, 0xFF,
   104  		0xFF, 0xC0, 0x03, 0xFF,
   105  		0xFF, 0xC0, 0x03, 0xFF,
   106  		0xFF, 0xC0, 0x03, 0xFF,
   107  		0xFF, 0xC0, 0x03, 0xFF,
   108  		0xFF, 0xC0, 0x03, 0xFF,
   109  		0xFF, 0xC0, 0x03, 0xFF,
   110  		0xFF, 0xC0, 0x03, 0xFF,
   111  		0xFF, 0xC0, 0x03, 0xFF,
   112  		0xFF, 0xC0, 0x03, 0xFF,
   113  		0xFF, 0xC0, 0x03, 0xFF,
   114  		0xFF, 0xC0, 0x03, 0xFF,
   115  		0xFF, 0xFF, 0xFF, 0xFF,
   116  		0xFF, 0xFF, 0xFF, 0xFF,
   117  		0xFF, 0xFF, 0xFF, 0xFF,
   118  		0xFF, 0xFF, 0xFF, 0xFF,
   119  		0xFF, 0xFF, 0xFF, 0xFF,
   120  		0xFF, 0xFF, 0xFF, 0xFF,
   121  		0xFF, 0xFF, 0xFF, 0xFF,
   122  		0xFF, 0xFF, 0xFF, 0xFF,
   123  		0xFF, 0xFF, 0xFF, 0xFF,
   124  		0xFF, 0xFF, 0xFF, 0xFF,
   125  	},
   126  	Black: [...]uint8{
   127  		0x00, 0x00, 0x00, 0x00,
   128  		0x00, 0x00, 0x00, 0x00,
   129  		0x3F, 0xFF, 0xFF, 0xFC,
   130  		0x3F, 0xFF, 0xFF, 0xFC,
   131  		0x3F, 0xFF, 0xFF, 0xFC,
   132  		0x3F, 0xFF, 0xFF, 0xFC,
   133  		0x3F, 0xFF, 0xFF, 0xFC,
   134  		0x3F, 0xFF, 0xFF, 0xFC,
   135  		0x3F, 0x00, 0x00, 0xFC,
   136  		0x3F, 0x00, 0x00, 0xFC,
   137  		0x3F, 0x00, 0x00, 0xFC,
   138  		0x3F, 0x00, 0x00, 0xFC,
   139  		0x3F, 0x00, 0x00, 0xFC,
   140  		0x3F, 0x00, 0x00, 0xFC,
   141  		0x3F, 0x00, 0x00, 0xFC,
   142  		0x3F, 0x00, 0x00, 0xFC,
   143  		0x3F, 0x00, 0x00, 0xFC,
   144  		0x3F, 0x00, 0x00, 0xFC,
   145  		0x3F, 0x00, 0x00, 0xFC,
   146  		0x3F, 0x00, 0x00, 0xFC,
   147  		0x3F, 0x00, 0x00, 0xFC,
   148  		0x3F, 0x00, 0x00, 0xFC,
   149  		0x3F, 0x00, 0x00, 0xFC,
   150  		0x3F, 0x00, 0x00, 0xFC,
   151  		0x3F, 0xFF, 0xFF, 0xFC,
   152  		0x3F, 0xFF, 0xFF, 0xFC,
   153  		0x3F, 0xFF, 0xFF, 0xFC,
   154  		0x3F, 0xFF, 0xFF, 0xFC,
   155  		0x3F, 0xFF, 0xFF, 0xFC,
   156  		0x3F, 0xFF, 0xFF, 0xFC,
   157  		0x00, 0x00, 0x00, 0x00,
   158  		0x00, 0x00, 0x00, 0x00,
   159  	},
   160  }
   161  
   162  func Scrollwid() int { return Display.Scale(12) }
   163  
   164  func Scrollgap() int { return Display.Scale(4) }
   165  
   166  func Margin() int { return Display.Scale(4) }
   167  
   168  func Border() int { return Display.Scale(2) }
   169  
   170  func ButtonBorder() int { return Display.Scale(2) }