VPI Picture

Discussions related to Visual Prolog
User avatar
Ferenc Nagy
VIP Member
Posts: 289
Joined: 24 Apr 2007 12:26

Where is this pictureCanvas code embedded?

Unread post by Ferenc Nagy » 5 Aug 2013 13:47

Paul,

I want to define a graphic window in a VIP 7.3 program.
I practiced drawing of function graphs in version 5.2.
There I could define a bare window from the main screen of the development environment.
It seems to me in 7.3 that I cannot define bare windows but only forms and dialogs.
If I understand well other posts of this forum I have to embed the code corresponding to your one in a form.

Is it true?

The next question is:
Forms are modal.
I have a form where I ask the limits of the drawing area [minX, maxX, minY, maxY].
May I call another form from the onOKClick event which does not have controls at all?
This way the picture canvas can be bigger than if it is in a sub-rectangle of the limit-asking form.
TIA, Regards,
Frank Nagy

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 5 Aug 2013 17:00

Frank,
In the main Task window, I did create a form to do a bunch of things. within that was a picture control to display the image when i was doing single image updates/modifications.

However, when I did batch processing, it was all done in the background, only the main task window showing. No forms or dialigs that I remember.

start a the very bottom at cyclethrough(). you should only need to follw the code through one of the drawGraphics predicates to see what did.

P.

Code: Select all

