Added text buffer to editor state, foundation for the text editor
This commit is contained in:
parent
e23be1cd58
commit
322a0960d7
@ -74,7 +74,7 @@ void Graphics::renderVirtualScreen() {
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
DrawTexturePro(m_virtualScreen.texture, m_virtualScreenLocalBounds, m_virtualScreenWindowBounds, m_origin, 0.0f, WHITE);
|
||||
DrawText(std::to_string(GetFPS()).c_str(), 10, 10, 30, YELLOW);
|
||||
//DrawText(std::to_string(GetFPS()).c_str(), 10, 10, 30, YELLOW);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
@ -358,8 +358,6 @@ void Graphics::Text(const std::string& s, int x, int y, int paletteIndex) {
|
||||
for (int i = 0; i < s.size(); ++i) {
|
||||
char c = s[i];
|
||||
std::string bitData = m_currentFont->GetCharData((int)c);
|
||||
|
||||
//std::cout << c << ": " << (int)c << " = " << bitData << std::endl;
|
||||
for (int j = 0; j < bitData.size(); ++j) {
|
||||
if(bitData[j] == '1')
|
||||
Pixel(x + (j % m_currentFont->GetWidth()) + ((m_currentFont->GetWidth() + 1) * i), y + (j / m_currentFont->GetWidth()), paletteIndex);
|
||||
@ -368,6 +366,15 @@ void Graphics::Text(const std::string& s, int x, int y, int paletteIndex) {
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::Char(char c, int x, int y, int paletteIndex) {
|
||||
std::string bitData = m_currentFont->GetCharData((int)c);
|
||||
for (int j = 0; j < bitData.size(); ++j) {
|
||||
if(bitData[j] == '1')
|
||||
Pixel(x + (j % m_currentFont->GetWidth()), y + (j / m_currentFont->GetWidth()), paletteIndex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::updateVMVars(pkpy::VM* vm) {
|
||||
vm->builtins->attr().set("mouseX", pkpy::py_var(vm, mouseX()));
|
||||
vm->builtins->attr().set("mouseY", pkpy::py_var(vm, mouseY()));
|
||||
@ -569,7 +576,12 @@ void Graphics::Img(PycronImage* img, int x, int y) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Graphics::GetCurrentFontWidth(){
|
||||
return m_currentFont->GetWidth();
|
||||
}
|
||||
int Graphics::GetCurrentFontHeight(){
|
||||
return m_currentFont->GetHeight();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -76,9 +76,13 @@ public:
|
||||
void Rect(int x, int y, int width, int height, int paletteIndex);
|
||||
void RectBorder(int x, int y, int width, int height, int paletteIndex);
|
||||
void Text(const std::string& s, int x, int y, int paletteIndex);
|
||||
void Char(char c, int x, int y, int paletteIndex);
|
||||
void Triangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, int paletteIndex);
|
||||
void Img(PycronImage* img, int x, int y);
|
||||
int GetPixel(int x, int y);
|
||||
|
||||
int GetCurrentFontWidth();
|
||||
int GetCurrentFontHeight();
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
struct PycronImage {
|
||||
int width;
|
||||
|
||||
@ -109,8 +109,8 @@ pkpy::PyObject* Pycron::getRandomNumber(pkpy::VM* vm, pkpy::ArgsView args) {
|
||||
float min = pkpy::py_cast<float>(vm, args[0]);
|
||||
float max = pkpy::py_cast<float>(vm, args[1]);
|
||||
// Seed the random number generator with a random device
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
static std::random_device rd;
|
||||
static std::mt19937 gen(rd());
|
||||
|
||||
// Define a uniform distribution for the range [min, max]
|
||||
std::uniform_real_distribution<float> distribution(min, max);
|
||||
|
||||
@ -11,5 +11,7 @@ public:
|
||||
virtual void Draw() = 0;
|
||||
virtual void OnEnter() = 0;
|
||||
virtual void OnExit() = 0;
|
||||
virtual void onKeyPressed(int key) = 0;
|
||||
virtual void OnKeyPressed(int key) = 0;
|
||||
virtual void OnCharPressed(char character) = 0;
|
||||
|
||||
};
|
||||
|
||||
@ -5,8 +5,23 @@
|
||||
#include "EditorState.h"
|
||||
#include "../Graphics/PycronImage.h"
|
||||
|
||||
|
||||
EditorState::EditorState(pkpy::VM *vm, Graphics *graphics) : m_vm(vm), m_graphics(graphics){
|
||||
test = m_graphics->loadImage("resources/plane2.png");
|
||||
|
||||
m_horizontalLetterSpacing = 1;
|
||||
m_verticalLetterSpacing = 1;
|
||||
|
||||
m_charWidth = m_graphics->GetCurrentFontWidth() + m_horizontalLetterSpacing; // Final size of char with spacing. If the literal width of the font is n, the final width is n + spacing.
|
||||
m_charHeight = m_graphics->GetCurrentFontHeight() + m_verticalLetterSpacing;
|
||||
|
||||
m_textWidth = (int)(m_graphics->m_screenWidth / m_charWidth);
|
||||
m_textHeight = (int)(m_graphics->m_screenHeight / m_charHeight);
|
||||
|
||||
m_characterBuffer = std::vector<char>(m_textWidth * m_textHeight);
|
||||
|
||||
Clear();
|
||||
|
||||
}
|
||||
|
||||
EditorState::~EditorState() {
|
||||
@ -16,15 +31,13 @@ EditorState::~EditorState() {
|
||||
void EditorState::Draw() {
|
||||
m_graphics->Clear(1);
|
||||
std::string text = "Editor State";
|
||||
m_graphics->Text(text, m_graphics->m_screenWidth / 2 - (text.size() / 2 * 6), m_graphics->m_screenHeight / 2 - (7 / 2), 5);
|
||||
for (int y = 0; y < 128; ++y) {
|
||||
for (int x = 0; x < 128; ++x) {
|
||||
int c = x;
|
||||
m_graphics->Pixel(x, y, m_graphics->rgbToID(x * 2, y * 2, m_graphics->mouseX()));
|
||||
|
||||
for (int i = 0; i < m_characterBuffer.size(); ++i) {
|
||||
m_graphics->Char(m_characterBuffer[i], (i % m_textWidth) * m_charWidth, (i / m_textWidth) * m_charHeight, 5);
|
||||
}
|
||||
}
|
||||
std::cout << test->width << "\n";
|
||||
m_graphics->Img(test, m_graphics->mouseX() - (test->height / 2), m_graphics->mouseY() - (test->width / 2));
|
||||
Clear();
|
||||
Text("This is a big long test!!!@%)(!*@#%PALSKDGJ", ((float)m_graphics->mouseX() / m_graphics->m_screenWidth) * m_textWidth, ((float)m_graphics->mouseY() / m_graphics->m_screenHeight) * m_textHeight);
|
||||
|
||||
}
|
||||
|
||||
void EditorState::OnEnter() {
|
||||
@ -35,6 +48,30 @@ void EditorState::OnExit() {
|
||||
|
||||
}
|
||||
|
||||
void EditorState::onKeyPressed(int key) {
|
||||
void EditorState::OnKeyPressed(int key) {
|
||||
std::cout << key << ". \n";
|
||||
}
|
||||
|
||||
void EditorState::Clear() {
|
||||
for (int i = 0; i < m_textWidth * m_textHeight; ++i) {
|
||||
m_characterBuffer[i] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
void EditorState::Text(const std::string &text, int x, int y) {
|
||||
for (int i = 0; i < text.size(); ++i) {
|
||||
int charX = x + i;
|
||||
int charY = y;
|
||||
if(charX < 0 || charY < 0 || charX >= m_textWidth || charY >= m_textHeight){
|
||||
return;
|
||||
}
|
||||
char c = text[i];
|
||||
m_characterBuffer[y * m_textWidth + (x + i)] = c;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorState::OnCharPressed(char character) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -12,12 +12,20 @@ public:
|
||||
void Draw() override;
|
||||
void OnEnter() override;
|
||||
void OnExit() override;
|
||||
void onKeyPressed(int key) override;
|
||||
void OnKeyPressed(int key) override;
|
||||
void OnCharPressed(char character) override;
|
||||
|
||||
private:
|
||||
pkpy::VM* m_vm;
|
||||
PycronImage* test;
|
||||
Graphics* m_graphics;
|
||||
int m_charWidth, m_charHeight;
|
||||
int m_textWidth, m_textHeight;
|
||||
int m_horizontalLetterSpacing, m_verticalLetterSpacing;
|
||||
std::vector<char> m_characterBuffer;
|
||||
|
||||
void Clear();
|
||||
void Text(const std::string& text, int x, int y);
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -34,7 +34,7 @@ void GameState::OnExit() {
|
||||
m_updateFunction = m_vm->None;
|
||||
}
|
||||
|
||||
void GameState::onKeyPressed(int key) {
|
||||
void GameState::OnKeyPressed(int key) {
|
||||
|
||||
}
|
||||
|
||||
@ -98,3 +98,7 @@ void GameState::loadPythonModules(std::unordered_map<std::string, std::string> &
|
||||
}
|
||||
}
|
||||
|
||||
void GameState::OnCharPressed(char character) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,9 @@ public:
|
||||
void Draw() override;
|
||||
void OnEnter() override;
|
||||
void OnExit() override;
|
||||
void onKeyPressed(int key) override;
|
||||
void OnKeyPressed(int key) override;
|
||||
void OnCharPressed(char character) override;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user