view multipaint.pde @ 244:c7748c19e1ff default tip

Update notes.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 23 Oct 2018 11:34:25 +0300
parents 7401300452c2
children
line wrap: on
line source

//
// Multipaint.JS v18.10.2018
// Tero Heikkinen (Dr. TerrorZ)
// ProcessingJS port and changes by Matti Hämäläinen (ccr/TNSP)
// processing setup draw and file things here
//

// Supported
final int C64 = 0, MSX = 5, SPECTRUM = 6, C64M = 10,
    PLUS4 = 9, PLUS4M = 19, CPC = 2;

// Experimental or incomplete
final int C64NOLIMIT = 32; // Commodore 64 without attribute limitations
final int C64FLI = 20, C64FLIM = 21; // incomplete FLI & AFLI modes
final int TIMEX = 7, JR200 = 8, AMIGA = 11, ATARIST = 12;
final int PICO8 = 88;
final int UNIA = 33;
final int COCO3 = 34;
final int BK0010 = 99;
final int QLLOW = 66;

// Reserved but completely unimplemented
final int VIC = 22; // VIC-20
final int CGA = 23; // 320 x 200 PC CGA screen with black, white, cyan, magenta
final int CGAX = 24; // 320 x 200 PC CGA screen with black, yellow, green, red-ish
final int EGA = 200; // 320 x 200 PC EGA screen, 16 colors of 64
final int VGA = 255; // 320 x 200 PC VGA screen, 256 colors of 65536
final int NES = 90; // 8-bit NES
final int SEGAM = 91; // 8-bit Sega Master System

final int GRIDMODE_OLD = 0;
final int GRIDMODE_NEW = 1;
final int AR_FLAT = 1;
final int AR_SQUARE = 0;

final int PEESEE = 0, MACOSX = 1, PSJS = 2;
final int COMMAND = 157; // Marq's cmd/ctrl solution

int g_machine = -1; // change this to autoselect
int platform = PSJS;

int[] g_grids = new int[16];

int[] g_r = new int[266];
int[] g_g = new int[266];
int[] g_b = new int[266];
int[] g_rgb = new int[266];

byte[] g_map = new byte[88000];
byte[] g_fillmap = new byte[88000];
byte[] g_rmap = new byte[88000];
byte[] g_icons = new byte[88000];
byte[] g_brush = new byte[88000];
byte[] g_template = new byte[16384];
byte[] g_redo = new byte[1024];
byte[] g_remdo = new byte[1024];
int[] g_chaup = new int[64];
byte[] g_data = new byte[1024];
int[] g_magpix = new int[64];
int[] g_magpiy = new int[64];

byte g_realfront, g_realback;

int g_tooltrigger, g_prevtool, g_rband, g_rbang, g_boxreconstruct,
    g_charlimit, g_animx, g_animy, g_animframes, g_animno, g_animtime,
    g_animspeed, g_keymacpos, g_forced_width, g_forced_height,
    g_hadjust, g_vadjust;

int g_wheelup = int(':'), g_wheeldown = int(';'), g_middlebutton = int(',');
int g_gridmode = GRIDMODE_OLD;
int g_pixelw = 1;
int g_aspect = AR_SQUARE;

boolean g_control = false, g_shift = false, g_alt = false,
    g_dirty, g_inhibit_aspect = false;

String g_formatname, g_formatext,
    filename = "", sfilename = "",
    g_name, g_exportext = "",
    g_exportname = "", g_keymacro = "",
    g_forced_palette = "";


//dimensions
int X, Y, MX, MY;
//generic mouse
boolean g_klikkeri, g_iconmode = false;
int g_ofx, g_ofy, g_button, g_realbutton, g_mx, g_my, g_orx, g_ory, g_msx, g_msy;
//rubberband,mouse
int g_phase, g_rx, g_ry, g_rx2, g_ry2, g_rubbermode;
int g_prex, g_prey, g_storedcoordx, g_storedcoordy;
//window positioning
int g_windowx, g_windowy, g_maglocx, g_maglocy;
int g_hedge, g_vedge, g_uiscale, g_wzoom;
//icons & gui stuff
int g_iconx, g_icony, g_piconx, g_picony;
int g_gridx, g_gridy, g_spare;
int g_farge, g_backg, g_ofarge, g_repanel, g_msgctr;
//machine related color properties
int g_attrimode, g_britemode, g_multic, g_backmode, g_maxcolors, g_hzoomer;
float g_palsteps;
//brush, tool parameters
int g_bsourcex, g_bsourcey, g_bsourcex2, g_bsourcey2;
int g_bsize, g_btype;


