b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | |
19 | #include <Xw_Extension.h> |
20 | |
b311480e |
21 | /* ifdef then trace on */ |
7fd59977 |
22 | #ifdef TRACE |
23 | #define TRACE_DEF_TILE |
24 | #endif |
25 | |
26 | /* |
27 | STATUS Xw_def_tile (atilemap,index,width,height,cdata): |
28 | XW_EXT_TILEMAP *atilemap |
29 | int index Tile index 0 >= x < MAXTILE |
30 | int width Width of tile in pixels |
31 | int height Height of tile in pixels |
32 | char *cdata Tile description |
33 | |
34 | Update Polygon tile Extended tilemap index with the specified |
35 | bitmap cdata . |
36 | Datas must be defined as one char by bit cdata with value 0 or 1 |
37 | so,cdata array must be defined as char cdata[width][height] |
38 | |
39 | NOTE than tile index 0 is the default Tile (SOLID) |
40 | and cann't be REDEFINED . |
41 | |
42 | Returns ERROR if BadTile Index or Bad tile datas |
43 | Returns SUCCESS if Successful |
44 | |
45 | */ |
46 | |
47 | #ifdef XW_PROTOTYPE |
48 | XW_STATUS Xw_def_tile (void* atilemap, |
49 | int index,int width,int height,char* cdata) |
50 | #else |
51 | XW_STATUS Xw_def_tile (atilemap,index,width,height,cdata) |
52 | void *atilemap; |
53 | int index ; |
54 | int width,height ; |
55 | char *cdata ; |
56 | #endif /*XW_PROTOTYPE*/ |
57 | { |
58 | XW_EXT_TILEMAP *ptilemap = (XW_EXT_TILEMAP*)atilemap ; |
59 | Window root ; |
60 | Screen *screen ; |
61 | unsigned char *pattern ; |
62 | int i,j,l,m,n ; |
63 | |
64 | if ( !Xw_isdefine_tileindex(ptilemap,index) ) { |
65 | /*Bad Tile Index*/ |
66 | Xw_set_error(13,"Xw_def_tile",&index) ; |
67 | return (XW_ERROR) ; |
68 | } |
69 | |
70 | if( width <= 0 || height <= 0 ) { |
71 | /*Bad Tile size*/ |
72 | Xw_set_error(14,"Xw_def_tile",&index) ; |
73 | return (XW_ERROR) ; |
74 | } |
75 | |
76 | if( !cdata ) { |
77 | /*Bad Tile data address*/ |
78 | Xw_set_error(15,"Xw_def_tile",&index) ; |
79 | return (XW_ERROR) ; |
80 | } |
81 | |
82 | if( ptilemap->tiles[index] ) |
83 | XFreePixmap(_PDISPLAY,ptilemap->tiles[index]) ; |
84 | ptilemap->tiles[index] = 0 ; |
85 | |
86 | screen = ScreenOfDisplay(_PDISPLAY,DefaultScreen(_PDISPLAY)) ; |
87 | root = RootWindowOfScreen(screen) ; |
88 | |
89 | pattern = (unsigned char*) Xw_malloc(width*height/8) ; |
90 | pattern[0] = 0x00 ; |
91 | for( i=n=0,l=8 ; i<width ; i++ ) { |
92 | for( j=0 ; j<height ; j++ ) { |
93 | m = i*width + j ; |
94 | pattern[n] |= (cdata[m] & 1) << --l ; |
95 | if( !l ) { |
96 | l = 8 ; |
97 | n++ ; |
98 | pattern[n] = 0x00 ; |
99 | } |
100 | } |
101 | } |
102 | |
103 | ptilemap->tiles[index] = XCreateBitmapFromData(_PDISPLAY,root, |
104 | (char*)pattern,width,height) ; |
105 | Xw_free(pattern) ; |
106 | |
107 | if( !ptilemap->tiles[index] ) { |
108 | /*Tile Bitmap Allocation failed*/ |
109 | Xw_set_error(16,"Xw_def_tile",&index) ; |
110 | return (XW_ERROR) ; |
111 | } |
112 | |
113 | #ifdef TRACE_DEF_TILE |
114 | if( Xw_get_trace() ) { |
115 | printf (" Xw_def_tile(%lx,%d,%d,%d,%lx)\n",(long ) ptilemap,index,width,height,(long ) cdata); |
116 | } |
117 | #endif |
118 | |
119 | return (XW_SUCCESS); |
120 | } |