implement batchGraphics     open core, vpiDomains   constants     className = "psc/batchMorse/batchGraphics".     classVersion = "1.0".   clauses     classInfo(className, classVersion).     class facts - text_to_encode     raw_Input_text:string:="".     picWin : pictureCanvas := erroneous.     controlRCT : rct := rct(0,0,256,256).     titleFontSize : positive := 10.     textToEncode : (string) nondeterm.     dot : char := '.'.     dash : char := '-'.     class facts - word_list     words : (string) nondeterm.     wordFile : string := "".     wordname : (string, string) nondeterm.         clauses wordname("-","hypen"). wordname(".","period"). wordname("?","question"). wordname(",","comma"). wordname(":","colon"). wordname("(","open paren"). % [...]   class predicates     getDot:().     getDash:().   clauses     getDot():-         std::repeat,         hasDomain(char,D),         D =   string::getCharFromValue(math::random(128-33) + 33),         D <> '\"', D <> ' ',         !,         dot := D.             getDot().           getDash():-         std::repeat,         hasDomain(char,D),         D =   string::getCharFromValue(math::random(128-33) + 33),         D <> '\"', D <> ' ',         D <> dot,         !,         dash := D.             getDash().   class predicates     randomColor : (color Fore [out],color Back [out]) determ.     clauses      randomColor(Fore, Back):-         Fore = convert(color, math::random(65000)),         std::repeat,         B = convert(color,math::random(65000)),         B<> Fore,         !,         Back = B.     class predicates     randomGrey : (color Fore [out],color Back [out]) determ.     clauses      randomGrey(Fore, Back):-         F = convert(color, math::random(255)),         std::repeat,         B = convert(color,math::random(255)),         B<> F,         !,         Fore = vpi::composeRGB(F,F,F),         Back = vpi::composeRGB(B,B,B).       class predicates     drawGraphicMorse:(integer).     drawGraphicISOMorse:(integer).   clauses     drawGraphicISOMorse(INint ):-         IN = toString(INint),         controlRCT = rct(_X1,_Y1,X2,Y2),         picWin := pictureCanvas::new(256,256), % black on white         Fore = color_black,         Back = color_white,   % sets the inverse white on black %        Fore = color_white, %        Back = color_black,   % sets random colors for front and back %        randomColor(Fore, Back),   % Sets greys for front and back %        randomGrey(Fore, Back),           picWin : setForeColor(Fore),         picWin : setbackColor(Back),         picWin : setBrush(brush(pat_Solid, Back)),         picWin : drawFloodFill(pnt(1,1), Back),           getDot(),         getDash(),                 DOT = string::replaceAll(toString(dot), "'", ""),         DASH = string::replaceAll(toString(dash), "'", ""),                 translateor::setISOMORPHS(DOT,DASH ),           RAW = raw_Input_text,           translateor::translateor(RAW, _MOrse, ISOMORPH),           XT =convert(integer, math::random(220)),         YT = convert(integer, math::random(220)),         picWin : drawTextInRect(rct(XT,YT,X2,Y2),ISOMORPH, [dtext_Left ,dtext_Wordbreak]),         PIC = picWin : getPicture(),         wordname(RAW, NAME),         FileName = string::concat( "isoMORSE ",/*RAW*/NAME,"-", IN, ".BMP"),         vpi::pictSave(PIC, FileName),         fail.             drawGraphicISOMorse(INint ):-         IN = toString(INint),         controlRCT = rct(_X1,_Y1,X2,Y2),         picWin := pictureCanvas::new(256,256), % black on white %        Fore = color_black, %        Back = color_white,   % sets the inverse white on black         Fore = color_white,         Back = color_black,   % sets random colors for front and back %        randomColor(Fore, Back),   % Sets greys for front and back %        randomGrey(Fore, Back),           picWin : setForeColor(Fore),         picWin : setbackColor(Back),         picWin : setBrush(brush(pat_Solid, Back)),         picWin : drawFloodFill(pnt(1,1), Back),           getDot(),         getDash(),                 DOT = string::replaceAll(toString(dot), "'", ""),         DASH = string::replaceAll(toString(dash), "'", ""),                 translateor::setISOMORPHS(DOT,DASH ),           RAW = raw_Input_text,           translateor::translateor(RAW, _MOrse, ISOMORPH),           XT =convert(integer, math::random(220)),         YT = convert(integer, math::random(220)),         picWin : drawTextInRect(rct(XT,YT,X2,Y2),ISOMORPH, [dtext_Left ,dtext_Wordbreak]),         PIC = picWin : getPicture(),         wordname(RAW, NAME),         FileName = string::concat( "isoinvMORSE ",/*RAW*/NAME,"-", IN, ".BMP"),         vpi::pictSave(PIC, FileName),         fail.                 drawGraphicISOMorse(_INint):-!.       drawGraphicMorse(INint):-         IN = toString(INint),         controlRCT = rct(_X1,_Y1,X2,Y2),         picWin := pictureCanvas::new(256,256), % sets black on white         Fore = color_black,         Back = color_white,   % sets the inverse white on black %        Fore = color_white, %        Back = color_black,   % sets random colors for front and back %        randomColor(Fore, Back),   % Sets greys for front and back %        randomGrey(Fore, Back),           picWin : setForeColor(Fore),         picWin : setbackColor(Back),         picWin : setBrush(brush(pat_Solid, Back)),         picWin : drawFloodFill(pnt(1,1), Back),           RAW = raw_Input_text,           translateor::translateor(RAW, MOrse, _ISOMORPH),           XT =convert(integer, math::random(220)),         YT = convert(integer, math::random(220)),         picWin : drawTextInRect(rct(XT,YT,X2,Y2),MOrse, [dtext_Left ,dtext_Wordbreak]),         PIC = picWin : getPicture(),         wordname(RAW, NAME),         FileName = string::concat("MORSE ",/* RAW*/NAME, "-", IN, ".BMP"),         vpi::pictSave(PIC, FileName),         fail.       drawGraphicMorse(INint):-         IN = toString(INint),         controlRCT = rct(_X1,_Y1,X2,Y2),         picWin := pictureCanvas::new(256,256), % sets black on white %        Fore = color_black, %        Back = color_white,   % sets the inverse white on black         Fore = color_white,         Back = color_black,   % sets random colors for front and back %        randomColor(Fore, Back),   % Sets greys for front and back %        randomGrey(Fore, Back),           picWin : setForeColor(Fore),         picWin : setbackColor(Back),         picWin : setBrush(brush(pat_Solid, Back)),         picWin : drawFloodFill(pnt(1,1), Back),           RAW = raw_Input_text,           translateor::translateor(RAW, MOrse, _ISOMORPH),           XT =convert(integer, math::random(220)),         YT = convert(integer, math::random(220)),         picWin : drawTextInRect(rct(XT,YT,X2,Y2),MOrse, [dtext_Left ,dtext_Wordbreak]),         PIC = picWin : getPicture(),         wordname(RAW, NAME),         FileName = string::concat("invMORSE ",/* RAW*/NAME, "-", IN, ".BMP"),         vpi::pictSave(PIC, FileName),         fail.       drawGraphicMorse(_INint):-!.      class predicates     loadTextToEncode:().     copy_to_text_to_encode:().      clauses      loadTextToEncode():-        directory::setCurrentDirectory("E:/research/SourcePhotos/Set -1-2"),         file::consult(wordFile, word_list),         copy_to_text_to_encode.                  copy_to_text_to_encode():-             retract(words(X)),               assert(textToEncode(X)),             fail.         copy_to_text_to_encode().                 class predicates     randomFontSize:().   clauses     randomFontSize():-         std::repeat,         hasDomain(positive, T),         T = math::random(24),         T > 8,         !,         titleFontSize := T.     randomFontSize().      class predicates     cycleThrough:().    clauses     cycleThrough():-         %retract value off database         retract(textToEncode(X)),         raw_Input_text:= X,            % set the new folder         directory::setCurrentDirectory("E:/research/SourcePhotos/Phase 1 Training and TEst/Set 1-1-1/morse"),         % create the MOrse version        foreach Counter = std::fromTo(1,1000) do             %  create 10 different version, using for loop.             randomFontSize(),             drawGraphicMorse(Counter)        end foreach,                  % create the IsoMorse versions          % set the new folder         directory::setCurrentDirectory("E:/research/SourcePhotos/Phase 1 Training and TEst/Set 1-1-1/isomorse"),        foreach Counter = std::fromTo(1,1000) do          %  create 10 different version, using for loop.             randomFontSize(),             drawGraphicISOMorse(Counter)        end foreach,                memory::garbageCollect(),                 fail.               cycleThrough().           clauses  batchMorse():-        wordFile:="words morse.txt",          loadTextToEncode(),      cycleThrough().       end implement batchGraphics
AI Rules!
P.

