go-hep.org/x/hep@v0.38.1/groot/rpad/canvas.go (about)

     1  // Copyright ©2023 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package rpad
     6  
     7  import (
     8  	"reflect"
     9  
    10  	"go-hep.org/x/hep/groot/rbytes"
    11  	"go-hep.org/x/hep/groot/root"
    12  	"go-hep.org/x/hep/groot/rtypes"
    13  	"go-hep.org/x/hep/groot/rvers"
    14  )
    15  
    16  type Canvas struct {
    17  	pad             Pad
    18  	fCatt           AttCanvas // Canvas attributes
    19  	fDISPLAY        string    // Name of destination screen
    20  	fXsizeUser      float32   // User specified size of canvas along X in CM
    21  	fYsizeUser      float32   // User specified size of canvas along Y in CM
    22  	fXsizeReal      float32   // Current size of canvas along X in CM
    23  	fYsizeReal      float32   // Current size of canvas along Y in CM
    24  	fHighLightColor int16     // Highlight color of active pad
    25  	fDoubleBuffer   int32     // Double buffer flag (0=off, 1=on)
    26  	fWindowTopX     int32     // Top X position of window (in pixels)
    27  	fWindowTopY     int32     // Top Y position of window (in pixels)
    28  	fWindowWidth    uint32    // Width of window (including borders, etc.)
    29  	fWindowHeight   uint32    // Height of window (including menubar, borders, etc.)
    30  	fCw             uint32    // Width of the canvas along X (pixels)
    31  	fCh             uint32    // Height of the canvas along Y (pixels)
    32  	fRetained       bool      // Retain structure flag
    33  }
    34  
    35  func (*Canvas) RVersion() int16 {
    36  	return rvers.Canvas
    37  }
    38  
    39  func (*Canvas) Class() string {
    40  	return "TCanvas"
    41  }
    42  
    43  func (c *Canvas) Name() string {
    44  	return c.pad.Name()
    45  }
    46  
    47  func (c *Canvas) Title() string {
    48  	return c.pad.Title()
    49  }
    50  
    51  // ROOTUnmarshaler is the interface implemented by an object that can
    52  // unmarshal itself from a ROOT buffer
    53  func (c *Canvas) UnmarshalROOT(r *rbytes.RBuffer) error {
    54  	if r.Err() != nil {
    55  		return r.Err()
    56  	}
    57  
    58  	hdr := r.ReadHeader(c.Class(), c.RVersion())
    59  
    60  	r.ReadObject(&c.pad)
    61  	c.fDISPLAY = r.ReadString()
    62  	c.fDoubleBuffer = r.ReadI32()
    63  	c.fRetained = r.ReadBool()
    64  
    65  	c.fXsizeUser = r.ReadF32()
    66  	c.fYsizeUser = r.ReadF32()
    67  	c.fXsizeReal = r.ReadF32()
    68  	c.fYsizeReal = r.ReadF32()
    69  	c.fWindowTopX = r.ReadI32()
    70  	c.fWindowTopY = r.ReadI32()
    71  	if hdr.Vers > 2 {
    72  		c.fWindowWidth = r.ReadU32()
    73  		c.fWindowHeight = r.ReadU32()
    74  	}
    75  	c.fCw = r.ReadU32()
    76  	c.fCh = r.ReadU32()
    77  	if hdr.Vers <= 2 {
    78  		c.fWindowWidth = c.fCw
    79  		c.fWindowHeight = c.fCh
    80  	}
    81  
    82  	r.ReadObject(&c.fCatt)
    83  	if r.Err() != nil {
    84  		panic(r.Err())
    85  	}
    86  
    87  	_ = r.ReadBool() // kMoveOpaque
    88  	_ = r.ReadBool() // kResizeOpaque
    89  
    90  	c.fHighLightColor = r.ReadI16()
    91  	_ = r.ReadBool() // fBatch
    92  	if hdr.Vers < 2 {
    93  		r.CheckHeader(hdr)
    94  		return r.Err()
    95  	}
    96  	_ = r.ReadBool() // kShowEventStatus
    97  	if hdr.Vers > 3 {
    98  		_ = r.ReadBool() // kAutoExec
    99  	}
   100  	_ = r.ReadBool() // kMenuBar
   101  
   102  	r.CheckHeader(hdr)
   103  	return r.Err()
   104  }
   105  
   106  // Keys implements the ObjectFinder interface.
   107  func (c *Canvas) Keys() []string {
   108  	return c.pad.Keys()
   109  }
   110  
   111  // Get implements the ObjectFinder interface.
   112  func (c *Canvas) Get(name string) (root.Object, error) {
   113  	return c.pad.Get(name)
   114  }
   115  
   116  func init() {
   117  	f := func() reflect.Value {
   118  		var c Canvas
   119  		return reflect.ValueOf(&c)
   120  	}
   121  	rtypes.Factory.Add("TCanvas", f)
   122  }
   123  
   124  var (
   125  	_ root.Object        = (*Canvas)(nil)
   126  	_ root.Named         = (*Canvas)(nil)
   127  	_ root.ObjectFinder  = (*Canvas)(nil)
   128  	_ rbytes.Unmarshaler = (*Canvas)(nil)
   129  )