This repository has been archived on 2026-04-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Tortuga/editor/editor_scene.cpp
T
Kayne Ruse 29928c0b92 Added a draw function to the pager
I'm also committing some simple debugging code in the scene.
2013-10-04 02:18:10 +10:00

142 lines
3.4 KiB
C++

/* Copyright: (c) Kayne Ruse 2013
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "editor_scene.hpp"
#include "utility.hpp"
#include <iostream>
#include <cstdio>
using namespace std;
//-------------------------
//Public access members
//-------------------------
EditorScene::EditorScene() {
//32 * 32 sized tiles
pager.SetWidth(32*4);
pager.SetHeight(32*4);
pager.SetOnNew([](Region* const ptr){
printf("New Region: %d, %d\n", ptr->GetX(), ptr->GetY());
});
pager.SetOnDelete([](Region* const ptr){
printf("Delete Region: %d, %d\n", ptr->GetX(), ptr->GetY());
});
sheetList.push_front(TileSheet());
TileSheet* sheetOne = &sheetList.front();
sheetList.push_front(TileSheet());
TileSheet* sheetTwo = &sheetList.front();
sheetOne->LoadSurface("rsc\\terrain.bmp", 32, 32);
sheetTwo->LoadSurface("rsc\\terrain.bmp", 32, 32);
cout << "--Sheet debug data--" << endl;
cout << "TileSheet::rangeEnd: " << TileSheet::GetRangeEnd() << endl;
cout << "sheetOne.totalCount: " << sheetOne->GetTotalCount() << endl;
cout << "sheetOne.begin: " << sheetOne->GetBegin() << endl;
cout << "sheetOne.end: " << sheetOne->GetEnd() << endl;
cout << "sheetTwo.totalCount: " << sheetTwo->GetTotalCount() << endl;
cout << "sheetTwo.begin: " << sheetTwo->GetBegin() << endl;
cout << "sheetTwo.end: " << sheetTwo->GetEnd() << endl;
cout << "--end debug data--" << endl;
}
EditorScene::~EditorScene() {
//
}
//-------------------------
//Frame loop
//-------------------------
void EditorScene::FrameStart() {
//
}
void EditorScene::Update(double delta) {
//
}
void EditorScene::FrameEnd() {
//
}
void EditorScene::Render(SDL_Surface* const screen) {
pager.DrawTo(screen, &sheetList, 0, 0);
}
//-------------------------
//Event handlers
//-------------------------
void EditorScene::MouseMotion(SDL_MouseMotionEvent const& motion) {
//
}
void EditorScene::MouseButtonDown(SDL_MouseButtonEvent const& button) {
switch(button.button) {
case SDL_BUTTON_LEFT: {
Region* ptr = pager.GetRegion(
snapToBase(pager.GetWidth(), button.x),
snapToBase(pager.GetHeight(), button.y)
);
cout << "New Tile: " <<
ptr->NewTileA({
snapToBase(32, button.x),
snapToBase(32, button.y),
0,
32,
32,
incrementer
})
<< endl;
;
if (++incrementer >= TileSheet::GetRangeEnd()) {
incrementer = 0;
}
}
}
}
void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//
}
void EditorScene::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
}
}
void EditorScene::KeyUp(SDL_KeyboardEvent const& key) {
//
}