void setup()
{
    // Get settings from Javascript runner, or use defaults
    g_machine = (mpMachine >= 0) ? mpMachine : C64;
    g_uiscale = (mpUIScale >= 1 && mpUIScale <= 3) ? mpUIScale : 2;
    g_forced_width = mpUIForcedWidth > 0 ? mpUIForcedWidth : 0;
    g_forced_height = mpUIForcedHeight > 0 ? mpUIForcedHeight : 0;
    g_forced_palette = mpUIPalette ? mpUIPalette : "";
    g_animspeed = 1;

    mpHideGUI();

    //normi
    g_magpix[0] = 3;
    g_magpix[1] = 8;
    g_magpix[2] = 16;
    g_magpiy[0] = 3;
    g_magpiy[1] = 8;
    g_magpiy[2] = 16;

    //mini
    g_magpix[10] = 2;
    g_magpix[11] = 6;
    g_magpix[12] = 16;
    g_magpiy[10] = 2;
    g_magpiy[11] = 6;
    g_magpiy[12] = 16;

    //maxi
    g_magpix[20] = 4;
    g_magpix[21] = 16;
    g_magpix[22] = 32;
    g_magpiy[20] = 4;
    g_magpiy[21] = 16;
    g_magpiy[22] = 32;

    //FLAT normi
    g_magpix[100] = 3;
    g_magpix[101] = 9;
    g_magpix[102] = 12;
    g_magpiy[100] = 2;
    g_magpiy[101] = 6;
    g_magpiy[102] = 8;

    //FLAT mini
    g_magpix[110] = 3;
    g_magpix[111] = 9;
    g_magpix[112] = 12;
    g_magpiy[110] = 2;
    g_magpiy[111] = 6;
    g_magpiy[112] = 8;

    //FLAT maxi
    g_magpix[120] = 6;
    g_magpix[121] = 12;
    g_magpix[122] = 21;
    g_magpiy[120] = 4;
    g_magpiy[121] = 8;
    g_magpiy[122] = 14;

    // Setup other stuff
    if (g_uiscale >= 1 && g_uiscale <= 3)
        g_wzoom = g_uiscale + 1;

    g_hedge = 32 * g_uiscale;
    g_vedge = 32 * g_uiscale;

    g_spare = 0;
    g_bsize = 0;
    g_btype = 0;
    g_phase = 0;
    g_button = LEFT;

    g_data[int('f')] = 1; // fill on
    g_data[int('g')] = 1; // grid on
    g_data[int('m')] = 0;
    g_data[int('M')] = 0; // mags off

    set_tool(3);

    g_gridx = 8;
    g_gridy = 8;
    g_multic = 0;
    g_repanel = -2;

    mpSetupMachine(g_machine);
    mpSetUIColors();

    g_icons = mpLoadBinaryFile("icons.bin");

    if (g_forced_palette.length() > 3)
        mpLoadPalette(g_forced_palette);

    int truwinsizex = X * g_magpix[magmode()];
    int truwinsizey = Y * g_magpiy[magmode()];

    if (g_forced_width == 0 || g_forced_height == 0)
    {
        g_hadjust = 0;
        g_vadjust = 0;

        int hsize = truwinsizex + g_hedge + (22) * g_wzoom;
        int vsize = truwinsizey + g_vedge + (14) * g_wzoom;

        while (vsize - g_vedge < (12 * 16) * g_wzoom)
            vsize += 2;

        while (hsize - g_hedge < (17 * 16) * g_wzoom)
            hsize += 2;

        size(hsize, vsize);
    }

    if (g_forced_width > 800 && g_forced_height > 600)
        size(g_forced_width, g_forced_height);

    if (g_inhibit_aspect)
        g_aspect = AR_SQUARE;

    int paspect = g_wzoom;
    if (g_aspect == AR_FLAT)
    {
        if (g_wzoom == 2) paspect = 1;
        if (g_wzoom == 3) paspect = 2;
        if (g_wzoom == 4) paspect = 3;
    }

    g_windowx = width - (g_hedge) - (truwinsizex);
    g_windowx = g_windowx / 2;
    g_windowy = height - (g_vedge) - (truwinsizey);
    g_windowy = g_windowy / 2;

    if (g_hadjust > 0)
        g_windowx = width - (g_hedge) - (g_wzoom * X) - g_hadjust;

    if (g_vadjust > 0)
        g_windowy = height - (g_vedge) - (paspect * Y) - g_vadjust;

    switcher(3);

    g_map[4] = byte(g_maxcolors - 1);
    g_ofarge = g_farge;
    MX = int(X / 8);
    MY = int(Y / 8);
    g_realfront = byte(g_farge);
    g_realback = byte(g_backg);

    for (int y = 0; y < Y; y++)
    for (int x = 0; x < X; x++)
        absolute_clearpoint(x, y);

    switcher(2);
    noStroke();
    background(g_r[263], g_g[263], g_b[263]);
    sussborder();
    setup_raster();

    message(" Multipaint| .JS 2018 -|v18.10.2018");
    message("*");
    g_dirty = true;
}


