Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 123 lines (103 sloc) 3.545 kB
e61c024 @DusteDdk Updated copyleft header.
authored
1 /************************************************************************
2 * This file is part of Wizznic. *
3 * Copyright 2009-2012 Jimmy Christensen <dusted@dusted.dk> *
4 * Wizznic is free software: you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation, either version 3 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * Wizznic is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
aa80153 @DusteDdk Nuked all windows newlines.
authored
15 * along with Wizznic. If not, see <http://www.gnu.org/licenses/>. *
e61c024 @DusteDdk Updated copyleft header.
authored
16 ************************************************************************/
17
17733f1 @DusteDdk More pointer work, not finished.
authored
18 #include "pointer.h"
19 #include "ticks.h"
20 #include "defs.h"
21 #include "sprite.h"
22 #include "pixel.h"
bba53ed @DusteDdk Updated the readme, and did some minor fixes in the menu.
authored
23 #include "input.h"
17733f1 @DusteDdk More pointer work, not finished.
authored
24
25 static inpPointerState_t inpPointer;
26 static SDL_Surface* ptrBackImg;
27 static SDL_Rect ptrBackRect;
28
29 inline inpPointerState_t* getInpPointerState()
30 {
31 return(&inpPointer);
32 }
33
34 void initPointer(SDL_Surface* screen)
35 {
36 //Load the "escape" overlay image
ab86871 @DusteDdk Fixed warning in pc.c, fixed ptr-back.png path.
authored
37 ptrBackImg = loadImg(DATADIR"data/ptr-back.png");
17733f1 @DusteDdk More pointer work, not finished.
authored
38 if( !ptrBackImg )
ab86871 @DusteDdk Fixed warning in pc.c, fixed ptr-back.png path.
authored
39 printf("Couldn't open %s\n",DATADIR"data/ptr-back.png");
17733f1 @DusteDdk More pointer work, not finished.
authored
40
41 ptrBackRect.x=0;
42 ptrBackRect.y=0;
43 ptrBackRect.w=ptrBackImg->w;
5fc258f @DusteDdk Tweaked mouse-brick-behaviour in leveleditor.
authored
44 ptrBackRect.h=ptrBackImg->h;
17733f1 @DusteDdk More pointer work, not finished.
authored
45
46 memset( &inpPointer, 0, sizeof(inpPointerState_t) );
47 inpPointer.timeSinceMoved=POINTER_SHOW_TIMEOUT;
48
49 //The color white
50 inpPointer.colWhite = SDL_MapRGBA( screen->format, 255,255,255,255 );
51
52 }
53
54 inline void drawPointer(SDL_Surface* screen)
55 {
56 if( inpPointer.timeSinceMoved < POINTER_SHOW_TIMEOUT )
57 {
58 //Update pointer-holddown time
59 if(inpPointer.isDown)
60 inpPointer.downTime += getTicks();
61
777626b @DusteDdk Incomplete, need backup, disk might die.
authored
62 if( inpPointer.escEnable )
63 {
64 inpPointer.escEnable=0;
65 SDL_BlitSurface( ptrBackImg, NULL, screen,NULL);
66 }
17733f1 @DusteDdk More pointer work, not finished.
authored
67
68 plotPixel(screen, inpPointer.vpX, inpPointer.vpY-2, inpPointer.colWhite );
69 plotPixel(screen, inpPointer.vpX, inpPointer.vpY+2, inpPointer.colWhite );
70
71 plotPixel(screen, inpPointer.vpX-2, inpPointer.vpY, inpPointer.colWhite );
72 plotPixel(screen, inpPointer.vpX+2, inpPointer.vpY, inpPointer.colWhite );
73
74 }
75 }
76
cc41166 @DusteDdk More cursor work, still not done.
authored
77 //The mousepointer is only "clicked" the first iteration that it is held down (when downTime is still 0)
78 //So, if the downtime is 0, then there is a chance that it is being hold down.
17733f1 @DusteDdk More pointer work, not finished.
authored
79 int_fast8_t isPointerClicked()
80 {
cc41166 @DusteDdk More cursor work, still not done.
authored
81 if( inpPointer.downTime==0 )
17733f1 @DusteDdk More pointer work, not finished.
authored
82 {
cc41166 @DusteDdk More cursor work, still not done.
authored
83 return(inpPointer.isDown);
17733f1 @DusteDdk More pointer work, not finished.
authored
84 }
85 return(0);
86 }
87
8cbb588 @DusteDdk Fixed braino and tweaked mouse-brick-select screen in editor.
authored
88 int_fast8_t isPointerInBox( SDL_Rect* r )
5fc258f @DusteDdk Tweaked mouse-brick-behaviour in leveleditor.
authored
89 {
90 if( r->x < inpPointer.vpX && r->w > inpPointer.vpX && r->y < inpPointer.vpY && r->h > inpPointer.vpY )
91 {
92 inpPointer.hitABox=1;
93 return(1);
94 }
8cbb588 @DusteDdk Fixed braino and tweaked mouse-brick-select screen in editor.
authored
95 return(0);
5fc258f @DusteDdk Tweaked mouse-brick-behaviour in leveleditor.
authored
96 }
97
17733f1 @DusteDdk More pointer work, not finished.
authored
98 int_fast8_t isBoxClicked( SDL_Rect* r )
99 {
100 if( isPointerClicked() )
101 {
5fc258f @DusteDdk Tweaked mouse-brick-behaviour in leveleditor.
authored
102 return( isPointerInBox(r));
17733f1 @DusteDdk More pointer work, not finished.
authored
103 }
104 return(0);
105 }
106
107 int_fast8_t isPointerEscapeClicked()
108 {
109 if( inpPointer.escEnable && isBoxClicked( &ptrBackRect ) )
110 {
111 inpPointer.hitABox=0;
bba53ed @DusteDdk Updated the readme, and did some minor fixes in the menu.
authored
112 resetMouseBtn();
17733f1 @DusteDdk More pointer work, not finished.
authored
113 return(1);
114 }
115 return(0);
116 }
117
118 int_fast8_t isAnyBoxHit()
119 {
120 return(inpPointer.hitABox);
121 }
777626b @DusteDdk Incomplete, need backup, disk might die.
authored
122
Something went wrong with that request. Please try again.