Morph doesn't paint on every tick?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Morph doesn't paint on every tick?

Louis LaBrunda
Hi All,

I'm making a CalendarDisplayMorph.  The code below is called every second.  I'm sure it is
being called every second.  But the seconds don't change every second.  It does change if I
click on the morph and select or move it or something.

I'm testing it with this:

        (TransformationMorph new asFlexOf: CalendarDisplayMorph new) openInWorld.

What am I missing?

Lou

displayDateTimeHeader
        "Display the date and time in the header."
        | font rect canvas fWidth weekDay dateString timeString |

        font := TextStyle default fontOfSize: 96.
        fWidth := self extent x.

        canvas := destForm getCanvas.
        rect := Rectangle origin: 0@0 extent: fWidth@headerHeight.
        canvas frameAndFillRectangle: rect fillColor: self cellColor borderWidth: 2 borderColor: self
borderColor.
        currentDate := DateAndTime now.

        weekDay := currentDate dayOfWeekName asString.
        self drawString: weekDay centeredIn: rect vOffset: 5 withFont: font color: self textColor.

        dateString := currentDate monthName, ' ', currentDate dayOfMonth printString, ', ',
currentDate year printString.
        self drawString: dateString centeredIn: rect vOffset: 35 withFont: font color: self
textColor.

        timeString := String streamContents: [:aStream | currentDate asTime print24: false
showSeconds: true on: aStream].
        self drawString: timeString centeredIn: rect vOffset: 65 withFont: font color: self
textColor.
--
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon


Reply | Threaded
Open this post in threaded view
|

Re: Morph doesn't paint on every tick?

Bob Arning-2

Morphs redraw when something has changed -- not much point in wasting cycles if everything is the same. So somewhere, like the Calendar... or an inner morph that only contains the time needs 2 methods like:


step

    self changed

stepTime

    ^1000    "or less"


On 12/26/17 7:22 PM, Louis LaBrunda wrote:
Hi All,

I'm making a CalendarDisplayMorph.  The code below is called every second.  I'm sure it is
being called every second.  But the seconds don't change every second.  It does change if I
click on the morph and select or move it or something.

I'm testing it with this:

	(TransformationMorph new asFlexOf: CalendarDisplayMorph new) openInWorld.

What am I missing?

Lou

displayDateTimeHeader
	"Display the date and time in the header."
	| font rect canvas fWidth weekDay dateString timeString |

	font := TextStyle default fontOfSize: 96.
	fWidth := self extent x.

	canvas := destForm getCanvas.
	rect := Rectangle origin: 0@0 extent: fWidth@headerHeight.
	canvas frameAndFillRectangle: rect fillColor: self cellColor borderWidth: 2 borderColor: self
borderColor.
	currentDate := DateAndTime now.

	weekDay := currentDate dayOfWeekName asString.
	self drawString: weekDay centeredIn: rect vOffset: 5 withFont: font color: self textColor.

	dateString := currentDate monthName, ' ', currentDate dayOfMonth printString, ', ',
currentDate year printString.
	self drawString: dateString centeredIn: rect vOffset: 35 withFont: font color: self
textColor.

	timeString := String streamContents: [:aStream | currentDate asTime print24: false
showSeconds: true on: aStream].
	self drawString: timeString centeredIn: rect vOffset: 65 withFont: font color: self
textColor.



Reply | Threaded
Open this post in threaded view
|

Morph doesn't paint on every tick?

Louis LaBrunda
Hi Bob,

Thanks for the answer.  I will give:

        self changed.

a try tomorrow.  #stepTime returns 1000.  The code is called every second.  I have checked with
messages to the transcript.  The method #displayDateTimeHeader is called every second.  It
clears the area.  Most of the text is repeated until the minute changes but the seconds change
with every call.  I don't understand why it doesn't redraw.  I may be breaking some rule with
how the morph is defined.  If so, I'm not sure what it is.  If sending self changed doesn't
work, maybe I will post a fileout of the whole morph, if you would be kind enough to take a
look.

Lou


On Tue, 26 Dec 2017 20:00:56 -0500, Bob Arning <[hidden email]> wrote:

>Morphs redraw when something has changed -- not much point in wasting
>cycles if everything is the same. So somewhere, like the Calendar... or
>an inner morph that only contains the time needs 2 methods like:
>
>
>step
>
>     self changed
>
>stepTime
>
>     ^1000    "or less"
>
>
>On 12/26/17 7:22 PM, Louis LaBrunda wrote:
>> Hi All,
>>
>> I'm making a CalendarDisplayMorph.  The code below is called every second.  I'm sure it is
>> being called every second.  But the seconds don't change every second.  It does change if I
>> click on the morph and select or move it or something.
>>
>> I'm testing it with this:
>>
>> (TransformationMorph new asFlexOf: CalendarDisplayMorph new) openInWorld.
>>
>> What am I missing?
>>
>> Lou
>>
>> displayDateTimeHeader
>> "Display the date and time in the header."
>> | font rect canvas fWidth weekDay dateString timeString |
>>
>> font := TextStyle default fontOfSize: 96.
>> fWidth := self extent x.
>>
>> canvas := destForm getCanvas.
>> rect := Rectangle origin: 0@0 extent: fWidth@headerHeight.
>> canvas frameAndFillRectangle: rect fillColor: self cellColor borderWidth: 2 borderColor: self
>> borderColor.
>> currentDate := DateAndTime now.
>>
>> weekDay := currentDate dayOfWeekName asString.
>> self drawString: weekDay centeredIn: rect vOffset: 5 withFont: font color: self textColor.
>>
>> dateString := currentDate monthName, ' ', currentDate dayOfMonth printString, ', ',
>> currentDate year printString.
>> self drawString: dateString centeredIn: rect vOffset: 35 withFont: font color: self
>> textColor.
>>
>> timeString := String streamContents: [:aStream | currentDate asTime print24: false
>> showSeconds: true on: aStream].
>> self drawString: timeString centeredIn: rect vOffset: 65 withFont: font color: self
>> textColor.
--
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon


