/* 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 2dOS API ? This API is less used to build this style of window but this is possible. 1 - Create a window. You must set the flag to WN_TRANSPARENCY. 3 - Load or create an AlphaBitmap / ObjBitmap 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 - Blit this ObjBitmap in the window 5 - Set the function _SETwindowTransparency 6 - Paint the window The flag WN_TRANSPARENCY is imperative, otherwise the window doesn't transparent. Usually, others falgs are useless. Of course, in this case, you must code all user interactions : close and move window for example. In this example, click in the window with the right or middle button to close it et destroy the VM. To move the window, clicks with the left button and drag it. To move the window, the user clicks on the window, press the left 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. */ /* When the window must be painted, the whole background is blitted. This background define the transparent and opaque zones See http://www.scolring.org/files/doc_html/_bltbitmap.html Prototype : fun [ObjWin ObjBitmap] I */ fun CBpaint (window, bmp)= _BLTbitmap window bmp 0 0; 0;; /* CBmove, CBunclick, CBclick allows to move the window See above for more explanations */ fun CBmove (window, user_parameter, xmove, ymove, maskmouse)= let user_parameter -> [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 CBunclick (window, user_parameter, xclick, yclick, btnmouse)= _CBcursorMove window nil nil; 0;; fun CBclick (window, user_parameter, xclick, yclick, btn)= if btn == MB_LBUTTON then // if left button, then move window ( _CBcursorMove window @CBmove [xclick yclick]; _CBwinUnclick window @CBunclick 0; 0 ) else // else the VM is destroyed let user_parameter -> [png bmp bmp8] in ( _DSbitmap bmp; _DSalphaBitmap png; _DSbitmap8 bmp8; _DSwindow window; _closemachine );; /* The main function See http://www.scolring.org/files/doc_html/_setwindowtransparency.html Prototype : fun [] I */ fun main ()= _showconsole; // we create a window with the flag WN_TRANSPARENCY. Give a name can be important to show it in the task bar let _CRwindow _channel nil 50 50 405 336 WN_TRANSPARENCY " Examples > Window > Nosquare" -> window in // we load an AlphaBitmap (this might have been a ObjBitmap) let _LDalphaBitmap _channel _checkpack "tutorials/window/nosquare.png" -> png in // we can not blit an AlphaBitmap here, we separate it (bitmap, alpha layer) let _GETalphaBitmaps png -> [bmp bmp8] in ( // paint callback to blit the whole bitmap in the window _CBwinPaint window @CBpaint bmp; // click callback to move the window or destroy the VM _CBwinClick window @CBclick [png bmp bmp8]; // call the paint window _PAINTwindow window; // define the transparency parameter _SETwindowTransparency window 0xffffff nil WN_TRANS_COLOR; _CRtext _channel window 5 155 395 20 ET_DOWN|ET_ALIGN_CENTER "Scol is a free language !"; 0 );;