void mpSetUIColors()
{
    // UI colors
    makecolor(256, 0xff, 0, 0xff);
    makecolor(257, 180, 180, 180);
//    g_rgb[257] = 0xff808080;
    makecolor(258, 0, 0, 0);
    makecolor(259, 48, 48, 48);

    // R,G and B for the palette sliders
    makecolor(260, 255, 0, 0);
    makecolor(261, 0, 255, 0);
    makecolor(262, 0, 0, 255);
    makecolor(263, 48, 48, 48); //backest UI background
}


function mpDisplayGUI()
{
    var velem = stGE("mpUI");
    if (velem)
    {
        stClearChildren(velem);
        velem.style.display = "block";
        velem.style.background = "red";
        velem.focus();
    }
    return velem;
}


function mpHideGUI()
{
    var velem = stGE("mpUI");
    if (velem)
    {
        velem.style.display = "none";
        stClearChildren(velem);
    }
    return velem;
}


void mpSetTitle(String str)
{
    console.log("TITLE: '" + str + "'");
}


void draw()
{
    if (!focused)
    {
        g_control = false;
        g_shift = false;
    }

    // If there should be no update, do not update.
    if (!g_dirty && !g_rubbermode)
        return;
    g_dirty = false;

    // Animate animbrush
    if (g_data[int('n')] == 1)
    {
        if (++g_animtime > 8 - g_animspeed * 2)
        {
            animbrush_do();
            g_animtime = 0;
        }
    }

    // Update some mouse variables
    if (g_data[int('m')] == 0 && g_data[int('M')] == 0)
    {
        g_mx = g_msx - g_windowx;
        g_my = g_msy - g_windowy;
    }
    else
    {
        g_mx = mouseX;
        g_my = mouseY;
    }

    g_msx = mouseX;
    g_msy = mouseY;

    // Actual tool drawing
    if (g_tooltrigger == 1 &&
        g_mx <= width - g_hedge &&
        g_my <= height - g_vedge)
        do_tool(g_mx, g_my, g_button);

    switcher(0);

    for (int i = 0; i < 1024; i++)
        g_remdo[i] = 0;

    // Tool drawing for shows
    int savebut = g_button;
    int tt = tool();
    if (tt != 5)
    {
        if (g_phase == 0)
            g_button = LEFT;
        do_tool(g_mx, g_my, LEFT);
    }
    else
        storecoords(g_mx, g_my);

    if (tt == 6) do_line(g_rx, g_ry, g_rx2, g_ry2, 0);
    if (tt == 7) do_circle(g_rx, g_ry, g_rx2, g_ry2);
    if (tt == 8) do_rectangle(g_rx, g_ry, g_rx2, g_ry2);
    g_button = savebut;

    // Screen update stuff
    loadPixels();
    viewport();
    switcher(1);

    if (g_pgrab)
        preview_box_drag();

    preview_window();
    update_ui(false);
    updatePixels();

    // Message control
    if (g_msgctr > 0)
        g_msgctr--;

    // Macro handling
    if (g_keymacro.length() > g_keymacpos)
    {
        macro_command(g_keymacro.charAt(g_keymacpos));
        g_keymacpos++;
    }
}