Color palette test, Mouse test
This commit is contained in:
parent
b8fcb14d0c
commit
2427e3b672
99
main.cpp
99
main.cpp
@ -1,4 +1,5 @@
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include "pocketpy.h"
|
||||
#include "raylib.h"
|
||||
|
||||
@ -14,24 +15,54 @@ int startupScreenHeight = virtualScreenHeight * initialScale;
|
||||
int screenWidth = startupScreenWidth;
|
||||
int screenHeight = startupScreenHeight;
|
||||
|
||||
void calculateBounds(Rectangle& bounds, Vector2& origin) {
|
||||
Rectangle virtualScreenBounds;
|
||||
Vector2 origin;
|
||||
|
||||
Color ColorFromHex(int hexValue) {
|
||||
// Extract red, green, blue, and alpha components from the hexadecimal value
|
||||
int r = (hexValue >> 16) & 0xFF;
|
||||
int g = (hexValue >> 8) & 0xFF;
|
||||
int b = hexValue & 0xFF;
|
||||
|
||||
// Normalize the color components to the range [0, 1]
|
||||
float rf = static_cast<float>(r) / 255.0f;
|
||||
float gf = static_cast<float>(g) / 255.0f;
|
||||
float bf = static_cast<float>(b) / 255.0f;
|
||||
|
||||
// Create and return the color
|
||||
return ColorFromNormalized({ rf, gf, bf, 1.0f }); // Alpha is set to 1.0 (fully opaque)
|
||||
}
|
||||
|
||||
void calculateBounds() {
|
||||
|
||||
float ar = (float)virtualScreenWidth / (float)virtualScreenHeight;
|
||||
float nar = (float)screenWidth / (float)screenHeight;
|
||||
|
||||
if(nar > ar) {
|
||||
bounds.height = screenHeight;
|
||||
bounds.width = bounds.height * ar;
|
||||
origin.x = -(screenWidth / 2.0f - (bounds.width / 2.0f));
|
||||
virtualScreenBounds.height = screenHeight;
|
||||
virtualScreenBounds.width = virtualScreenBounds.height * ar;
|
||||
origin.x = -(screenWidth / 2.0f - (virtualScreenBounds.width / 2.0f));
|
||||
origin.y = 0;
|
||||
}else {
|
||||
bounds.width = screenWidth;
|
||||
bounds.height = bounds.width / ar;
|
||||
virtualScreenBounds.width = screenWidth;
|
||||
virtualScreenBounds.height = virtualScreenBounds.width / ar;
|
||||
origin.x = 0;
|
||||
origin.y = -(screenHeight / 2.0f - (bounds.height / 2.0f));
|
||||
origin.y = -(screenHeight / 2.0f - (virtualScreenBounds.height / 2.0f));
|
||||
}
|
||||
}
|
||||
|
||||
int mouseX(){
|
||||
int x = GetMouseX();
|
||||
float adjX = x + origin.x;
|
||||
return adjX / virtualScreenBounds.width * virtualScreenWidth;
|
||||
}
|
||||
|
||||
int mouseY(){
|
||||
int y = GetMouseY();
|
||||
float adjY = y + origin.y;
|
||||
return adjY / virtualScreenBounds.height * virtualScreenHeight;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
SetTraceLogLevel(LOG_ERROR);
|
||||
@ -41,17 +72,29 @@ int main() {
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
|
||||
InitWindow(startupScreenWidth, startupScreenHeight, "test");
|
||||
SetTargetFPS(-1);
|
||||
SetTargetFPS(60);
|
||||
|
||||
RenderTexture2D virtualScreen = LoadRenderTexture(virtualScreenWidth, virtualScreenHeight);
|
||||
Rectangle sourceRec = { 0.0f, 0.0f, (float)virtualScreen.texture.width, -(float)virtualScreen.texture.height };
|
||||
Rectangle virtualScreenBounds;
|
||||
Vector2 origin;
|
||||
calculateBounds(virtualScreenBounds, origin);
|
||||
calculateBounds();
|
||||
|
||||
pkpy::VM* vm = new pkpy::VM();
|
||||
|
||||
Texture2D logo = LoadTexture("resources/img.png");
|
||||
Texture2D mouse = LoadTexture("resources/mouse.png");
|
||||
|
||||
// Load palette
|
||||
vector<Color> palette;
|
||||
|
||||
ifstream paletteFile("resources/palette2.hex");
|
||||
string line;
|
||||
|
||||
if(paletteFile.is_open()){
|
||||
while(getline(paletteFile, line)){
|
||||
palette.push_back(ColorFromHex(stoi(line, nullptr, 16)));
|
||||
}
|
||||
paletteFile.close();
|
||||
}
|
||||
|
||||
try {
|
||||
pkpy::CodeObject_ code = vm->compile("return 'test'", "main.py", pkpy::EXEC_MODE, false);
|
||||
@ -62,12 +105,16 @@ int main() {
|
||||
|
||||
}
|
||||
|
||||
HideCursor();
|
||||
|
||||
while(!WindowShouldClose()) {
|
||||
|
||||
|
||||
if (IsWindowResized() && !IsWindowFullscreen())
|
||||
{
|
||||
screenWidth = GetScreenWidth();
|
||||
screenHeight = GetScreenHeight();
|
||||
calculateBounds(virtualScreenBounds, origin);
|
||||
calculateBounds();
|
||||
}
|
||||
|
||||
if (IsKeyPressed(KEY_F)) {
|
||||
@ -83,22 +130,34 @@ int main() {
|
||||
screenHeight = GetMonitorHeight(monitor);
|
||||
ToggleFullscreen();
|
||||
}
|
||||
calculateBounds(virtualScreenBounds, origin);
|
||||
calculateBounds();
|
||||
}else if(IsKeyPressed(KEY_I)){
|
||||
flip = !flip;
|
||||
}
|
||||
|
||||
BeginTextureMode(virtualScreen);
|
||||
ClearBackground(BLUE);
|
||||
ClearBackground(palette[1]);
|
||||
DrawText(("Hello World " + to_string(GetFPS()) + " FPS").c_str(), 5, 5, 5, RAYWHITE);
|
||||
DrawTexture(logo, 80 + cos(GetTime()) * (virtualScreenHeight / 4), (virtualScreenHeight / 2) + sin(GetTime()) * (virtualScreenHeight / 4) - 29, WHITE);
|
||||
DrawLineBezier((Vector2){80, 20}, (Vector2){virtualScreenWidth - 5, virtualScreenHeight - 5}, 1, GREEN);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 15, GREEN);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 13, YELLOW);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 11, ORANGE);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 9, RED);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 7, PURPLE);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 5, BLUE);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 15, palette[31]);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 13, palette[28]);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 11, palette[16]);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 9, palette[15]);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 7, palette[51]);
|
||||
DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 5, palette[47]);
|
||||
|
||||
DrawRectangle(3, 19, 33, 33, BLACK);
|
||||
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
DrawRectangle(4 + i * 4, 20 + j * 4, 3, 3, palette[i + j * 8]);
|
||||
}
|
||||
}
|
||||
|
||||
DrawTexture(mouse, mouseX(), mouseY(), WHITE);
|
||||
DrawText(to_string(mouseX()).c_str(), 2, 70, 5, palette[37]);
|
||||
DrawText(to_string(mouseY()).c_str(), 2, 78, 5, palette[27]);
|
||||
|
||||
EndTextureMode();
|
||||
|
||||
|
||||
BIN
resources/mouse.png
Normal file
BIN
resources/mouse.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 194 B |
64
resources/palette2.hex
Normal file
64
resources/palette2.hex
Normal file
@ -0,0 +1,64 @@
|
||||
2e222f
|
||||
3e3546
|
||||
625565
|
||||
966c6c
|
||||
ab947a
|
||||
694f62
|
||||
7f708a
|
||||
9babb2
|
||||
c7dcd0
|
||||
ffffff
|
||||
6e2727
|
||||
b33831
|
||||
ea4f36
|
||||
f57d4a
|
||||
ae2334
|
||||
e83b3b
|
||||
fb6b1d
|
||||
f79617
|
||||
f9c22b
|
||||
7a3045
|
||||
9e4539
|
||||
cd683d
|
||||
e6904e
|
||||
fbb954
|
||||
4c3e24
|
||||
676633
|
||||
a2a947
|
||||
d5e04b
|
||||
fbff86
|
||||
165a4c
|
||||
239063
|
||||
1ebc73
|
||||
91db69
|
||||
cddf6c
|
||||
313638
|
||||
374e4a
|
||||
547e64
|
||||
92a984
|
||||
b2ba90
|
||||
0b5e65
|
||||
0b8a8f
|
||||
0eaf9b
|
||||
30e1b9
|
||||
8ff8e2
|
||||
323353
|
||||
484a77
|
||||
4d65b4
|
||||
4d9be6
|
||||
8fd3ff
|
||||
45293f
|
||||
6b3e75
|
||||
905ea9
|
||||
a884f3
|
||||
eaaded
|
||||
753c54
|
||||
a24b6f
|
||||
cf657f
|
||||
ed8099
|
||||
831c5d
|
||||
c32454
|
||||
f04f78
|
||||
f68181
|
||||
fca790
|
||||
fdcbb0
|
||||
Loading…
Reference in New Issue
Block a user