📄 memory.cxx
字号:
/* * Copyright (c) 2003 Century Software, Inc. All Rights Reserved. * * This file is part of the PIXIL Operating Environment * * The use, copying and distribution of this file is governed by one * of two licenses, the PIXIL Commercial License, or the GNU General * Public License, version 2. * * Licensees holding a valid PIXIL Commercial License may use this file * in accordance with the PIXIL Commercial License Agreement provided * with the Software. Others are governed under the terms of the GNU * General Public License version 2. * * This file may be distributed and/or modified under the terms of the * GNU General Public License version 2 as published by the Free * Software Foundation and appearing in the file LICENSE.GPL included * in the packaging of this file. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. * * RESTRICTED RIGHTS LEGEND * * Use, duplication, or disclosure by the government is subject to * restriction as set forth in paragraph (b)(3)(b) of the Rights in * Technical Data and Computer Software clause in DAR 7-104.9(a). * * See http://www.pixil.org/gpl/ for GPL licensing * information. * * See http://www.pixil.org/license.html or * email cetsales@centurysoftware.com for information about the PIXIL * Commercial License Agreement, or if any conditions of this licensing * are not clear to you. */// System header files#include <errno.h>#include <stdio.h>#include <stdarg.h>#include <stdlib.h>#include <sys/vfs.h>#include <unistd.h>// Local header files#include <FL/x.H>#include <FL/Enumerations.H>#include <nxbox.h>#include "memory.h"#include <pixlib/pixlib.h>#include <sysconf_plugin.h>// Typedef, macro, enum/struct/union definitions#define SZ_TAGS 4// Global scope variableschar *size_tags[SZ_TAGS] = { "Bytes", "KB", "MB", "GB"}; // Tags for size labelsstatic char *f_curDev; // Ptr to the current device value// Static function prototypes (non class)static double getsztags(int byteval, int *idx);NxMemory::~NxMemory(){ // Delete the widgets delete _memsl; delete _storsl; delete _stormb; // Delete the output widgets delete _memory.used; delete _memory.free; delete _memory.total; delete[]_memory.u_str; delete[]_memory.f_str; delete[]_memory.t_str; delete _storage.used; delete _storage.free; delete _storage.total; delete[]_storage.u_str; delete[]_storage.f_str; delete[]_storage.t_str; delete _mainw;} // end of NxMemory::~NxMemory()NxMemory::NxMemory(int X, int Y, int W, int H, char *appname){ // Set up default values.... _winX = X; _winY = Y; _memory.u_str = _memory.f_str = _memory.t_str = NULL; _storage.u_str = _storage.f_str = _storage.t_str = NULL; // Build the window and widgets MakeWindow(X, Y, W, H); // Set the initial values.... GetValues(MEM_GV_UPDMNT | MEM_GV_UPDMEM | MEM_GV_UPDSTO);}voidNxMemory::ShowWindow(void){ Fl::add_timeout(2.0, proc_tmr, (void *) this); _mainw->show();}voidNxMemory::HideWindow(void){ Fl::remove_timeout(proc_tmr, (void *) this); _mainw->hide();}voidNxMemory::MakeWindow(int X, int Y, int W, int H){ int col_width, // Column width curx, // Current x coordinate cury, // Current y coordinate mar = 4; // Left margin double fontw0, // Width of "0%" in current font fontw100; // Width of "100%" in current font Fl_Color def_bg, // Default background def_fg, // Default foreground def_sel; // Default selection color NxApp *instance = sysconf_get_instance(); // Get the back/fore ground colors def_bg = instance->getGlobalColor(APP_BG); def_fg = instance->getGlobalColor(APP_FG); def_sel = instance->getGlobalColor(APP_SEL); // Get the default font width's fl_font(DEFAULT_TEXT_FONT, DEFAULT_TEXT_SIZE); fontw0 = fl_width("0%"); fontw100 = fl_width("100%"); _mainw = new Fl_Group(X, Y, W, H); _mainw->color(instance->getGlobalColor(APP_BG)); curx = _winX + mar; cury = _winY + mar; col_width = (_mainw->w() - (2 * mar)) / 2; { // Memory section.... NxBox *o = new NxBox(curx, cury, _mainw->w() - (2 * mar), BUTTON_HEIGHT); o->color(def_bg); o->labelcolor(def_fg); o->box(FL_FLAT_BOX); o->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); o->label("Memory: "); cury += BUTTON_HEIGHT; } { NxBox *min, *max; NxSlider *o; o = _memsl = new NxSlider((int) (curx + fontw0 + 2), cury, _mainw->w() - (int) ((2 * mar) + fontw0 + fontw100 + 2), BUTTON_HEIGHT); min = new NxBox(curx, cury, (int) fontw0, BUTTON_HEIGHT); max = new NxBox((int) (_mainw->w() - (mar + fontw100)), cury, (int) (fontw100), BUTTON_HEIGHT); min->color(def_bg); min->labelcolor(def_fg); min->box(FL_FLAT_BOX); min->label("0%"); max->color(def_bg); max->labelcolor(def_fg); max->box(FL_FLAT_BOX); max->label("100%"); o->box(FL_BORDER_BOX); o->minimum(0.0); o->maximum(100.0); o->step(1.0); o->type(FL_HOR_FILL_SLIDER); o->deactivate(); o->value(50.0); cury += 2 * BUTTON_HEIGHT; } // end of slider { NxBox *lbl1, // Label *lbl2, *lbl3, *o, // Output text *p, *q; lbl1 = new NxBox(curx, cury, col_width, BUTTON_HEIGHT); o = new NxBox(curx + col_width + mar, cury, col_width - mar, BUTTON_HEIGHT); lbl2 = new NxBox(curx, cury + BUTTON_HEIGHT, col_width, BUTTON_HEIGHT); p = new NxBox(curx + col_width + mar, cury + BUTTON_HEIGHT, col_width - mar, BUTTON_HEIGHT); lbl3 = new NxBox(curx, cury + (2 * BUTTON_HEIGHT), col_width, BUTTON_HEIGHT); q = new NxBox(curx + col_width + mar, cury + (2 * BUTTON_HEIGHT), col_width - mar, BUTTON_HEIGHT); // Set up the labels lbl1->color(def_bg); lbl1->labelcolor(def_fg); lbl1->box(FL_FLAT_BOX); lbl1->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT); lbl1->label("In Use: "); lbl2->color(def_bg); lbl2->labelcolor(def_fg); lbl2->box(FL_FLAT_BOX); lbl2->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT); lbl2->label("Free: "); lbl3->color(def_bg); lbl3->labelcolor(def_fg); lbl3->box(FL_FLAT_BOX); lbl3->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT); lbl3->label("Total: "); // Set up the output o->color(def_bg); o->labelcolor(def_fg); o->box(FL_FLAT_BOX); o->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT); p->color(def_bg); p->labelcolor(def_fg); p->box(FL_FLAT_BOX); p->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT); q->color(def_bg); q->labelcolor(def_fg); q->box(FL_FLAT_BOX); q->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT); _memory.used = o; _memory.free = p; _memory.total = q; cury += (4 * BUTTON_HEIGHT); } // end of labels { // Storage section NxBox *o; // Label for memory // TODO: Probably will need to adjust width to allow for the menu button o = new NxBox(curx, cury, (_mainw->w() - (2 * mar)), BUTTON_HEIGHT); instance->def_font(o); o->box(FL_FLAT_BOX); o->color(def_bg); o->labelcolor(def_fg); o->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT); o->label("Storage on:"); } // end of storage label { // Storage menu button options NxMenuButton *o; // Menu button o = new NxMenuButton(col_width + mar, cury, col_width - (2 * mar), BUTTON_HEIGHT); instance->def_font(o); o->label("Device List"); o->callback(stor_mb_cb, (void *) this); o->menu((NxMenuItem *) NULL); o->value(0); _stormb = o; cury += BUTTON_HEIGHT + mar; } // end of storage menu button { NxBox *min, *max; NxSlider *o; o = _storsl = new NxSlider((int) (curx + fontw0 + 2), cury, _mainw->w() - (int) (((2 * mar) + fontw0 + fontw100 + 2)), BUTTON_HEIGHT); min = new NxBox(curx, cury, (int) fontw0, BUTTON_HEIGHT); max = new NxBox((int) (_mainw->w() - (mar + fontw100)), cury, (int) fontw100, BUTTON_HEIGHT); min->color(def_bg); min->labelcolor(def_fg); min->box(FL_FLAT_BOX); min->label("0%"); max->color(def_bg); max->labelcolor(def_fg); max->box(FL_FLAT_BOX); max->label("100%"); o->box(FL_BORDER_BOX); o->minimum(0.0); o->maximum(100.0); o->step(1.0); o->type(FL_HOR_FILL_SLIDER); o->deactivate(); o->value(50.0); cury += 2 * BUTTON_HEIGHT; } // end of slider { NxBox *lbl1, // Label *lbl2, *lbl3, *o, // Output text *p, *q; lbl1 = new NxBox(curx, cury, col_width, BUTTON_HEIGHT); o = new NxBox(curx + col_width + mar, cury, col_width, BUTTON_HEIGHT); lbl2 = new NxBox(curx, cury + BUTTON_HEIGHT, col_width, BUTTON_HEIGHT); p = new NxBox(curx + col_width + mar, cury + BUTTON_HEIGHT, col_width, BUTTON_HEIGHT); lbl3 = new NxBox(curx, cury + (2 * BUTTON_HEIGHT), col_width, BUTTON_HEIGHT); q = new NxBox(curx + col_width + mar, cury + (2 * BUTTON_HEIGHT), col_width, BUTTON_HEIGHT); // Set up the labels lbl1->color(def_bg); lbl1->labelcolor(def_fg); lbl1->box(FL_FLAT_BOX); lbl1->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT); lbl1->label("In Use: "); lbl2->color(def_bg); lbl2->labelcolor(def_fg); lbl2->box(FL_FLAT_BOX); lbl2->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT); lbl2->label("Free: "); lbl3->color(def_bg); lbl3->labelcolor(def_fg); lbl3->box(FL_FLAT_BOX); lbl3->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT); lbl3->label("Total: "); // Set up the output o->color(def_bg); o->labelcolor(def_fg); o->box(FL_FLAT_BOX); o->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT); o->color(def_bg); o->labelcolor(def_fg); p->color(def_bg); p->labelcolor(def_fg); p->box(FL_FLAT_BOX); p->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT); q->color(def_bg); q->labelcolor(def_fg);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -