1 /*
2 	C-Dogs SDL
3 	A port of the legendary (and fun) action/arcade cdogs.
4 	Copyright (c) 2014, 2016, 2019-2020 Cong Xu
5 	All rights reserved.
6 
7 	Redistribution and use in source and binary forms, with or without
8 	modification, are permitted provided that the following conditions are met:
9 
10 	Redistributions of source code must retain the above copyright notice, this
11 	list of conditions and the following disclaimer.
12 	Redistributions in binary form must reproduce the above copyright notice,
13 	this list of conditions and the following disclaimer in the documentation
14 	and/or other materials provided with the distribution.
15 
16 	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 	POSSIBILITY OF SUCH DAMAGE.
27 */
28 #pragma once
29 
30 #include <stdbool.h>
31 
32 #include <cdogs/c_array.h>
33 #include <cdogs/mission.h>
34 #include <cdogs/vector.h>
35 
36 // Point: draw as long as mouse is down; to smooth input draws a line from
37 //        last known position to current position
38 // Line: draw line from mouse down position to mouse up position
39 // Box: draw box outline from mouse down position to mouse up position
40 // Box filled: like box but with filled interior
41 // Room: special type of box; the outline is always wall and the interior is
42 //       always room
43 // Select: draw outline and drag contents to another location
44 // Add item: add items to the map
45 typedef enum
46 {
47 	BRUSHTYPE_POINT,
48 	BRUSHTYPE_LINE,
49 	BRUSHTYPE_BOX,
50 	BRUSHTYPE_BOX_FILLED,
51 	BRUSHTYPE_BOX_AND_FILL,
52 	BRUSHTYPE_SELECT,
53 	BRUSHTYPE_FILL,
54 	BRUSHTYPE_SET_PLAYER_START,
55 	BRUSHTYPE_ADD_ITEM,
56 	BRUSHTYPE_ADD_CHARACTER,
57 	BRUSHTYPE_ADD_OBJECTIVE,
58 	BRUSHTYPE_ADD_KEY,
59 	BRUSHTYPE_ADD_PICKUP,
60 	BRUSHTYPE_SET_KEY,
61 	BRUSHTYPE_SET_EXIT
62 } BrushType;
63 
64 // Encapsulates the drawing brushes and draws tiles to a static mission
65 // There are main and secondary types corresponding to mouse left and right
66 // BrushSize is the size of the stroke
67 // HighlightedTiles are the tiles that are highlighted to show the brush
68 // stroke
69 typedef struct
70 {
71 	BrushType Type;
72 	union {
73 		int ItemIndex;
74 		const MapObject *MapObject;
75 		const PickupClass *Pickup;
76 	} u;
77 	int Index2;
78 	int MainType;
79 	int SecondaryType;
80 	int PaintType;
81 	int IsActive;
82 	int IsPainting;
83 	int BrushSize;
84 	struct vec2i LastPos;
85 	struct vec2i Pos;
86 	CArray HighlightedTiles; // of struct vec2i
87 	struct vec2i SelectionStart;
88 	struct vec2i SelectionSize;
89 	int IsMoving;		  // for the select tool, whether selecting or moving
90 	struct vec2i DragPos; // when moving, location that the drag started
91 
92 	char GuideImage[CDOGS_PATH_MAX];
93 	Pic GuideImagePic;
94 	Uint8 GuideImageAlpha;
95 } EditorBrush;
96 
97 void EditorBrushInit(EditorBrush *b);
98 void EditorBrushTerminate(EditorBrush *b);
99 
100 void EditorBrushSetHighlightedTiles(EditorBrush *b);
101 typedef enum
102 {
103 	EDITOR_RESULT_NONE,
104 	EDITOR_RESULT_CHANGED,
105 	EDITOR_RESULT_RELOAD,
106 	// Note: deliberately set so that bit checking works, i.e.
107 	// er & EDITOR_RESULT_CHANGED, er & EDITOR_RESULT_RELOAD
108 	EDITOR_RESULT_CHANGED_AND_RELOAD,
109 	EDITOR_RESULT_CHANGE_TOOL,
110 } EditorResult;
111 #define EDITOR_RESULT_NEW(_change, _reload)                                   \
112 	(EditorResult)((!!(_change)) | (!!(_reload) << 1))
113 EditorResult EditorBrushStartPainting(EditorBrush *b, Mission *m, int isMain);
114 EditorResult EditorBrushStopPainting(EditorBrush *b, Mission *m);
115 
116 bool EditorBrushTryLoadGuideImage(EditorBrush *b, const char *filename);
117