// Dwg_HelloWorld.cpp  file ==============
// generated by pfodWeb Designer Arduino Export V1.1.5 -- 19th September 2025
/*   
 * (c)2025 Forward Computing and Control Pty. Ltd.
 * NSW Australia, www.forward.com.au
 * This code is not warranted to be fit for any purpose. You may only use it at your own risk.
 * This generated code may be freely used for both private and commercial use
 * provided this copyright is maintained.
 */

#include "Dwg_HelloWorld.h"
#include <pfodDebugPtr.h>

//#define DEBUG
static Print* debugPtr = NULL;  // local to this file

Dwg_HelloWorld dwg_HelloWorld;


static unsigned long dwgRefresh = 0;

Dwg_HelloWorld::Dwg_HelloWorld() {
  initialized = false;
}

void Dwg_HelloWorld::init() {
  if (initialized) {
    return;
  }
  initialized = true;
  (void)debugPtr;  // suppress unused warning
#ifdef DEBUG
  debugPtr = getDebugPtr();
#endif
  pfodDrawing::init();
}

// return true if handled else false
// either handle cmd here or in main sketch
bool Dwg_HelloWorld::processDwgCmds() {
// byte dwgCmd = parserPtr->parseDwgCmd(); // pfodParse calls this automagically before calling this method
  if (!(*(parserPtr->getDwgCmd()))) {  // ==> getDwgCmd returned pointer to empty string
    return false; // not dwg cmd, not handled
  }

  // if (debugPtr) { debugPtr->print("dwgCmd did not match:"); debugPtr->println(cmd_c1); }
  return false; // not handled
}

bool Dwg_HelloWorld::sendDwg() {
  if (!parserPtr->cmdEquals(*this)) {
    return false; // not this dwg's loadCmd
  }  // else
  if (parserPtr->isRefresh()) { // refresh just send update
    sendUpdate();
  } else {
    sendFullDrawing();
  }
  return true;
}

// all the indexed items are included here, edit as needed for updates
void Dwg_HelloWorld::sendIndexedItems() {
}
        
void Dwg_HelloWorld::sendFullDrawing() {
    // Start the drawing
    dwgsPtr->start(50, 50, dwgsPtr->BLUE);
    parserPtr->sendRefreshAndVersion(dwgRefresh); // sets version and refresh time for dwg pfodWeb processes this
    dwgsPtr->label().color(dwgsPtr->RED).text("Hello World").fontSize(8).bold().offset(25,25).center().decimals(2).send();
    sendIndexedItems(); // update indexed items with their real values
    dwgsPtr->end();
}
        
// only indexed items can be sent as an update
// all the indexed items are included here, edit as needed
void Dwg_HelloWorld::sendUpdate() {
    dwgsPtr->startUpdate();
    sendIndexedItems(); // send updated indexed items        
    dwgsPtr->end();
}
// ============== end of Dwg_HelloWorld.cpp  file 
