// DrawRect paints a rectangle using box characters.
773157
func (p *Painter) DrawRect(x, y, w, h int) {
	for j := 0; j < h; j++ {
		for i := 0; i < w; i++ {
			m := i + x
			n := j + y

			switch {
			case i == 0 && j == 0:
				p.DrawRune(m, n, '┌')
			case i == w-1 && j == 0:
				p.DrawRune(m, n, '┐')
			case i == 0 && j == h-1:
				p.DrawRune(m, n, '└')
			case i == w-1 && j == h-1:
				p.DrawRune(m, n, '┘')
			case i == 0 || i == w-1:
				p.DrawRune(m, n, '│')
			case j == 0 || j == h-1:
				p.DrawRune(m, n, '─')
			}
		}
	}
}
823568
func (s *ScrollArea) Draw(p *Painter) {
	p.Translate(-s.topLeft.X, -s.topLeft.Y)
	defer p.Restore()

	off := image.Point{s.topLeft.X, s.topLeft.Y}
	p.WithMask(image.Rectangle{Min: off, Max: s.Size().Add(off)}, func(p *Painter) {
		s.Widget.Draw(p)
	})
}
815267
func (rgc *RasterGraphicContext) DrawImage(img image.Image) {
	DrawImage(img, rgc.img, rgc.current.Tr, draw.Over, BilinearFilter)
}
1149668
func drawComboColor(win *Window, state nstyle.WidgetStates, header rect.Rect, is_active bool, color color.RGBA) {
	style := &win.ctx.Style
	out := &win.cmds
	/* draw combo box header background and border */
	var background *nstyle.Item
	if state&nstyle.WidgetStateActive != 0 {
		background = &style.Combo.Active
	} else if state&nstyle.WidgetStateHovered != 0 {
		background = &style.Combo.Hover
	} else {
		background = &style.Combo.Normal
	}

	if background.Type == nstyle.ItemImage {
		out.DrawImage(header, background.Data.Image)
	} else {
		out.FillRect(header, 0, style.Combo.BorderColor)
		out.FillRect(shrinkRect(header, 1), 0, background.Data.Color)
	}
	{
		var content rect.Rect
		var button rect.Rect
		var bounds rect.Rect
		var sym label.SymbolType
		if state&nstyle.WidgetStateHovered != 0 {
			sym = style.Combo.SymHover
		} else if is_active {
			sym = style.Combo.SymActive
		} else {
			sym = style.Combo.SymNormal
		}

		/* calculate button */
		button.W = header.H - 2*style.Combo.ButtonPadding.Y

		button.X = (header.X + header.W - header.H) - style.Combo.ButtonPadding.X
		button.Y = header.Y + style.Combo.ButtonPadding.Y
		button.H = button.W

		content.X = button.X + style.Combo.Button.Padding.X
		content.Y = button.Y + style.Combo.Button.Padding.Y
		content.W = button.W - 2*style.Combo.Button.Padding.X
		content.H = button.H - 2*style.Combo.Button.Padding.Y

		/* draw color */
		bounds.H = header.H - 4*style.Combo.ContentPadding.Y

		bounds.Y = header.Y + 2*style.Combo.ContentPadding.Y
		bounds.X = header.X + 2*style.Combo.ContentPadding.X
		bounds.W = (button.X - (style.Combo.ContentPadding.X + style.Combo.Spacing.X)) - bounds.X
		out.FillRect(bounds, 0, color)

		/* draw open/close button */
		drawSymbolButton(win, button, content, state, &style.Combo.Button, sym)
	}
}
817681
func drawConfFmtExp(p int, ct string, format *formatConditional) *xlsxCfRule {
	return &xlsxCfRule{
		Priority: p + 1,
		Type:     validType[format.Type],
		Formula:  []string{format.Criteria},
		DxfID:    &format.Format,
	}
}
535180
func (b *Box) Draw(p *Painter) {
	style := "box"
	if b.IsFocused() {
		style += ".focused"
	}

	p.WithStyle(style, func(p *Painter) {

		sz := b.Size()

		if b.border {
			p.WithStyle(style+".border", func(p *Painter) {
				p.DrawRect(0, 0, sz.X, sz.Y)
			})
			p.WithStyle(style, func(p *Painter) {
				p.WithMask(image.Rect(0, 0, sz.X-1, 1), func(p *Painter) {
					p.DrawText(1, 0, b.title)
				})
			})
			p.FillRect(1, 1, sz.X-2, sz.Y-2)
			p.Translate(1, 1)
			defer p.Restore()
		} else {
			p.FillRect(0, 0, sz.X, sz.Y)
		}

		var off image.Point
		for _, child := range b.children {
			switch b.Alignment() {
			case Horizontal:
				p.Translate(off.X, 0)
			case Vertical:
				p.Translate(0, off.Y)
			}

			p.WithMask(image.Rectangle{
				Min: image.ZP,
				Max: child.Size(),
			}, func(p *Painter) {
				child.Draw(p)
			})

			p.Restore()

			off = off.Add(child.Size())
		}
	})
}
1320462
func (surface *Surface) FillRects(rects []Rect, color uint32) error {
	if C.SDL_FillRects(surface.cptr(), rects[0].cptr(), C.int(len(rects)), C.Uint32(color)) != 0 {
		return GetError()
	}
	return nil
}
883203
func (c *Frame) DrawControl(t termboxControl) {
	ctlX, ctlY := t.GetX(), t.GetY()
	t.SetX((c.GetX() + ctlX))
	t.SetY((c.GetY() + ctlY))
	t.Draw()
	t.SetX(ctlX)
	t.SetY(ctlY)
}
1097423
func (f *Flex) Draw(screen tcell.Screen) {
	f.Box.Draw(screen)

	// Calculate size and position of the items.

	// Do we use the entire screen?
	if f.fullScreen {
		width, height := screen.Size()
		f.SetRect(0, 0, width, height)
	}

	// How much space can we distribute?
	x, y, width, height := f.GetInnerRect()
	var proportionSum int
	distSize := width
	if f.direction == FlexRow {
		distSize = height
	}
	for _, item := range f.items {
		if item.FixedSize > 0 {
			distSize -= item.FixedSize
		} else {
			proportionSum += item.Proportion
		}
	}

	// Calculate positions and draw items.
	pos := x
	if f.direction == FlexRow {
		pos = y
	}
	for _, item := range f.items {
		size := item.FixedSize
		if size <= 0 {
			size = distSize * item.Proportion / proportionSum
			distSize -= size
			proportionSum -= item.Proportion
		}
		if item.Item != nil {
			if f.direction == FlexColumn {
				item.Item.SetRect(pos, y, size, height)
			} else {
				item.Item.SetRect(x, pos, width, size)
			}
		}
		pos += size

		if item.Item != nil {
			if item.Item.GetFocusable().HasFocus() {
				defer item.Item.Draw(screen)
			} else {
				item.Item.Draw(screen)
			}
		}
	}
}
1302659
func (p *Padder) Draw(painter *Painter) {
	painter.Translate(p.padding.X, p.padding.Y)
	defer painter.Restore()

	p.widget.Draw(painter)
}
598433
func (renderer *Renderer) FillRect(rect *Rect) error {
	return errorFromInt(int(
		C.SDL_RenderFillRect(renderer.cptr(), rect.cptr())))
}
360984
func (p *Painter) FillRect(x, y, w, h int) {
	for j := 0; j < h; j++ {
		for i := 0; i < w; i++ {
			p.DrawRune(i+x, j+y, ' ')
		}
	}
}
465282
func Draw(w http.ResponseWriter, req *http.Request) {
	ctxt := fs.NewContext(req)

	url := req.FormValue("url")
	if url == "" {
		url = "http://swtch.com/qr"
	}
	if req.FormValue("upload") == "1" {
		upload(w, req, url)
		return
	}

	t0 := time.Now()
	img := req.FormValue("i")
	if !isImgName(img) {
		img = "pjw"
	}
	if req.FormValue("show") == "png" {
		i := loadSize(ctxt, img, 48)
		var buf bytes.Buffer
		png.Encode(&buf, i)
		w.Write(buf.Bytes())
		return
	}
	if req.FormValue("flag") == "1" {
		flag(w, req, img, ctxt)
		return
	}
	if req.FormValue("x") == "" {
		var data = struct {
			Name string
			URL  string
		}{
			Name: img,
			URL:  url,
		}
		runTemplate(ctxt, w, "qr/main.html", &data)
		return
	}

	arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
	targ := makeTarg(ctxt, img, 17+4*arg("v")+arg("z"))

	m := &Image{
		Name:         img,
		Dx:           arg("x"),
		Dy:           arg("y"),
		URL:          req.FormValue("u"),
		Version:      arg("v"),
		Mask:         arg("m"),
		RandControl:  arg("r") > 0,
		Dither:       arg("i") > 0,
		OnlyDataBits: arg("d") > 0,
		SaveControl:  arg("c") > 0,
		Scale:        arg("scale"),
		Target:       targ,
		Seed:         int64(arg("s")),
		Rotation:     arg("o"),
		Size:         arg("z"),
	}
	if m.Version > 8 {
		m.Version = 8
	}

	if m.Scale == 0 {
		if arg("l") > 1 {
			m.Scale = 8
		} else {
			m.Scale = 4
		}
	}
	if m.Version >= 12 && m.Scale >= 4 {
		m.Scale /= 2
	}

	if arg("l") == 1 {
		data, err := json.Marshal(m)
		if err != nil {
			panic(err)
		}
		h := md5.New()
		h.Write(data)
		tag := fmt.Sprintf("%x", h.Sum(nil))[:16]
		if err := ctxt.Write("qrsave/"+tag, data); err != nil {
			panic(err)
		}
		http.Redirect(w, req, "/qr/show/"+tag, http.StatusTemporaryRedirect)
		return
	}

	if err := m.Encode(req); err != nil {
		fmt.Fprintf(w, "%s\n", err)
		return
	}

	var dat []byte
	switch {
	case m.SaveControl:
		dat = m.Control
	default:
		dat = m.Code.PNG()
	}

	if arg("l") > 0 {
		w.Header().Set("Content-Type", "image/png")
		w.Write(dat)
		return
	}

	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	fmt.Fprint(w, "<center><img src=\"data:image/png;base64,")
	io.WriteString(w, base64.StdEncoding.EncodeToString(dat))
	fmt.Fprint(w, "\" /><br>")
	fmt.Fprintf(w, "<form method=\"POST\" action=\"%s&l=1\"><input type=\"submit\" value=\"Save this QR code\"></form>\n", m.Link())
	fmt.Fprintf(w, "</center>\n")
	fmt.Fprintf(w, "<br><center><font size=-1>%v</font></center>\n", time.Now().Sub(t0))
}
191034
func (s *StyledBox) Draw(p *tui.Painter) {
	p.WithStyle(s.Style, func(p *tui.Painter) {
		s.Box.Draw(p)
	})
}
841022
func drawTogglebox(win *Window, type_ toggleType, state nstyle.WidgetStates, style *nstyle.Toggle, active bool, labelrect, select_, cursor rect.Rect, str string) {
	out := &win.cmds
	font := win.ctx.Style.Font

	if style.DrawBegin != nil {
		style.DrawBegin(out)
	}
	if style.DrawEnd != nil {
		defer style.DrawEnd(out)
	}
	switch type_ {
	case toggleCheck:
		if style.Draw.Checkbox != nil {
			style.Draw.Checkbox(out, state, style, active, labelrect.Rectangle(), select_.Rectangle(), cursor.Rectangle(), str, font)
			return
		}
	default:
		if style.Draw.Radio != nil {
			style.Draw.Radio(out, state, style, active, labelrect.Rectangle(), select_.Rectangle(), cursor.Rectangle(), str, font)
			return
		}
	}

	/* select correct colors/images */
	var background *nstyle.Item
	var cursorstyle *nstyle.Item
	var text textWidget
	if state&nstyle.WidgetStateHovered != 0 {
		background = &style.Hover
		cursorstyle = &style.CursorHover
		text.Text = style.TextHover
	} else if state&nstyle.WidgetStateActive != 0 {
		background = &style.Hover
		cursorstyle = &style.CursorHover
		text.Text = style.TextActive
	} else {
		background = &style.Normal
		cursorstyle = &style.CursorNormal
		text.Text = style.TextNormal
	}

	/* draw background and cursor */
	if background.Type == nstyle.ItemImage {
		out.DrawImage(select_, background.Data.Image)
	} else {
		switch type_ {
		case toggleCheck:
			out.FillRect(select_, 0, background.Data.Color)
		default:
			out.FillCircle(select_, background.Data.Color)
		}
	}
	if active {
		if cursorstyle.Type == nstyle.ItemImage {
			out.DrawImage(cursor, cursorstyle.Data.Image)
		} else {
			switch type_ {
			case toggleCheck:
				out.FillRect(cursor, 0, cursorstyle.Data.Color)
			default:
				out.FillCircle(cursor, cursorstyle.Data.Color)
			}
		}
	}

	text.Padding.X = 0
	text.Padding.Y = 0
	text.Background = style.TextBackground
	widgetText(out, labelrect, str, &text, "LC", font)
	return
}
350270
func (surface *Surface) FillRect(rect *Rect, color uint32) error {
	if C.SDL_FillRect(surface.cptr(), rect.cptr(), C.Uint32(color)) != 0 {
		return GetError()
	}
	return nil
}
850762
func (p *Panel) Draw() {
	p.BoxLayout.SetOrientation(Vertical)
	p.BoxLayout.Draw()
}