Reputation: 11
Drag a corner of an image in DM triggers the image content refreshed to the new window size. What is the DM script command to trigger that refreshing?
Specifically, I want to add a text below the image. So, I get the imageDocument as root component, add a text annotation below the image (the vertical position of the text is beyond the bottom border of the image). Without "imgDoc.ImageDocumentSwitchToPageMode()", the text is not visible. When I change the image size with mouse, the image content is updated and the text is shown. Looking for script doing that.
Thanks,
Upvotes: 0
Views: 136
Reputation: 11
For new GMS 2.x or higher, the answer is void ImageDocumentOptimizeWindow( ImageDocument imgDoc )
. Not tested.
For older GMS, a generic solution is like this,
void resetImageDisplay(image img) {
imageDisplay imgDsp=img.ImageGetImageDisplay(0)
imageDocument imgDoc = img.ImageGetOrCreateImageDocument()
imgDoc.ImageDocumentSwitchToPageMode()
imgDoc.ImageDocumentSwitchToImageMode(imgDsp)
}
void main() {
image img:=exprSize(512,512, random())
img.showImage()
imageDisplay imgDsp=img.ImageGetImageDisplay(0)
component comp1=imgDsp.NewTextAnnotation(200, 540, "text 1", 14)
component comp2=imgDsp.NewTextAnnotation(200, 560, "text 2", 18)
comp1.ComponentSetForegroundColor(0,0,0)
comp2.ComponentSetForegroundColor(0,0,0)
imgDsp.ComponentAddChildAtEnd(comp1)
imgDsp.ComponentAddChildAtEnd(comp2)
img.resetImageDisplay()
//img.setWindowSize(1024,1024)
}
main()
Upvotes: 0
Reputation: 2939
The command you're seeking is void ImageDocumentOptimizeWindow( ImageDocument imgDoc )
but there is a bit more to the story:
You can add annotations (which really are Components
) to any other Component
. An ImageDisplay
is also a specialization of a Component
. Thus, you may either add text as an annotation on an ImageDisplay
- or on an ImageDocument
.
If the first, then the text will move & resize when you move/resize the ImageDisplay, but if you add it to the ImageDocument's root component, it is "side-ordered" to and independent of the ImageDisplay on the page.
Here is a code example for either:
image test := RealImage("Test",4,512,512)
test=icol
test.ShowImage()
imageDisplay disp = test.ImageGetImageDisplay(0)
imageDocument doc = test.ImageGetOrCreateImageDocument()
If ( TwoButtonDialog("Add as part of Image or Page?","Image","Page") )
{
component text1 = NewTextAnnotation( 10, 550, "Under image as part of ImageDisplay", 20)
disp.ComponentAddChildAtEnd(text1)
doc.ImageDocumentOptimizeWindow()
}
else
{
component text2 = NewTextAnnotation( 10, 550, "Under image as part of ImageDocument", 20)
doc.ImageDocumentEnsurePlacedOnPage()
doc.ImageDocumentSwitchToPageMode()
doc.ImageDocumentGetRootComponent().ComponentAddChildAtEnd(text2)
}
To better understand the structure of things, you may want to run a script like the following on an ImageDocument:
void RecursiveListChildren( component parent, string preFix )
{
number numChild = parent.ComponentCountChildren()
Result("\n"+preFix+" [Type "+parent.ComponentGetType()+"]")
for( Number i =0; i<numChild; i++ )
RecursiveListChildren( parent.ComponentGetChild(i), prefix + "..." )
}
component root = GetFrontImageDocument().ImageDocumentGetRootComponent()
ClearResults()
RecursiveListChildren(root,".")
For the two documents of the first script, this will give you:
. [Type 24]
.... [Type 20]
....... [Type 13]
and
. [Type 24]
.... [Type 20]
.... [Type 13]
Upvotes: 0