ElectronWorkstation.st
author Claus Gittinger <cg@exept.de>
Thu, 15 Aug 2019 19:50:30 +0200
changeset 8775 e7b56d14fa77
parent 8772 4bfdf08ef358
child 8777 41f6f70e6919
permissions -rw-r--r--
#FEATURE by exept class: ElectronWorkstation class definition added: #ascentOf: #defaultEventMask #descentOf: #eventPending #getFontWithFamily:face:style:size:sizeUnit:encoding: #initializeScreenProperties #maxAscentOf: #maxDescentOf: #maxWidthOfFont: #minWidthOfFont: #pointerPosition #widthOf:from:to:inFont: comment/format in: #initializeFor: class: ElectronWorkstation class added: #initialize comment/format in: #documentation class: ElectronWorkstation::ElectronGraphicsContext class definition class: ElectronWorkstation::ElectronGraphicsContext class added: #documentation

"{ Encoding: utf8 }"

"{ Package: 'stx:libview' }"

"{ NameSpace: Smalltalk }"

DeviceWorkstation subclass:#ElectronWorkstation
	instanceVariableNames:'bridge eventQueue'
	classVariableNames:'ExposureMask StructureNotifyMask KeyPressMask KeyReleaseMask
		PointerMotionMask EnterWindowMask LeaveWindowMask ButtonPressMask
		ButtonMotionMask ButtonReleaseMask PropertyChangeMask'
	poolDictionaries:''
	category:'Interface-Graphics'
!

DeviceGraphicsContext subclass:#ElectronGraphicsContext
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	privateIn:ElectronWorkstation
!

!ElectronWorkstation class methodsFor:'documentation'!

documentation
"
    Smalltalk at:#Display2 put:(ElectronWorkstation newFor:'localhost:8588').
    (TopView onDevice:Display2) 
        label:'Hello';
        open
"
! !

!ElectronWorkstation class methodsFor:'class initialization'!

initialize
    ExposureMask        := 1 bitShift:0.
    StructureNotifyMask := 1 bitShift:1.
    KeyPressMask        := 1 bitShift:2.
    KeyReleaseMask      := 1 bitShift:3.
    PointerMotionMask   := 1 bitShift:4.
    EnterWindowMask     := 1 bitShift:5.
    LeaveWindowMask     := 1 bitShift:6.
    ButtonPressMask     := 1 bitShift:7.
    ButtonMotionMask    := 1 bitShift:8.
    ButtonReleaseMask   := 1 bitShift:9.
    PropertyChangeMask  := 1 bitShift:10.
! !

!ElectronWorkstation methodsFor:'accessing & queries'!

defaultEventMask
    "return a mask to enable some events by default."

    ^ ExposureMask | StructureNotifyMask |
      KeyPressMask | KeyReleaseMask |
      PointerMotionMask |
      EnterWindowMask | LeaveWindowMask |
      ButtonPressMask | ButtonMotionMask | ButtonReleaseMask |
      PropertyChangeMask

!

isOpen
    "return true, if there is a valid connection to the display"

    ^ bridge notNil
! !

!ElectronWorkstation methodsFor:'event handling'!

eventPending 
    ^ eventQueue notNil and:[eventQueue notEmpty]

! !

!ElectronWorkstation methodsFor:'font stuff'!

ascentOf:aFontId
    "/ the font name is its ID
    ^ 17
!

descentOf:aFontId
    "/ the font name is its ID
    ^ 17
!

getFontWithFamily:familyString face:faceString style:styleString size:sizeArg sizeUnit:sizeUnit encoding:encodingSym
    "try to get the specified font, return id.
     If not available, try next smaller font.
     If no font fits, return nil"

    "/ return the font name as ID
    ^ '%1-%2-%3-%4-%5-%6' 
        bindWith:familyString 
        with:faceString 
        with:styleString 
        with:sizeArg 
        with:sizeUnit 
        with:encodingSym
!

maxAscentOf:aFontId
    "/ the font name is its ID
    ^ 17
!

maxDescentOf:aFontId
    "/ the font name is its ID
    ^ 17
!

maxWidthOfFont:aFontId
    "/ the font name is its ID
    ^ 20
!

minWidthOfFont:aFontId
    "/ the font name is its ID
    ^ 20
!

widthOf:aString from:index1 to:index2 inFont:aFontId
    "/ the font name is its ID
    ^ (index2-index1+1) * 20
! !

!ElectronWorkstation methodsFor:'initialization & release'!

closeConnection
    "close down connection to Display - usually never done"

    |b|

    (b := bridge) notNil ifTrue:[
        bridge := nil.
        b close
    ].

    "Created: 13.1.1997 / 22:10:07 / cg"
!

initializeFor:aHostAndPortStringOrNil
    bridge := NodeJSBridge newBridgeForHostAndPort:aHostAndPortStringOrNil.
    bridge 
        startBridgeIn:'.'
        command:'node' 
        environment:nil 
        debug:false.
    bridge connect.

    self initializeScreenProperties.
    self initializeDefaultValues.
    self initializeKeyboardMap.
    self initializeDeviceSignals.
    self initializeDeviceResourceTables.

    Screen default isNil ifTrue:[
        "not initialized yet?"
        self initializeViewStyle.
    ].

    "
     ElectronWorkstation newFor:'localhost:8098'
    "
!

initializeScreenProperties
    super initializeScreenProperties.

    monitorType := #unknown.
    visualType := #TrueColor.
    depth := 24.
    redShift := 16.
    greenShift := 8.
    blueShift := 0.

    Display notNil ifTrue:[
        width := Display width.
        height := Display height.
    ] ifFalse:[
        width := 1280.
        height := 1024.
    ].
! !

!ElectronWorkstation methodsFor:'pointer stuff'!

pointerPosition
    ^ 0@0
! !

!ElectronWorkstation::ElectronGraphicsContext class methodsFor:'documentation'!

documentation
"
    documentation to be added.

    class:
        <a short class summary here, describing what instances represent>

    responsibilities:    
        <describing what my main role is>

    collaborators:    
        <describing with whom and how I talk to>

    API:
        <public api and main messages>
        
    example:
        <a one-line examples on how to use - can also be in a separate example method>

    implementation:
        <implementation points>

    [author:]
        exept MBP

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!ElectronWorkstation class methodsFor:'documentation'!

version_CVS
    ^ '$Header$'
! !


ElectronWorkstation initialize!