/* Copyright (C) 2011, Stephane Bisaro, aka iri License : you can do what you want with this source code This code is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */ /* How to create a no-square window in Scol with the 2dGraphic API ? This API is the most commonly used to build this style of window. 1 - Create a window. You must set the flag to WN_TRANSPARENCY. 2 - Add in the window a container. 3 - Load or create an AlphaBitmap to the background. Either a transparency color or an alpha layer or both to define the transparent zone and the opaque zone. Black and white are often used. 4 - Add a CompBitmap object with this background in the container 5 - Set the function _SETcontainerTransparency 6 - Paint the container See http://www.scolring.org/files/doc_html/_setcontainertransparency.html To move the window, the user clicks on the window, press the button and drag it. When he releases the mouse button, the move stops. Click >> Drag >> Mouse moves >> Window moves You must define two callback : - when the user clicks - when the user releases (unclick) In a first time, we define the cursorMove callback : it will move the window in calculate the difference between old and new mouse coordinates. In a second time, this last callback will be nil, so inactivated and the window can not move. */ /* These functions allows the user to move the interface when he press the mouse button. See above */ fun CBmove (objcontainer, user_parameter, xmove, ymove, maskmouse)= let user_parameter -> [window xold yold] in let _GETwindowPositionSize window -> [winx winy _ _] in let [winx+(xmove-xold) winy+(ymove-yold)] -> [xnew ynew] in _POSITIONwindow window xnew ynew 405 336; 0;; fun CBclick (objcontainer, window, xclick, yclick, btnmouse, maskmouse)= _CBcontainerCursorMove objcontainer @CBmove [window xclick yclick]; 0;; fun CBunclick (objcontainer, user_parameter, xclick, yclick, btnmouse, maskmouse)= _CBcontainerCursorMove objcontainer nil nil; 0;; fun CBleave (objcontainer, user_parameter)= _CBcontainerCursorMove objcontainer nil nil; 0;; /* To close this application : all resources and all objects are destroyed before the VM ... */ fun CBclose (compbitmap, user_parameter, xclick, yclick, btnmouse, maskmouse)= let user_parameter -> [window container background logo png1 png2 png3 font msg] in ( _DScompBitmap background; _DScompBitmap logo; _DScompBitmap compbitmap; _DScompText msg; _DSalphaBitmap png1; _DSalphaBitmap png2; _DSalphaBitmap png3; _DScontainer container; _DSfont font; _DSwindow window; _closemachine );; /* The main function. See comments above and below Prototype : fun [] I */ fun main ()= _showconsole; // we create a window with the flag WN_TRANSPARENCY. let _CRwindow _channel nil 50 50 405 336 WN_TRANSPARENCY " Examples > Window > Nosquare" -> window in // we add a container inside the window let _CRcontainerFromObjWin _channel window 0 0 405 336 CO_CHILDINSIDE|CO_NOBORDER 0 "" -> container in // we load the background let _LDalphaBitmap _channel _checkpack "tutorials/window/nosquare.png" -> png1 in // we include a CompBitmap with the background inside the entire container let _CRcompBitmap _channel container nil [0 0] OBJ_ENABLE|OBJ_VISIBLE OBJ_CONTAINER_ALLEVENTS png1 0 0 405 336 -> background in // we add a button to close the VM let _LDalphaBitmap _channel _checkpack "tutorials/window/close.png" -> png2 in let _CRcompBitmap _channel container nil [365 30] OBJ_ENABLE|OBJ_VISIBLE OBJ_CONTAINER_CLICK png2 0 0 36 26 -> close in // we add a logo, for fun and see the transparency ... let _LDalphaBitmap _channel _checkpack "tutorials/window/logo.png" -> png3 in let _CRcompBitmap _channel container nil [200 20] OBJ_ENABLE|OBJ_VISIBLE 0 png3 0 0 64 64 -> logo in // we add a text field, for fun and see the transparency ... let _CRfont _channel 20 0 0 "arial" -> font in let _CRcompText _channel container nil [5 170] OBJ_ENABLE|OBJ_VISIBLE|CT_LABEL|CT_CENTER OBJ_CONTAINER_ALLEVENTS 395 25 "Scol is a free language" font [0xFFFFFF 0 0 0] nil nil nil -> msg in ( // a click and the VM is destroyed _CBcompBitmapClick close @CBclose [window container background logo png1 png2 png3 font msg]; // to move the interface (see above) _CBcontainerClick container @CBclick window; _CBcontainerUnClick container @CBunclick 0; _CBcontainerCursorLeave container @CBleave 0; // configure the transparency _SETcontainerTransparency container 0xffffff nil WN_TRANS_COLOR; // repaint the container to takes all childs and parameters _PAINTcontainer container; 0 );;