Reply | Threaded
Open this post in threaded view
|

Re: Morph doesn't paint on every tick?

Bob Arning-2

Your code seems to make changes to destForm, but nothing in this method tells me what causes destForm to actually appear on the screen. In addition to knowing how often this method is called, knowing how often #drawOn: for the calendar is called would give you a more complete picture.


On 12/26/17 10:13 PM, Louis LaBrunda wrote:
Hi Bob,

Thanks for the answer.  I will give:

	self changed.

a try tomorrow.  #stepTime returns 1000.  The code is called every second.  I have checked with
messages to the transcript.  The method #displayDateTimeHeader is called every second.  It
clears the area.  Most of the text is repeated until the minute changes but the seconds change
with every call.  I don't understand why it doesn't redraw.  I may be breaking some rule with
how the morph is defined.  If so, I'm not sure what it is.  If sending self changed doesn't
work, maybe I will post a fileout of the whole morph, if you would be kind enough to take a
look.

Lou


On Tue, 26 Dec 2017 20:00:56 -0500, Bob Arning [hidden email] wrote:

Morphs redraw when something has changed -- not much point in wasting 
cycles if everything is the same. So somewhere, like the Calendar... or 
an inner morph that only contains the time needs 2 methods like:


step

    self changed

stepTime

    ^1000    "or less"


On 12/26/17 7:22 PM, Louis LaBrunda wrote:
Hi All,

I'm making a CalendarDisplayMorph.  The code below is called every second.  I'm sure it is
being called every second.  But the seconds don't change every second.  It does change if I
click on the morph and select or move it or something.

I'm testing it with this:

	(TransformationMorph new asFlexOf: CalendarDisplayMorph new) openInWorld.

What am I missing?

Lou

displayDateTimeHeader
	"Display the date and time in the header."
	| font rect canvas fWidth weekDay dateString timeString |

	font := TextStyle default fontOfSize: 96.
	fWidth := self extent x.

	canvas := destForm getCanvas.
	rect := Rectangle origin: 0@0 extent: fWidth@headerHeight.
	canvas frameAndFillRectangle: rect fillColor: self cellColor borderWidth: 2 borderColor: self
borderColor.
	currentDate := DateAndTime now.

	weekDay := currentDate dayOfWeekName asString.
	self drawString: weekDay centeredIn: rect vOffset: 5 withFont: font color: self textColor.

	dateString := currentDate monthName, ' ', currentDate dayOfMonth printString, ', ',
currentDate year printString.
	self drawString: dateString centeredIn: rect vOffset: 35 withFont: font color: self
textColor.

	timeString := String streamContents: [:aStream | currentDate asTime print24: false
showSeconds: true on: aStream].
	self drawString: timeString centeredIn: rect vOffset: 65 withFont: font color: self
textColor.



Reply | Threaded
Open this post in threaded view
|

Morph doesn't paint on every tick?

Louis LaBrunda
Hi Bob,

Thanks for the help.  Adding self changed to the end of the method solved the problem.

>Your code seems to make changes to destForm, but nothing in this method
>tells me what causes destForm to actually appear on the screen. In
>addition to knowing how often this method is called, knowing how often
>#drawOn: for the calendar is called would give you a more complete picture.

The whole mechanism of how morphs work, are drawn and such is a mystery to me.  I admit I
haven't looked very much but is there something I can read that will help me understand the big
picture of how morphs work?

Lou
--
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon


Reply | Threaded
Open this post in threaded view
|

Re: Morph doesn't paint on every tick?

Bob Arning-2

Well, there have been books and wikis and such, but I always prefer looking at the code itself.


On 12/27/17 9:43 AM, Louis LaBrunda wrote:
The whole mechanism of how morphs work, are drawn and such is a mystery to me.  I admit I
haven't looked very much but is there something I can read that will help me understand the big
picture of how morphs work?



Reply | Threaded
Open this post in threaded view
|

Re: Morph doesn't paint on every tick?

marcel.taeumel

Hi Lou,


you do not have to worry about re-drawing if you combine morphs only to create your application. That is, you write code that creates and configures line morphs, string morphs, rectangle morphs, and so on. If, however, you write your own #drawOn: methods, you have to tell Morphic about the side-effects that influence graphics via "self changed" or "self invalidRect: someRectangle". Yet, idiomatic use of Morphic means to employ custom #drawOn: methods _very_ scarcely.


In current Trunk, there are only 104 implementors of #drawOn: but 1051 senders of

#addMorph:, #addAllMorphs:, #addMorphBack:, #addMorphFront: combined.


Best,

Marcel



From: Squeak-dev <[hidden email]> on behalf of Bob Arning <[hidden email]>
Sent: Wednesday, December 27, 2017 3:56 PM
To: [hidden email]
Subject: Re: [squeak-dev] Morph doesn't paint on every tick?
 

Well, there have been books and wikis and such, but I always prefer looking at the code itself.


On 12/27/17 9:43 AM, Louis LaBrunda wrote:
The whole mechanism of how morphs work, are drawn and such is a mystery to me.  I admit I
haven't looked very much but is there something I can read that will help me understand the big
picture of how morphs work?