Skip to content

Commit

Permalink
add demo version
Browse files Browse the repository at this point in the history
  • Loading branch information
lets-all-be-stupid-forever committed Jan 3, 2025
1 parent 2970fcd commit d5f58b6
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 165 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
cmake-build-*
third_party/*.gz
build
build-demo
wip
todo.txt
sdk
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
OPTION(OPENMP "Use OpenMP for thread detection")
OPTION(STEAM "Steam support")
OPTION(DEMO "Demo Version")

IF (DEMO)
add_compile_definitions(DEMO_VERSION=1)
ENDIF()

IF (OPENMP)
find_package(OpenMP REQUIRED)
Expand Down
126 changes: 0 additions & 126 deletions src/api_web.c

This file was deleted.

9 changes: 9 additions & 0 deletions src/clip_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include "img.h"

Image ImageFromClipboard() {
#ifdef DEMO_VERSION
{
Image r = {0, 0, 0, 0, 0};
return r;
}
#endif
clip::image img;
if (!clip::get_image(img)) {
// std::cout << "Error getting image from clipboard\n";
Expand Down Expand Up @@ -51,6 +57,9 @@ Image ImageFromClipboard() {
}

void ImageToClipboard(Image img) {
#ifdef DEMO_VERSION
return;
#endif
clip::image_spec spec;
spec.width = img.width;
spec.height = img.height;
Expand Down
5 changes: 1 addition & 4 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define COLOR_EQ(u, v) \
(((u).r == (v).r) && ((u).g == (v).g) && ((u).b == (v).b) && ((u).a == (v).a))

#ifndef WEB
#ifndef DEMO_VERSION
// Maximum image size is 8k.
// For images bigger than that, a dedicated exporter/reader is necessary
// (stb_image blocks at 8k by default)
Expand Down Expand Up @@ -38,9 +38,6 @@
#define rect_start ((Rectangle){16 * 0, 16 * 1, 13, 13})
#define rect_stop ((Rectangle){16 * 2, 16 * 1, 13, 13})

// Icon of the sandbox challenge for the WEB version, which doesn't have lua.
#define rect_sandbox ((Rectangle){368, 80, 33, 33})

// Logo of CircuitArtist (for About page)
#define rect_logo ((Rectangle){160, 80, 158, 67})

Expand Down
12 changes: 0 additions & 12 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <omp.h>
#endif

#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#endif

#ifdef WIN32
#ifndef CA_SHOW_CONSOLE
// This pragma hides the console app terminal in window.
Expand All @@ -16,8 +12,6 @@
#endif
#endif

static void WebUpdateDrawFrame(void); // Update and Draw one frame

static Ui _ui = {0};

int main() {
Expand All @@ -31,9 +25,6 @@ int main() {
omp_set_num_threads(nt);
#endif

#if defined(PLATFORM_WEB)
emscripten_set_main_loop(web_update_draw_frame, 0, 1);
#else
SetExitKey(0); // Avoids window closing with escape key
SetTargetFPS(60);
SetTraceLogLevel(LOG_ERROR);
Expand All @@ -43,10 +34,7 @@ int main() {
break;
}
}
#endif
UiUnload(&_ui);
CloseWindow();
return 0;
}

void WebUpdateDrawFrame() { UiUpdateFrame(&_ui); }
8 changes: 7 additions & 1 deletion src/paint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,13 @@ void PaintHandleCameraMovement(Paint* ca) {
}
}

bool PaintGetIsDirty(Paint* ca) { return HistGetIsDirty(&ca->h); }
bool PaintGetIsDirty(Paint* ca) {
#ifdef DEMO_VERSION
return false;
#else
return HistGetIsDirty(&ca->h);
#endif
}

Image PaintGetSelBuffer(Paint* ca) { return HistGetSelBuffer(&ca->h); }

Expand Down
4 changes: 0 additions & 4 deletions src/w_about.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ static void AboutUpdateLayout() {
int total_w = bw + 2 * 2;
int x = (sw - total_w) / 2;
int bh = 9 * 35 * s;
#ifdef WEB
// Making it smaller for the web version
bh = 4 * 35 * 2;
#endif
int total_h = (bh + 35 * 1 + 35 * 1);
int pad = 10 * s;
while (total_h + 2 * pad + 10 > sh) {
Expand Down
56 changes: 38 additions & 18 deletions src/w_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,11 @@ void MainInit(Ui* ui) {
C.header_size = 24 * ui->scale;
C.bottom_size = 3 * 17 * 1 * ui->scale - 6 * ui->scale;

#ifdef WEB
C.btn_challenge.disabled = true;
C.btn_tutorial.disabled = true;
C.btn_new.disabled = true;
#ifdef DEMO_VERSION
C.btn_save.disabled = true;
C.btn_saveas.disabled = true;
C.btn_open.disabled = true;
C.btn_exit.disabled = true;
#endif

PaintLoad(&C.ca);
LevelOptions* opt = ApiGetLevelOptions();
if (!opt->startup_image_path) {
Expand Down Expand Up @@ -198,17 +194,18 @@ void MainUpdate(Ui* ui) {

void MainUpdateControls(Ui* ui) {
MainUpdateHud(ui);
#ifndef WEB
if (IsKeyPressed(KEY_TAB)) {
TutorialOpen(ui);
}
#endif
if (IsKeyPressed(KEY_F10)) {
ui->debug = !ui->debug;
}

#ifndef DEMO_VERSION
if (IsKeyPressed(KEY_S) && IsKeyDown(KEY_LEFT_CONTROL)) {
MainOnSaveClick(ui, false);
}
#endif

bool mouse_on_target = MainGetIsCursorInTargeTimage() && ui->hit_count == 0;
C.mouse_on_target = mouse_on_target;
Expand Down Expand Up @@ -376,10 +373,8 @@ void MainUpdateHud(Ui* ui) {
if (BtnUpdate(&C.btn_clockopt[5], ui)) PaintSetClockSpeed(&C.ca, 5);

if (BtnUpdate(&C.btn_simu, ui)) PaintToggleSimu(&C.ca);
#ifndef WEB
if (BtnUpdate(&C.btn_challenge, ui)) LevelsOpen(ui);
if (BtnUpdate(&C.btn_tutorial, ui)) TutorialOpen(ui);
#endif

Vector2 pos = GetMousePosition();
if (RectHover(C.fg_color_rect, pos)) {
Expand Down Expand Up @@ -457,6 +452,17 @@ void MainDraw(Ui* ui) {
sprintf(txt, "Drag to resize");
}
FontDrawTexture(txt, 0, 0, WHITE);

#ifdef DEMO_VERSION
const char msg1[] = "Max image size in demo version is 512x512";
const char msg2[] = "Full version available on Steam.";
rlTranslatef(0, -14, 0);
FontDrawTexture(msg2, 2, 2, BLACK);
FontDrawTexture(msg2, 0, 0, RED);
rlTranslatef(0, -14, 0);
FontDrawTexture(msg1, 2, 2, BLACK);
FontDrawTexture(msg1, 0, 0, RED);
#endif
rlPopMatrix();
EndScissorMode();
}
Expand Down Expand Up @@ -488,7 +494,6 @@ void MainDraw(Ui* ui) {
bool simu_on = PaintGetMode(&C.ca) == MODE_SIMU;
BtnDrawIcon(&C.btn_simu, bscale, ui->sprites,
simu_on ? rect_stop : rect_start);
#ifndef WEB
// {
// int x = C.btn_challenge.hitbox.x;
// int y = C.btn_challenge.hitbox.y - 10 * 2;
Expand All @@ -506,10 +511,6 @@ void MainDraw(Ui* ui) {
sprintf(txt, "Lvl: %s", co->options[cd->ilevel].name);
BtnDrawText(&C.btn_challenge, bscale, txt);
}

#else
BtnDrawIcon(&C.btn_challenge, bscale, ui->sprites, rect_sandbox);
#endif
BtnDrawText(&C.btn_tutorial, bscale, "Tutorial");

bool color_disabled = PaintGetMode(&C.ca) != MODE_EDIT;
Expand Down Expand Up @@ -578,13 +579,23 @@ void MainDraw(Ui* ui) {
if (ui->window == WINDOW_MAIN) {
BtnDrawLegend(&C.btn_new, bscale, "New Image");
BtnDrawLegend(&C.btn_open, bscale, "Load Image");
BtnDrawLegend(&C.btn_save, bscale, "Save Image (C-S)");
BtnDrawLegend(&C.btn_saveas, bscale, "Save Image As...");
BtnDrawLegend(&C.btn_about, bscale, "About Circuit Artist");
BtnDrawLegend(&C.btn_exit, bscale, "Exit");

BtnDrawLegend(&C.btn_sel_open, bscale, "Load Selection from Image");

#ifndef DEMO_VERSION
BtnDrawLegend(&C.btn_save, bscale, "Save Image (C-S)");
BtnDrawLegend(&C.btn_saveas, bscale, "Save Image As...");
BtnDrawLegend(&C.btn_sel_save, bscale, "Save Selection as Image");
#else
BtnDrawLegend(&C.btn_save, bscale,
"Save Image (C-S)\n`Not available in demo version.`");
BtnDrawLegend(&C.btn_saveas, bscale,
"Save Image As...\n`Not available in demo version.`");
BtnDrawLegend(&C.btn_sel_save, bscale,
"Save Selection as Image\n`Not available in demo version.`");

#endif

BtnDrawLegend(
&C.btn_simu, bscale,
Expand Down Expand Up @@ -931,9 +942,15 @@ void MainDrawStatusBar(Ui* ui) {
sprintf(txt, "[level] %s", co->options[cd->ilevel].name);
FontDrawTextureOutlined(txt, xc, yc7, tc, bg);

#ifndef DEMO_VERSION
const char* fname = GetFileName(MainGetFilename());
sprintf(txt, "[img] %s", fname);
FontDrawTextureOutlined(txt, xc, yc8, tc, bg);
#else
const char* msg = "[Demo] Full version available on Steam.";
FontDrawTextureOutlined(msg, xc, yc8, tc, RED);
#endif

Image img = PaintGetEditImage(&C.ca);
sprintf(txt, "[img] w: %d h: %d", img.width, img.height);
FontDrawTextureOutlined(txt, xc, yc9, tc, bg);
Expand Down Expand Up @@ -1032,6 +1049,9 @@ void MainUpdateWidgets() {

C.btn_sel_open.disabled = ned;
C.btn_sel_save.disabled = !has_sel || ned;
#ifdef DEMO_VERSION
C.btn_sel_save.disabled = true;
#endif

C.btn_rotate.hidden = (tool != TOOL_SEL) || ned;
C.btn_flipv.hidden = (tool != TOOL_SEL) || ned;
Expand Down

0 comments on commit d5f58b6

Please sign in to comment.