sources restructured; removed some unused libraries
[k8-i-v-a-n.git] / src / tools / igor.cpp
blob1801f3503f57235c839d0b8792e450fb44d11036
1 #include <algorithm>
2 #include <iostream>
3 #include <fstream>
4 #include <cstdlib>
6 #include "graphics.h"
7 #include "bitmap.h"
8 #include "whandler.h"
9 #include "feio.h"
10 #include "rawbit.h"
11 #include "felist.h"
13 #define STRETCH 5
14 #define TILE_SIZE 16
15 cv2 TILE_V2(TILE_SIZE, TILE_SIZE);
18 int Main (int, char **) {
19 festring OldDirectory;
20 std::ifstream IConfigFile(".igor.rc");
21 if (IConfigFile.is_open()) {
22 char ch;
23 while (IConfigFile.get(ch)) OldDirectory << ch;
25 IConfigFile.close();
26 std::cout << "Where is the graphics directory? ";
28 if (OldDirectory.GetSize()) std::cout << '[' << OldDirectory.CStr() << "] ";
30 festring Directory;
31 char ch;
32 while ((ch = getchar()) != '\n') Directory << ch;
34 if (Directory.IsEmpty()) Directory = OldDirectory;
35 if (!Directory.IsEmpty() && Directory[Directory.GetSize()-1] != '/') Directory << '/';
37 std::ofstream OConfigFile(".igor.rc");
38 OConfigFile << Directory.CStr();
39 OConfigFile.close();
41 graphics::Init();
42 graphics::SetMode("IGOR 1.203", 0, v2(800, 600), false);
43 graphics::LoadDefaultFont(Directory+"Font.pcx");
44 DOUBLE_BUFFER->ClearToColor(0);
46 rawbitmap *CBitmap;
47 felist List(CONST_S("Choose file to edit:"));
48 List.AddEntry(CONST_S("Char.pcx"), LIGHT_GRAY);
49 List.AddEntry(CONST_S("Humanoid.pcx"), LIGHT_GRAY);
50 List.AddEntry(CONST_S("Item.pcx"), LIGHT_GRAY);
51 List.AddEntry(CONST_S("GLTerra.pcx"), LIGHT_GRAY);
52 List.AddEntry(CONST_S("OLTerra.pcx"), LIGHT_GRAY);
53 uShort Selected;
54 festring FileName;
55 List.SetPos(v2(300, 250));
56 List.SetWidth(200);
57 while ((Selected = List.Draw()) & FELIST_ERROR_BIT) if(Selected == ESCAPED) return 0;
58 switch (Selected) {
59 case 0: FileName = CONST_S("Char.pcx"); break;
60 case 1: FileName = CONST_S("Humanoid.pcx"); break;
61 case 2: FileName = CONST_S("Item.pcx"); break;
62 case 3: FileName = CONST_S("GLTerra.pcx"); break;
63 case 4: FileName = CONST_S("OLTerra.pcx"); break;
65 CBitmap = new rawbitmap(Directory + FileName);
66 bitmap CursorBitmap(Directory+"Cursor.pcx");
67 CursorBitmap.ActivateFastFlag();
68 v2 Cursor(0, 0);
69 int k = 0;
70 Selected = 0;
71 packcol16 Color[4] = { MakeRGB16(47, 131, 95), MakeRGB16(123, 0, 127), MakeRGB16(0, 131, 131), MakeRGB16(175, 131, 0) };
72 std::vector<v2> DrawQueue;
73 uChar TempBuffer[256];
74 blitdata B1 = {
75 DOUBLE_BUFFER,
76 { 0, 0 },
77 { RES.X - STRETCH * 16 - 10, RES.Y - STRETCH * 16 - 10 },
78 { TILE_SIZE, TILE_SIZE },
79 { STRETCH }
81 blitdata B2 = {
82 DOUBLE_BUFFER,
83 { 0, 0 },
84 { RES.X - STRETCH * 32 - 20, RES.Y - STRETCH * 16 - 10 },
85 { TILE_SIZE, TILE_SIZE },
86 { STRETCH }
88 blitdata B3 = {
89 DOUBLE_BUFFER,
90 { 0, 0 },
91 { 0, 0 },
92 { TILE_SIZE, TILE_SIZE },
93 { 0 },
94 TRANSPARENT_COLOR
97 for (;;) {
98 static v2 MoveVector[] = { v2(0, -16), v2(-16, 0), v2(0, 16), v2(16, 0) };
99 static int Key[] = { 'w', 'a', 's', 'd' };
100 int c;
101 for (c = 0; c < 4; ++c) {
102 if (Key[c] == k) {
103 v2 NewPos = Cursor+MoveVector[c];
104 if (NewPos.X >= 0 && NewPos.X <= CBitmap->GetSize().X-16 &&
105 NewPos.Y >= 0 && NewPos.Y <= CBitmap->GetSize().Y-16) Cursor = NewPos;
106 break;
108 if ((Key[c]&~0x20) == k) {
109 v2 NewPos = Cursor+(MoveVector[c]<<2);
110 if (NewPos.X >= 0 && NewPos.X <= CBitmap->GetSize().X-16 &&
111 NewPos.Y >= 0 && NewPos.Y <= CBitmap->GetSize().Y-16) Cursor = NewPos;
112 break;
115 if (k >= 0x31 && k <= 0x34) Selected = k-0x31;
116 else if (k == '+') CBitmap->AlterGradient(Cursor, TILE_V2, Selected, 1, false);
117 else if (k == '-') CBitmap->AlterGradient(Cursor, TILE_V2, Selected, -1, false);
118 else if (k == '>') CBitmap->AlterGradient(Cursor, TILE_V2, Selected, 1, true);
119 else if (k == '<') CBitmap->AlterGradient(Cursor, TILE_V2, Selected, -1, true);
120 else if (k == KEY_UP) CBitmap->Roll(Cursor, TILE_V2, v2(0, -1), TempBuffer);
121 else if (k == KEY_DOWN) CBitmap->Roll(Cursor, TILE_V2, v2(0, 1), TempBuffer);
122 else if (k == KEY_RIGHT) CBitmap->Roll(Cursor, TILE_V2, v2(1, 0), TempBuffer);
123 else if (k == KEY_LEFT) CBitmap->Roll(Cursor, TILE_V2, v2(-1, 0), TempBuffer);
124 else if (k == '=') {
125 FONT->Printf(DOUBLE_BUFFER, v2(10, 460), RED, "Select col to swap with [1-4/ESC]");
126 graphics::BlitDBToScreen();
127 for (k = GET_KEY(); k != 0x1B; k = GET_KEY()) {
128 if (k >= 0x31 && k <= 0x34) {
129 CBitmap->SwapColors(Cursor, TILE_V2, Selected, k - 0x31);
130 break;
133 } else if (k == 0x1B) {
134 FONT->Printf(DOUBLE_BUFFER, v2(10, 460), RED, "Save? [y/n/c]");
135 graphics::BlitDBToScreen();
136 for (;;) {
137 k = GET_KEY();
138 if (k == 'y' || k == 'Y') {
139 CBitmap->Save(Directory + FileName);
140 delete CBitmap;
141 return 0;
143 if (k == 'n' || k == 'N') {
144 delete CBitmap;
145 return 0;
147 if (k == 'c' || k == 'C') break;
149 } else if (k == 'p') {
150 std::vector<v2>::iterator i = std::find(DrawQueue.begin(), DrawQueue.end(), Cursor);
151 if (i == DrawQueue.end()) DrawQueue.push_back(Cursor); else DrawQueue.erase(i);
152 } else if (k == 'c') {
153 DrawQueue.clear();
156 DOUBLE_BUFFER->ClearToColor(0);
157 DOUBLE_BUFFER->Fill(0, 0, CBitmap->GetSize(), 0xF81F);
158 CBitmap->MaskedBlit(DOUBLE_BUFFER, v2(0, 0), v2(0, 0), CBitmap->GetSize(), Color);
159 DOUBLE_BUFFER->DrawRectangle(RES.X-STRETCH*16-12, RES.Y-STRETCH*16-12, RES.X-9, RES.Y-9, DARK_GRAY, true);
160 DOUBLE_BUFFER->DrawRectangle(RES.X-STRETCH*32-22, RES.Y-STRETCH*16-12, RES.X-STRETCH*16-19, RES.Y-9, DARK_GRAY, true);
161 B1.Src = Cursor;
162 DOUBLE_BUFFER->StretchBlit(B1);
163 FONT->Printf(DOUBLE_BUFFER, v2(10, 480), WHITE, "Control cursor: wasd and WASD");
164 FONT->Printf(DOUBLE_BUFFER, v2(10, 490), WHITE, "Select m-col: 1-4");
165 FONT->Printf(DOUBLE_BUFFER, v2(10, 500), WHITE, "Safely alter gradient: ±");
166 FONT->Printf(DOUBLE_BUFFER, v2(10, 510), WHITE, "Power alter gradient: <>");
167 FONT->Printf(DOUBLE_BUFFER, v2(10, 520), WHITE, "Swap m-cols: =");
168 FONT->Printf(DOUBLE_BUFFER, v2(10, 530), WHITE, "Push to / pop from draw queue: p");
169 FONT->Printf(DOUBLE_BUFFER, v2(10, 540), WHITE, "Clear draw queue: c");
170 FONT->Printf(DOUBLE_BUFFER, v2(10, 550), WHITE, "Roll picture: arrow keys");
171 FONT->Printf(DOUBLE_BUFFER, v2(10, 570), WHITE, "MColor selected: %d", Selected + 1);
172 FONT->Printf(DOUBLE_BUFFER, v2(10, 580), WHITE, "Current position: (%d, %d)", Cursor.X, Cursor.Y);
174 for (c = 0; c < (int)DrawQueue.size(); ++c) {
175 B2.Src = DrawQueue[c];
176 DOUBLE_BUFFER->StretchBlit(B2);
177 B3.Dest = DrawQueue[c];
178 CursorBitmap.NormalMaskedBlit(B3);
181 B3.Dest = Cursor;
182 CursorBitmap.NormalMaskedBlit(B3);
183 graphics::BlitDBToScreen();
184 k = GET_KEY();
187 return 1;