User avatar
Ferenc Nagy
VIP Member
Posts: 289
Joined: 24 Apr 2007 12:26

Where did you see your controlRCT?

Unread post by Ferenc Nagy » 6 Aug 2013 6:24

Paul,

Thank you for the code.
Where did you see your controlRCT?
In the task window of your program?
TIA, Regards,
Frank Nagy

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 6 Aug 2013 11:47

Where did you see your controlRCT?
In the task window of your program?
do you mean where could I visually see what I drew?

in single image mode, yes, there was a bitmap control in a dialog on the task window. for Batch mode (which is what the above code is from) there was no visual presentation. I fI wanted to see the image, I would use MS Paint or some other image viewer.
AI Rules!
P.

User avatar
Ferenc Nagy
VIP Member
Posts: 289
Joined: 24 Apr 2007 12:26

Why don't I see the text "Morse"?

Unread post by Ferenc Nagy » 6 Aug 2013 15:04

Hi,
I tried to use a picture canvas within a group box of a form.

Code: Select all

predicates     onDraw_butClick : button::clickResponder. clauses     onDraw_butClick(Source) = button::noAction:-         storeView(devi:disp:coor:number,devi:disp:coor:system),         onPaint(This,canvas_gb:getRect(),getWindowGDI()),         vpiCommonDialogs::note("Draw").
...

Code: Select all

onPaint(Source, Rectangle, GDI) :-         % 2013.08.06. Test         canvas_gb:getSize(W,H),         PicWin = pictureCanvas::new(W,H),         PicWin:setFont(vpi::fontCreateByName("Andale Mono",32)),         PicWin:setForeColor(color_Red),         PicWin:setBackColor(color_Black),         PicWin:setBackMode(bk_Opaque),         PicWin:drawTextInRect(Rectangle,"Morse", [dtext_center ,dtext_vcenter]),         programControl::sleep(5000),         Ready=PicWin:getPicture().
This code is within a form.
The "canvas_gb" is an empty group box.
I see only the note "Draw" but I do not see the text "Morse".
Why?
Attachments
pikk 023.png
Sketch of form.
pikk 023.png (14.65 KiB) Viewed 1657 times
TIA, Regards,
Frank Nagy

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 7 Aug 2013 0:17

If I can dig up my whoel application for creating my sample images I will upload it.

One thing I do remember is I did seem to have lots of problems early on, this only seems to work with BMP images. when I tried using JPGs, PNGs and others I seemed to have lots of problems.

P.
AI Rules!
P.

User avatar
Ferenc Nagy
VIP Member
Posts: 289
Joined: 24 Apr 2007 12:26

User friendly inventions

Unread post by Ferenc Nagy » 7 Aug 2013 8:47

Hi Paul,

Maybe I select the simple window and "old" VPI graphics instead of "new" but cumbersome Picture Canvas and Window GDI.
There is a rather fresh topic:
General Window Constructions
in this forum.

I remember that I suffered much with metrics, print jobs and other "user friendly inventions" of VIP 5.2 graphics.

Once upon a time Turbo Prolog 1.0 invented a makewindow statement with ONLY 7 THAT IS SEVEN parameters.
Even earlier the cabinet where I gave up my box 900 punched cards was decorated with a picture of a lion made of "*" characters.
TIA, Regards,
Frank Nagy

Post Reply