/* * wGraph.c * * Low-level graphics handling * * © 1994-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Glass. * * Glass is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * Glass is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Glass. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*----- Header files ------------------------------------------------------*/ /* * ANSI standard headers */ #include #include #include /* * Steel headers */ #define _STDAPP #define _LOWLVL #include "steel/Steel.h" #include "steel/bbc.h" #include "steel/colourtran.h" /* * Glass headers */ #include "gStruct.h" #include "gMenus.h" #include "gIcons.h" #include "glass.h" #include "gPrefs.h" #include "window.h" #include "_window.h" /*----- Private variables -------------------------------------------------*/ static int window__dashPos; /* Current rotating dash position */ /*----- Main code ---------------------------------------------------------*/ /* * void window__colourChange(int col1,int col2) * * Use * Sets up the current foreground colour so that when plotted over colour * col1 it looks like col2 and vice-versa. The effects of plotting over * other colours is defined to be psychedelically interesting, but not * pretty. * * Basically, all it does is suss out what the colours really mean and XOR * them together. * * Parameters * int col1,int col2 == the Wimp colour numbers to swap between */ void window__colourChange(int col1,int col2) { wimp_palettestr pal; int x,y; wimpt_noerr(wimp_readpalette(&pal)); wimpt_noerr(colourtran_return_colournumber(pal.c[col1],&x)); wimpt_noerr(colourtran_return_colournumber(pal.c[col2],&y)); if (os_swiv(XOS_SetColour,3,x^y)) { if (wimpt_bpp()==8) { wimpt_noerr(colourtran_colournumbertoGCOL(x^y,&x)); bbc_vduq(18,3,x>>2); bbc_vduq(23,17,2,(x & 3)<<6,0,0,0,0,0,0); } else bbc_vduq(18,3,x^y); } } /* * void window__setXORColour(glass_windPointer *w,int col) * * Use * Sets up the current foreground colour so that it appears to be WIMP * colour col on the specified window background. Lots of tedious * ColourTransing to do on this, with no real reward, but at least it will * look vaguely right in 256 colour modes. * * Parameters * glass_windPointer *w == the window in which to set the colour * int col == the colour to set */ void window__setXORColour(glass_windPointer *w,int col) { int old=w->def->desc.w.colours[3]; /* --- Make sure the background isn't transparent --- */ if (old==255) old=1; window__colourChange(old,col); } /* * void window__makeDashPattern(int ptn) * * Use * Sets the OS dash pattern to the given pattern (only the lowest byte * is considered). * * Parameters * int ptn == the LSB of this word contains the dash pattern as a bit * pattern */ void window__makeDashPattern(int ptn) { int byte1,byte2; byte1=242; byte2=8; wimpt_noerr(os_byte(163,&byte1,&byte2)); /* Dot-dash length */ bbc_vduq(23,6,ptn,ptn,ptn,ptn,ptn,ptn,ptn,ptn); } /* * void window__setDash(void) * * Use * Sets the dashed pattern so that it looks as if a 'rotating' box is being * dragged, like the WIMP's, only better... The box is set up so that a * SINGLE exclusive-or plot will move the dash round. */ #define SECTION(x,i) ((((x)<<(i)) & 0xff00) >> 8) void window__setDash(void) { int dash=SECTION(0xFCFCFC,window__dashPos); int newDash; window__dashPos+=2; if (window__dashPos>7) window__dashPos=0; newDash=SECTION(0xFCFCFC,window__dashPos); dash^=newDash; window__makeDashPattern(dash); window__setXORColour(window__dragWind(),window__DRAGCOL); } /* * void window__rotate(int by) * * Use * Rotates the current rotating-dash pattern by a given amount. This is * used to rotate the dash box while the box is moving. * * Parameters * int by == the number of steps to rotate the dash pattern. */ void window__rotate(int by) { window__dashPos+=by; if (window__dashPos<0) window__dashPos=6; else if (window__dashPos>7) window__dashPos=0; window__makeDashPattern(SECTION(0xFCFCFC,window__dashPos)); window__setXORColour(window__dragWind(),window__DRAGCOL); } /* * void window__rectangle(int x,int y,int w,int h) * * Use * Draws a rectangle, using the current dotted line pattern * * Parameters * int x == the left side of the rectangle * int y == the right side of the rectangle * int w == the width of the rectangle (may be <0) * int h == the height of the rectangle (may be <0) */ void window__rectangle(int x,int y,int w,int h) { bbc_plot(bbc_DottedBoth+bbc_MoveCursorAbs,x,y); bbc_plot(bbc_DottedBoth+bbc_DrawRelFore,0,h); bbc_plot(bbc_DottedExInit+bbc_DrawRelFore,w,0); bbc_plot(bbc_DottedExInit+bbc_DrawRelFore,0,-h); bbc_plot(bbc_DottedExBoth+bbc_DrawRelFore,-w,0); }